PDA

View Full Version : Drawing Faces from 3DS file



Reaperc89
10-23-2011, 02:20 PM
So I just implemented the ability to load vertices and faces from a 3DS file, and it mostly works, with one aspect that has me scratching my head. I am using the following loop to draw the faces after loading a model. The issue is that the model seems to display numerous extra edges when viewing in a wireframe mode. I have checked multiple models and have seen this throughout, I am wondering if anyone has any suggestions on how to fix my problem.



glBegin(GL_TRIANGLES);
for(int x = 1; x < 4*numberOfTriangles+1; x++)
{
//Face bit modifiers not needed, skip em.
if(tLoop == 4)
{
tLoop = 0;
continue;
}
else
{
glVertex3f(Vertices[Triangles[x]*3],Vertices[(Triangles[x]*3)+1],Vertices[(Triangles[x]*3)+2]);
tLoop++;
}
}
glEnd();



And the following is an example of what I am asking about.
http://img.photobucket.com/albums/v298/Reaperc89/Pistol.jpg

BionicBytes
10-23-2011, 03:38 PM
I don't think your loop looks right. Doesn't x have to increase by 3 on each iteration?

Reaperc89
10-23-2011, 04:03 PM
If I was drawing 3 vertices per loop it would, but I'm only drawing a single vertex per loop.

Reaperc89
10-24-2011, 04:33 PM
Figured out my own problem. Notice how the begin and end blocks appear outside of the loop. The program was trying to draw triangles using every vertex in the mesh, one after another. Thus it kinda created one giant mess. I changed to placing three vertices at a time(one face), and I placed the begin/end blocks inside the loop, and changed the loop to increment by 4 each time, allowing me to skip the face data.

Just in case anyone was curious.