Jump to content
  • Advertisement
Sign in to follow this  
cow_in_the_well

Mapping clip space coords to pixels

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!