 # Silly question: generating display lists.

I’ve been writing a Videoscape file reader to play around with. I’ve managed to get it to read the information into custom arrays(with vertex information in Vertex objects of float xyz coords, and faces(planes) of the object in objects containing how many vertices in the face, and an array of 3-4 Vertex objects).
However, when I go to build the display list, the resulting object comes out wonky. A pyramid has two points, a cube has some faces drawn correctly but others with holes, etc.
I suspect that I’m overlooking something simple when writing the glVertexes. Here’s the section that builds the list; nplanes is the number of faces, and planes is the array of face objects:

mesh = glGenLists(1);
printf("Now building display list.
");
glNewList(mesh, GL_COMPILE);
/* The nplanes loop /
for(i = 0; i <= (nplanes-1); i++){
if(planes[i].numVerts == 3){
count = 2;
glBegin(GL_TRIANGLES);
}
else if(planes[i].numVerts == 4){
count = 3;
}
else{
/
shouldn’t happen /
count = 4;
glBegin(GL_POLYGON);
}
/
generic coloring for now /
glColor3f(1.0f, 1.0f, 0.0f);
/
Individual plane loop */
for(j = 0; j <= count; j++){
glVertex3f(planes[i].vertexes[j].x,planes[i].vertexes[j].y, planes[i].vertexes[j].z);
}
glEnd();

}
glEndList();
return mesh;

Hi!

I can only guess what goes wrong here:
where’s the information that connects the right points in a face?
Yesterday I just tried to read some ascii object file generated my moonlight, (.off file) and it generated the amount of vertices, faces and what vertices are in one face (allways 4: quads).

I guess that’s why you have holes in you object.

And just as a coding tip:
try to use only ‘<’ in your for loops, and the numbers make a whole lot more sence. for a triangle you get:
for (i=0; i<3; i++)
once reading this line and you see it coverts 3 points (0…2). much simpler.
well, that’s my opinion, and i’m sure others as well.
And you van use planes[i].numVerts in your ‘j’ loop like this:
for(j = 0; j < planes[i].numVerts; j++)

no need for the count variable anymore too…

happy coding,
John

Yeah, I’m surprised I didn’t notice the <= statements; too many long hours coding for a filesystem. Doh…

The face information is what’s in the planes array; each plane/face has three or four vertexes that were assigned earlier, and how many verts are in itself. In Videoscape, you can have either 3 or 4 vertexes for a face:
4 0 3 2 1 0x(color)
This line says “four verts total, the first one is the 0th vertex in the vertex list, the next is the 3rd vertex in the vertex list, the next is the 2nd vertex in the vertex list, the next is the 1st vertex in the vertex list”.

I guess the logic flow is like:

for(each face(counted by i)
if numVerts = 3
{
glBegin(GL_TRIANGLES)
else if numVerts = 4
Sorry for being somewhat obtuse, I’m trying to get a handle on 3d coordinates. 