Understanding of glTexCoord*

Hi opengl’ers :slight_smile:

i began to code in c++ with SDL and then started to use OpenGL.
After some lessons i started to learn texture mapping.

It was really easy to put a texture on a simple quad. After that i tried to figure out how glTexCoord2f is really working.

The first time i thought for glTexCoord2f the two parameters stand for the (x,y) coordinate which should be the same as the glVertex method to match. But it wasnt.

Then i’ve read something about representating the part of the texture in percentage. As parameters are between 0 and 1, 1 stand for 100% of the texture width/height, but i dont get it. What does that mean.

As ONE glTexCoord is always mapped to a point in a GL_QUADS area, how is glTexCoord interpreted by OpenGL?

I have a 256x256 *.bmp texture. And i have 256x256 Quad which is simply put on window with 4 glVertex3f method calls.
When i use standard parameters for glTexCoord2f, like (0,1), (1,1), (0,0) and (1,0), then texture is mapped perfectly on the Quad.

But i tried to only map a part of the texture to this quad, changing the glTexCoord parameters. I tried to map the top half of the texture (means from 0,0 to 256,128) on the 256x256 Quad. This didnt work, i got a texture on the full quad in one color, the text/logo on the texture just disappered. When i tried to use parameters for glTexCoord greater than 1.0 then i got a strange dashed lines texture.

Im still confused, how is glTexCoord really working?
How can i map the half or any part of a texture on simple quad (like blitting a part of an image on a surface, or just stretch the texture on the full quad).

Thanks for any help.

glTexCoord2f - means float.

If you want half of the quad you should use following texcoords:
(0.0f, 0.5f), (1.0f, 0.5f), (1.0f, 0.0f), (0.0f, 0.0f)

No matter how big the texture is, it’s coordinates are always in range 0.0f-1.0f.
So, 0.5f is half of texture, 2.0f is texture repeated twice.

The only exception are rectangular textures specified using GL_TEXTURE_RECTANGLE instead of GL_TEXTURE_2D.