I have implemented the ability to load 3DS files into an OpenGL program of mine, and run into a slight problem. All of the vertices are placed properly, and the faces are drawn, but the issue is that most(or all) of the vertices seem to retain a connection to one or two vertices, creating a large number of extra edges. Anyone run into this issue before or have a suggestion on how I can fix it?
The following block of code is the loop I use to draw the faces. It loops through one vertex at a time, skipping every fourth value (in theory) as they are unused face modifiers.
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();
This next is an image representing the problem I am having. http://img.photobucket.com/albums/v298/Reaperc89/Pistol.jpg
The fact that
glBegin
andglEnd
are outside the loop is absolutely no problem. Drawing triangles using every vertex one after the other is just the correct way. It will build a triangle form every 3 consecutive vertices, which is what you want.Your problem was, that you increased
tLoop
inside the else block, and therefore actually skipped every fifth index, instead of every fourth. So unrolling prevented it, but it has nothing to do withglBegin/glEnd
not working outside of the loop. But like said in the comment, you don't need thetLoop
anyway, as you can just usex
instead:or even better unroll the loop:
But placing the
glBegin/glEnd
inside the loop is the silliest thing you can do. In fact if you already use a vertex/index array based representation, it should be quite easy to port your rendering code to vertex arrays, which are much faster than immediate mode, more so when powered by VBOs.