View Full Version : texture concept query

07-03-2011, 03:42 AM

I have understood the basic of how texturing is done but the main issue is I am not getting the relation between glTexCoord2f() and glVertex3f e.g

gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, -1.0f);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(-1.0f, 1.0f, -1.0f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(1.0f, 1.0f, -1.0f);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, -1.0f);

how are these code lines relate to each other.Please help me..I am really stuck with this. I have read many articles and forums but still not clear with it. Kindly help..



Dan Bartlett
07-03-2011, 04:28 AM
http://www.opengl.org/sdk/docs/man/xhtml/glVertex.xml explains it
glVertex commands are used within glBegin/glEnd pairs to specify point, line, and polygon vertices. The current color, normal, texture coordinates, and fog coordinate are associated with the vertex when glVertex is called.
So the glTexCoord2f/glNormal/etc. calls set the current value for that attribute, then when you call glVertex it takes all those current values + forms a vertex. If you were to call glTexCoord2f multiple times before a glVertex call, only the last value before the glVertex call will be used, as that would be the current value at that time.

07-03-2011, 04:38 AM
Thanks for the reply..but can you explain me the lines I have mentioned above...igot the gist of it but how it is getting worked up in implementation is problematic for me..Kindly help

07-03-2011, 04:56 AM
Each vertex is assigned a texture coordinate so that for each vertex it is possible to know the exact location on the image the vertex is, and so that we can know for each polygon the matching polygon in the image, and so we'll be able to know what part of the image will be used to cover the polygon. And if we do this for all polygons we can cover all the mesh.

Texture coordinates are generally given in the range [0..1] since images have different sizes. [0..1] covers the image in its widght and height.

For more information try a google search about texture mapping.

07-03-2011, 12:45 PM
What about the OpenGL Programming Guide?

and there is a link on that page for version 1.1.
You would want to read the chapter on texture mapping