PDA

View Full Version : glNormalPointer glDrawElements, tables structure



Kojot
10-20-2010, 05:28 AM
Let's say I have:


GLfloat vertices[] = {...}; // 8 of vertex coords
GLubyte indices[] = {0,1,2,3, // 24 of indices
0,3,4,5,
0,5,6,1,
1,6,7,2,
7,4,3,2,
4,7,6,5};

I use glDrawElements() function to render GL_QUADS and everything is ok.
But what if I want to add normal array to my object? What structure does it have to be?
3 floats for every index (one Normal for every Vertex)?
or 3 floats for every 4 of indexes (one Normal for every Quad) ?
Or should I use glDrawElements() function not once, but for every Quad separetely, giving property amount of indices?

wimmla
10-20-2010, 06:02 AM
If I understand your question well.
One normal per vertex is best (enables nicest viewing).
See http://www.lighthouse3d.com/opengl/terrain/index.php3?normals for an excellent explanation.
r
Wim

BionicBytes
10-20-2010, 06:08 AM
The usual thing to do is send 3 floats per normal, per vertex.

Kojot
10-20-2010, 07:09 AM
I want to have one normal per polygon. In your description there is one normal per every vertex.

For example:
Polygon A consists of vertex indexes: 0, 1, 2, 3
Polygon B consists of vertex indexes: 1, 4, 5, 6
All vertices in polygon A should have normal nA, and all vertices in polygon B should have normal nB.

We can see, that vertex number 1 is common to Polygon A and Polygon B. I would like to set normal nA to vertex number 1 when I render polygon A, and normal nB to vertex number 1 when I render polygon B.

Is there any possibilty to set different normal to every element of Index Array?