PDA

View Full Version : glTexCoord and glNormal



kospanak
07-07-2008, 08:40 AM
Hello. I have some questions that need to be answered. What exactly is the function of glTexCoord and what is the difference between glTexCoord and glNormal?

Zengar
07-07-2008, 09:02 AM
glNormal specifies the per-vertex normal vector, which is used in lighting calculation, glTexCoord specifies the per-vertex texture coordinate which is used in texture application (read the corresponding pages from the OpenGL specification). Feel free to ask more specific questions...

kospanak
07-07-2008, 10:15 AM
I 've read the corresponding pages in OpenGl specification. What i am trying to do is to create an angular fisheye from a cubemap. So i got the idea to wrap the texture of the cubemap around a sphere and map the texture according to the maths that are applied in order to create the angular fisheye. In order to understand better what i try to do, here is the link:

http://local.wasp.uwa.edu.au/~pbourke/projection/fisheye/

What i do not understand is this: must i ,for each point of the sphere, determine the vector for the mapping by use of glTexcoord? In fact, should i use glTexCoordd at all?

PS: In order to understand, read the the paragraphs "Creating an angular fisheye" and "Inverse transform".

Zengar
07-07-2008, 10:45 AM
If I understand that case correctly, normal and texture coordinates equal each other (if you interpret the cubemap as a normal vector lookup table). Still, GL maps texture to a surface using the texture coordinates, so you will have to specify texture coordinates, unless you use shaders and do anything manually anyway.

kospanak
07-07-2008, 12:01 PM
(if i remember correctly, with shaders you manipulate directly the GPU "programmable pipeline.) i do not use shaders. i use glNormal3f and when i want to generate texture coordinates, i use these functions:

glTexGenfv(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGenfv(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGenfv(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

What intrigues me in the link that i gave you to look is this:
In the paragraph "Inverse transform", it says that for each unit vector (x,y,z) we find a (u,v) coordinates. I wrote the code for the calculations of (u,v) , given the (x,y,z), and then before calling glVertex i called glTexCoord2f for the (u,v) and from the code above i deleted the first 3 lines. The results was catastrophic to be exact. What could 've gone wrong???

PS: Sorry if i tire you with my questions

Zengar
07-07-2008, 12:59 PM
Uhm, TexGen "replaces" manually specified texture coordinates with the generated ones. So when you enable it (with glEnable) then all data you specify with TexCoord is lost. Even so, you don't need to specify texture coordinates if they are generated: what I meant is that you need them for texture mapping, no matter where they come from (manually or generated)!

kospanak
07-07-2008, 02:21 PM
what i know that TexGen is used to create "automatically" the texture coordinates using OpenGL's modes. What i do not know (exactly) is how to create manually texture coordinates (in this case the necessary coordinates for fisheye). Something is missing, but i do not know what

dletozeun
07-08-2008, 12:22 AM
I don't know fisheye projection, but there should be a way to generate these texture coordinates procedurally.
For an arbitrary 3D mesh, texture coordinates are often generated in 3D modelers by artists using projections like: plane, spherical, cylindrical, ... projections.