Sign in to follow this  

Setup camera for 1:1 pixelmapping

Recommended Posts

I'm trying to setup camera with perspective projection so that I get 1:1 mapping of an quad to pixels. I got this 320x256 sized quad with texture that I want to be rendered in 320x256 pixels on screen I can't get it to work 100%, either the width is correct or the height. Cant get both to match which is a bit annoying. Anyone know how to do this? [Edited by - devnick on March 28, 2006 5:31:13 AM]

Share this post

Link to post
Share on other sites

Well the first thing to do is look up in the SDK for the FVF formats you can use. Look up one called D3DFVF_XYZRHW. This means you add one float after the z component and if you set that to one, the vertices will not be transformed, they will map exactly how you want.

Hope that helps,


Share this post

Link to post
Share on other sites
I still want the vertices to be transformed as usual but at z=1 I want it (in this case a quad) to apear to be in screenspace, ie 1:1 mapping. So it's a question of setting up the camera and projection matrix correct.

Thanks anyway.

Share this post

Link to post
Share on other sites
Hmm. I can suggest something but I haven't tried it. It should work though...
What you must do, is set the width and height of the visible volume at the camera's near clipping plane to the width and height of your quad, and then make sure that the distance from the camera to the quad is exactly equal to the distance of the near clipping plane.
To sum up, set the projection matrix to:

[ 320.f 0 0 0 ]
[ 0 256.f 0 0 ]
[ 0 0 z2/(z2-z1) 1 ]
[ 0 0 -z1*z2/(z2-z1) 0 ]

where z1 is the near clippling distance and z2 is the far one.
You can use one of the D3DXMatrixPerspectiveFovLH/RH for this.

Then set the view matrix so that the camera's "look at" axis is perpendicular to the quad, and intersects the quad at its center.
E.g. if the quad is parallel to the XY plane, and its center is (0,0,0), set the camera target to (0,0,0) and its position to (0,0,-z1).
Avoid forcing the camera to look straight down (or up), because there is a bug in that case.

If nothing seems to render, it could be a "z-fighting" problem. Position the camera at (0,0,-(z1+ε)), where ε is some very small positive number, like 0.001f
Of course, the viewport's dimension should also be 320 and 256 respectively.
As I said, I've never done this, but it *should* work.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this