Advertisement Jump to content
Sign in to follow this  

Mapping clip space coords to pixels

This topic is 3865 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 ( 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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!