Sign in to follow this  

Mapping clip space coords to pixels

This topic is 3460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, my problem is thus: I'm representing a GUI window in -1 to 1 clip space coordinates, which is a quad. Now, I want to clip child GUI components to the region of the parent window, so I'm using a scissor rectangle which somewhat works. The problem is that I'm converting clip space coordinates of the parent window's quad vertices to screen pixels so I can setup the scissor RECT (which takes integer coordinates). However, the way I'm converting from clip -> pixels doesn't always match up to how d3d is rendering the quad so I sometimes get the scissor region off by one. I looked up Direct3D's rasterization rules (http://msdn.microsoft.com/en-us/library/bb147314(VS.85).aspx) and setup my clip->screen mapping function like so:
float rx1 = (clipRect.x * halfScreenWidth + halfScreenWidth);
float ry1 = (clipRect.y * -halfScreenHeight + halfScreenHeight);
float rx2 = (clipRect.z * halfScreenWidth + halfScreenWidth);
float ry2 = (clipRect.w * -halfScreenHeight + halfScreenHeight);

D3DRECT region;
region.x1 = (LONG)floor( rx1 + 0.5f );
region.y1 = (LONG)floor( ry1 + 0.5f );
region.x2 = (LONG)rx2;
region.y2 = (LONG)ry2;

Which, from what I can tell, matches up to d3d's top-left-inclusive rule. However I'm still getting problems :/. Any advice? Thanks in advance. -Thomas

Share this post


Link to post
Share on other sites

This topic is 3460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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