PDA

View Full Version : Understanding Texture coordinates



Mctittles
07-24-2011, 03:28 PM
I'm trying to draw a simple quad with only one part of a texture used to see how texture mapping works. It's a 32 by 32 texture and I'm currently just trying to get the left strip of pixels shown.
I first tried to map the texture coordinates with the left X zero and the right X 1/32 (0.03125). This did not work when zoomed in it blended with the pixels to the right and had a dark edge to the left.
I read somewhere that openGL samples pixels from the center, so I tried again with 0 for left X and .5/32 (0.015625) for the right X . This was better, but still had a darker left border.

Finally I got it to work by using .5/32 (0.015625) for both the left and right X coordinates.

To come up with my solution I just messed with numbers until it worked, so I still do not know if I'm doing right. Can anyone explain how to exactly map only parts of a texture. Most tutorials say use zero for left and one for right, but this does not work.

Alfonse Reinheart
07-24-2011, 03:35 PM
It sounds like you forgot to turn off texture filtering. If you have GL_TEXTURE_MAG/MIN_FILTER set to GL_LINEAR, then you will get blending between texels. Set it to GL_NEAREST if you only want the value closest to the texel.

Mctittles
07-28-2011, 07:26 AM
You are right! I had actually tried testing this but I was setting the wrong texture. It works now. Thanks!