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

glNormalPointer()

Started by Escaflowne75 Dec 10, 2002 at 6:46 PM 2 replies 850+ views
Original Post
Escaflowne75
Escaflowne75
Hi all. I''m trying to use glNormalPointer in conjunction with vertex arrays. I can''t seem to find out how many normals need to be in the normal array. Is it one normal per face or one normal per vertext? -escaflowne75
Palidine
Palidine
one normal vector per vertex in the vertex array.

if you''re using normal3f and vertex3f then length of normals array will be exactly equal to the lenght of the vertex array. remember that both are different from the index array (which is related to numIndices). ack. hopefully i was clear. i can''t tell...need sleep

-me
Escaflowne75
Escaflowne75
Ok, well I have this section of code that I thought created a bunch of normal vectors based on vertices in a face. I obviously have this code wrong cause when I use it, the program won't run.


    
void createNormals(const GLfloat Vertices[], const GLubyte Index[], GLfloat *Normals,
int sizeOfIndex, int numVertexPerFace )
{

if(!Normals)
Normals = new GLfloat[sizeOfIndex*3];

Point3 a, b, c;

Vector3 tempVect;

int y = 0, count = 0, z = 0;

while(y < sizeOfIndex*3)
{
for(int x = 0; x < numVertexPerFace; x++)
{
if(x == 0)
count = x;
a.x = Vertices[Index[count+z]*3];
a.y = Vertices[Index[count+z]*3+1];
a.z = Vertices[Index[count+z]*3+2];


count++;
if(count == numVertexPerFace)
count = 0;

b.x = Vertices[Index[count+z]*3];
b.y = Vertices[Index[count+z]*3+1];
b.z = Vertices[Index[count+z]*3+2];


count++;
if(count == numVertexPerFace)
count = 0;

c.x = Vertices[Index[count+z]*3];
c.y = Vertices[Index[count+z]*3+1];
c.z = Vertices[Index[count+z]*3+2];

if(count == numVertexPerFace)
count = 0;

if( count < numVertexPerFace && count > 0)
count = count - 1;
else
count = numVertexPerFace -1;

tempVect.set(createNormal(a, b, c));

if(y < sizeOfIndex*3)
Normals[y++] = tempVect.x;


if(y < sizeOfIndex*3)
Normals[y++] = tempVect.y;


if(y < sizeOfIndex*3)
Normals[y++] = tempVect.z;
}

z = z + numVertexPerFace;
}

}


It's suppose to go through a vertex array and the associated index array and create normals for each vertex based on the number of vertices in the face and stick them into a newly created array called Normals. I can't see the problem with it. I get an access violation when I try to run it. If anybody can see the problem or suggest a better way to get normals, please let me know.

-escaflowne75

[edited by - escaflowne75 on December 12, 2002 4:55:17 AM]

[edited by - escaflowne75 on December 12, 2002 5:04:48 AM]

Topic Locked

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

Sign in to reply to this topic.