refresh code

Looking at some refresh code I inherited. Works with GL_QUADS which I want to replace with GL_TRIANGLE. First however I have to understand what’s going on.

The programmer is applying a texture to a 3D model (glTexImage3d). Iterating for(i=0;i<nslices;i++) The texture is 3D data we are displaying in an OpenGL visualizer.

Am I to assume that if a glVertex3f command follows a glTexCoord3f then that location in the texture is associated with that location in the model? So specifying four end coordinates in sequence it defines the outer points of the quad? This is repeated for each and every plane in the z direction.

z3=((float) i)/(nslices-1.0f)*2.0f-1.0f;
z4=1.0f-((float) i)/(nslices-1.0f);

glTexCoord3f (0.0f,0.0f,z4);
glVertex3f (-1.0f, -1.25f,z3);

glTexCoord3f (1.0f, 0.0f,z4);
glVertex3f (1.0f, -1.25f,z3);

glTexCoord3f (1.0f, 1.0f,z4);
glVertex3f (1.0f, 1.25f,z3);

glTexCoord3f (0.0f, 1.0f,z4);
glVertex3f (-1.0f, 1.25f,z3);

Yes. glTexCoord sets the current texture coordinates (similarly, glColor and glNormal set the current colour and normal). glVertex creates a new vertex with the specified position and the current texture coordinates, colour and normal.


Thanx for the answer.

I forgot to ask why is glTexCoord3f 0 to 1 based while glVertex3f is -1.25 to 1.25 based.

The texture source is 384 wide x 384 depth x 480 height.
The glTexImage3D is 384 wide x 384 depth x 480 height
384 to 480 is a 1 to 1.25 proportion