Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL function calls

Started by MindCode Dec 30, 2002 at 12:47 PM 2 replies 650+ views
Original Post
MindCode
MindCode
Do the GL functions calls of glVertex/glNormal/glColor/glTexCoord have to be specified in a certain order? Does this: glVertex3f(1.f, 0.f, 1.f); glColor3f(1.f, 1.f,1.f); glNormal3f(0.f, 1.f, 0.f); Equal this: glNormal3f(0.f, 1.f, 0.f); glColor3f(1.f, 1.f,1.f); glVertex3f(1.f, 0.f, 1.f); I was wondering because it seems on my implementation, when I put TexCoord before Color it messed things up.
That's just my understanding; I could be wrong.
pi_equals_3
pi_equals_3
calling glNormal and glColor BEFORE glVertex will apply the normal and the color to the vertex drawn. If you call those functions AFTER glVertex, they won''t apply until the next vertex is drawn. As far as glTexCoord and glColor, I think calling them both will apply a texture to a vertex, and tint it that color, but I don''t think it would make a difference which order the two go in. How does it mess up? What happens differently when you put them in the other order?
MindCode
MindCode
It was a while ago so it may have been two other functions I''m confusing. Probably

So what your saying is that glVertex has to be the last one called?
That's just my understanding; I could be wrong.
pi_equals_3
pi_equals_3
Yes, it has to be the last one, assuming you want all the calls to apply to that vertex. Calling glColor just sets the current color, which the later glVertex call will use. For instance, if I want to draw a quad with four colors blended across each vertex, I would specify each vertex''s color before i draw it.

glBegin(GL_QUADS);

glColor3f(1.0f, 0.0f, 0.0f); // Sets current color to red
glVertex3f(0.0f, 0.0f, 0.0f); // Draws a red vertex

glColor3f(0.0f, 1.0f, 0.0f); // Sets current color to green
glVertex3f(1.0f, 0.0f, 0.0f); // Draws a green vertex

glColor3f(0.0f, 0.0f, 1.0f); // Sets current color to blue
glVertex3f(1.0f, 1.0f, 0.0f); // Draws a blue vertex

glColor3f(1.0f, 1.0f, 0.0f); // Sets current color to yellow
glVertex3f(0.0f, 1.0f, 0.0f); // Draws a yellow vertex

glEnd();


whereas if you did this...

glBegin(GL_QUADS);

glVertex3f(0.0f, 0.0f, 0.0f); // Draw a vertex with last color
glColor3f(1.0f, 0.0f, 0.0); // Set color to red

glVertex3f(1.0f, 0.0f, 0.0f); // Draw a red vertex
glColor3f(1.0f, 0.0f, 0.0); // Set color to green

glVertex3f(1.0f, 1.0f, 0.0f); // Draw a green vertex
glColor3f(1.0f, 0.0f, 0.0); // Set color to blue

glVertex3f(0.0f, 1.0f, 0.0f); // Draw a blue vertex
glColor3f(1.0f, 0.0f, 0.0); // Set color to yellow
// doesnt apply to any vertex

glEnd();

....you wouldnt get the intended result.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.