PDA

View Full Version : Display lists and normal vectors



02-13-2004, 12:21 AM
This is probably a more advanced topic, but I'm not sure. the deal is that I'm trying to use display lists to render a scene with a couple of objects that I've created. The problem is that I can get these to display correctly without using the display lists, however, when trying to use the displaylists only the abient color of the world is lighting the object. the normals don't seen to be doing anything. Also I've enable light0 as well.

dvm
02-13-2004, 04:44 AM
Without remembering much, have you checked what kind of functions are able to go inside a display list. You can't put everything in them. I believe though that your problem might lie somewhere else. Try posting some code.

02-13-2004, 08:31 AM
As a quick note. This code are just parts, of a huge project that I've been working on. This was originaly done in my 3D graphics class in school and I've been working on it to try and make better.

This section is how I'm calling my display list

theObject = glGenLists(1);
glNewList(theObject,GL_COMPILE);
// render the basic object
float mat_specular[4]={(float) [speculate getRed],(float) [speculate getGreen],(float) [speculate getBlue],1.0f}; //color of specular highlight
float mat_diffuse[4]={(float) [diffuse getRed],(float) [diffuse getGreen],(float) [diffuse getBlue],1.0f}; //diffuse material (blue)
float mat_ambient[4]={(float) [material getRed],(float) [material getGreen],(float) [material getBlue],1.0f}; //ambient material (red)

glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,&shininess);
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
[bObject buildDisplayObject];
glEndList();
glShadeModel(GL_SMOOTH);

bObject buildDisplayObject then calls a face object and that references a section of real computer memory that holds all of the vertex information including vertex normals. The vertex information is pulled from a ".obj" file.

the face object does this.

gets the three vertices of the face. (I've tesselated all the faces from the ".obj" file.)
gets the normals from each vertex.

glBegin(GL_TRIANGLES);

// Vertex A
glNormal3f([vAnormal getX],[vAnormal getY],[vAnormal getZ]);
glVertex3f([vertexA getX],[vertexA getY],[vertexA getZ]);

// Vertex B
glNormal3f([vBnormal getX],[vBnormal getY],[vBnormal getZ]);
glVertex3f([vertexB getX],[vertexB getY],[vertexB getZ]);

// Vertex C
glNormal3f([vCnormal getX],[vCnormal getY],[vCnormal getZ]);
glVertex3f([vertexC getX],[vertexC getY],[vertexC getZ]);

glEnd();

Ok, that's how I'm defining my display list.

then to render I define a single light source light0 and also define the ambient light in the scene.

glMatrixMode(GL_MODELVIEW)
glLoadIdentity();
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT,GL_FILL);
glFrontFace(GL_CCW);
glCullFace(GL_BACK);
for( index = 0; index < [self numberOfInstanceObjects]; index++){

glPushMatrix();
if( index == 0 ) {
//glPushMatrix();
glRotatef(-roty,0.0,1.0,0.0);
glTranslatef(0.0,0.0,-10.0);
glRotatef(roty,1.0,0.0,0.0);
}
tempObject = [self getInstanceObject:index];
[tempObject renderInstanceObject];

if (index == 0 ){
glPopMatrix();
glPopMatrix();
glPopMatrix();
}
}
roty += 0.5;
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glDisable(GL_CULL_FACE);


all that tempObject renderInstanceObject does is call the display list for that particular instanceObject.

- (void) renderInstanceObject
{
glCallList(theObject);
}


then I flush the buffers in opengl.

I hope that you can understand the code 'cause I've written this in objective-C.

Thanks for the help.
BTW, as far as I can tell, the normals can fit into the display list, but I've been looking at the 1.5 information about the display lists, unfortunately I've only got opengl 1.2 support on my computer.

Thanks again

mithun_daa
02-13-2004, 11:46 AM
are u sure your normals are facing in the right direction? u could just try negating the normal values. this is just a long shot.

another thing i observed was that u have 3 popmatrix statements when the index = 0. your not even pushing when index = 0. i think that u dont need those popmatrix statements when index= 0 at all.

[This message has been edited by mithun_daa (edited 02-13-2004).]

02-13-2004, 08:31 PM
Ok, I tried making all of the normals negative and I get the same results. Also, the glPopMatrix() weren't the problem either. I shortend some of the code for the posting, but that function did need to be there. As of right now, it looking like I won't be able to use display lists. Which is really sad, 'cause I was seeing around 200 fps with the display lists and roughly 70 fps otherwise.

Thanks again for the help.

02-14-2004, 01:55 AM
Display lists are able to store every GL state or GL command that you can think of. You are probably having a bug in your code : when it is complex and split among several functions, it is hard to track GL state precisely.

Maybe the DL store too much info ? Have you tried to put all your glEnable(GL_LIGHTING) etc inside the DL or before it ?