PDA

View Full Version : Problems with normals and glDrawElements



Mr.Freeze
09-30-2001, 07:20 PM
Hi,

I'm wondering what I do wrong, but the normals don't have the correct orientation with :

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3,GL_FLOAT,0,vertices);
glNormalPointer(GL_FLOAT,0,normals);
glDrawElements(GL_TRIANGLES,indexLength,GL_UNSIGNE D_INT,indexes);

but do with :

glBegin(GL_TRIANGLES);
for (int i=0;i<indexPLength;i++)
{
glNormal3fv(normals+3*i);
glVertex3fv(vertices+3*(*(indexes+i)));
}
glEnd();

How come??
In my normals array I specify a normal for every vertex.
If I have 4 points and 3 triangles for instance, I have the following arrays:

indices:
p1x,p1y,p1z, http://www.opengl.org/discussion_boards/ubb/tongue.gifoint1
p2x,p2y,p2z, http://www.opengl.org/discussion_boards/ubb/tongue.gifoint2
p3x,p3y,p3z, http://www.opengl.org/discussion_boards/ubb/tongue.gifoint3
p4x,p4y,p4z http://www.opengl.org/discussion_boards/ubb/tongue.gifoint4

indexes:
i1,i2,i3, :triangle 1
i4,i5,i6, :triangle 2
i7,i8,i9 :triangle 3

normals:
nx1,ny1,nz1, :normal 1
nx2,ny2,nz2, :normal 2
nx3,ny3,nz3, :normal 3
nx4,ny4,nz4, :normal 4
nx5,ny5,nz5, :normal 5
nx6,ny6,nz6, :normal 6
nx7,ny7,nz7, :normal 7
nx8,ny8,nz8, :normal 8
nx9,ny9,nz9, :normal 9

Can someone help me??

Thanks http://www.opengl.org/discussion_boards/ubb/smile.gif