Jump to content
  • Advertisement
Sign in to follow this  
RPTD

OpenGL Correct way of sub-texture coordinates

This topic is 2835 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

Let's say I have a texture of 1000x800 pixels in size (example for better numbers). I want now to render a full screen quad in which I want to tap for example from only the sub-image 800x600 for example. The texture has to be addressed using normalized texture coordinates in GLSL. Question now is, what is the "correct" texture coordinates to clamp to?

From the opengl specs I understand it that the range [0..1] goes from "one edge of the texture to the other". So this would mean the left side of the pixel x=0 would be s=0 and the right side of the pixel x=999 would be s=1. Where is now the correct border for the sub-image? I figured so far:

clamped = 0 <= s <= 800/1000

is this correct or should it be 799/1000? if I tap exactly at s=1 would I get the pixel 799 or 800 with the above formula? are there differences between ATI and nVidia in this one?

Share this post


Link to post
Share on other sites
Advertisement
I believe (i'm not 100% so bear with me), that to get the exact co-ordinate of centre of a texel you need to add 0.5px.

So if you want to change the bottom left pixel, the coordinates (non-normalised) of the borders of that pixel are:

0,0 - 1,1 (The centre of the pixel lies at 0.5,0.5)

So to update the bottom left 100x100 square, the co-ordinates would be

0,0 - 100,100.

Share this post


Link to post
Share on other sites
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!