BlueSpud
BlueSpud

Reputation: 1623

The Right Way To Draw Normals In OpenGL?

Right now I am writing a program in OpenGl. I'm rendering some-what complex 3D figures from files. After triple checking the code, I know that all the values are being read right. The only thing thats acting weird is the normals. I'm drawing them like this:

     glVertex3fv(vert1);
     glVertex3fv(vert2);
     glVertex3fv(vert3);


    glNormal3fv(norm1);
    glNormal3fv(norm2);
    glNormal3fv(norm3);

The values are being read from GLFloats. Tell me the right way, or at least what I'm doing wrong.

Upvotes: 4

Views: 1384

Answers (1)

Tim
Tim

Reputation: 35933

When you call glVertex, that finishes a vertex, so you need to set all the other vertex state before that. You need to set the normal for a vertex before finishing it.

It should look like this:

glNormal3fv(norm1);
glVertex3fv(vert1);

glNormal3fv(norm2);
glVertex3fv(vert2);

glNormal3fv(norm3);
glVertex3fv(vert3);

Upvotes: 7

Related Questions