Archived

This topic is now archived and is closed to further replies.

narfidoo

OpenGL OpenGL question

Recommended Posts

This may be stupid. I''m new. Say I have an array of vertices and an array of indices for triangles as well as an array of normals. How would I render my object in OpenGL? I have tried glDrawElements but that doesn''t work with the normals. I''m not sure what to do. Oh and I don''t want to draw the triangles seperately, I want them to be smoothly shaded together. Thanks, GG

Share this post


Link to post
Share on other sites
A-B
|/|
C_D

VECTOR verts[] = { A,B,C,D }
VECTOR norms[] = { A,B,C,D }
GLuint indices[] = { 0,1,2,1,2,3 }; // A B C B C D

glVertexPointer( 3, GL_FLOAT, 0, verts);
glNormalPointer( GL_FLOAT, 0, norms);
glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices );

will draw the two triangles u will also need to enable the clent states for vertices and normals


http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
Oh, I found out my problem.

My array had normals for each triangle, not each vertex. Any way I can do this?
Otherwise, how can I find the normal for a vertex?

Share this post


Link to post
Share on other sites
Just use the same normal for each vertex. You can have different normals for each vertex so things can look rounded with some shading type the way I understand it (like if you have polygons connects you put the same normal for vertexes that touch and it rounds it off...I think ) Anyway just put the same normal for each vertex, I know that works.


-=Foible=-

Share this post


Link to post
Share on other sites