PDA

View Full Version : Silly question: generating display lists.



Scott Francis
05-22-2000, 01:02 PM
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.\n");
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;
glBegin(GL_QUADS);
}
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;

Sjonny
05-23-2000, 12:04 AM
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

Scott Francis
05-23-2000, 11:01 AM
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
glBegin(GL_QUADS)
for(each vertex(counted by j) in the current plane)
{
assign it a glVertex.
}
glEnd;
}

I tried looking at a flat regular plane with the reader; three of the points come out normal. However, the fourth one wasn't there--it looked like someone had snipped off a third of the square.

Sorry for being somewhat obtuse, I'm trying to get a handle on 3d coordinates. :)