Sign in to follow this  
TrueTom

OpenGL Linear interpolation behaviour

Recommended Posts

Hello, if I use texture interpolation (GL_LINEAR), does OpenGL interpolate even if there is no need to (Draw a 16x16 texture to a 16x16 rect)? (Cause it currently does and I wonder if it's my fault; the tex coords look good, but maybe due to some rounding errors) Regards, Thomas

Share this post


Link to post
Share on other sites
OpenGL does the interpolation, surely.
But if you want to draw exact quad, yo must specify exact texture coordinates.
Unfortunately, they are not 0 and 1.
Imagine, you texture width is W and height is H.
So, exact coordinates would be from 0.5/W to 1.0 - 0.5/W horizontally, and 0.5/H to 1.0 - 0.5/H vertically.

To read more about why is it so, look here:

http://download.nvidia.com/developer/NVTextureSuite/Atlas_Tools/Texture_Atlas_Whitepaper.pdf

page 12

Share this post


Link to post
Share on other sites
@blizzard999: Well, this seems obvious but is a problem if you need to interpolate some parts of a texture and some not...

@Jackis: Thank you very much, that helped me a lot. The solution is really that simple. Just add an offset of 0.5f to every coordinate and you're doing fine (using endpoint-exclusive rect required). You also have to do this with the destination coords and everything works fine. I also got rid of the recommended gltranslatef(0.375, 0.375, 0.0), doesn't work reliable.

Share this post


Link to post
Share on other sites
TrueTom:
You're welcome!
And about glTranslatef(0.375f, 0.375f, 0.f)
I works, but it doesn't affect texturing, this trick is helpful for drawing smth in exact window positions, but not for exact texturing, you're right!

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