Wireframe Loading Issue - Lines Out of Place

Hello all!

I’m a bit stuck with loading a wireframe (made of triangles) using an OBJ loader/parser I made (OpenGL exercise with GLUT/GLEW). There are some random lines that show up - look near the spout, and inside the teapot*. The more vertices (more complex objects), the more random lines. I am fairly certain the vertices and faces are being loaded correctly from the OBJ, I checked the vector arrays. And the OBJ files are definitely fine, I tested the handful with another parser as well.

Any advice on how I go about solving this problem would be much appreciated. There may be some commented-out items that seem out of place because I removed about 200 lines worth of other functions. The loader/parser is a separate file altogether.

Thanks!

*For some reason I can’t post any URLs (linking/embedding images), so if you’d like to view my screenshot you can paste the following into your browser:
Screenshot: goo.gl/PJT8ST

Afterthought: I’m using GL_LINE_LOOP… Is this the reason I am not getting triangles? If I change it to GL_TRIANGLES I get pretty much the same mess with the complex objects, except they are now completely black (no more wireframe) and look even worse.

Edit: Will post link to complete program once it’s finished + summary of all issues I encountered.

It looks like your code is drawing one big line loop primitive from the raw array of all vertices in your model, hence the unwanted connection lines. You should, instead, use face definitions from the obj file to draw your primitives.

Thanks for the reply!

I did that already. It’s in my code inside the renderTriangles function I posted the link to above. I stored all the Face information inside a vertex array (facesVertices), and then as I looped through it, using the value at the current index I drew the lines using the data stored in a separate vertices array. The data inside both these should be correct.

So I figure the problem must be something else. =/

Yeah but you’re drawing just one line loop primitive so there is unwanted line drawn between the last vertex of face N and the first vertex of face N+1. You should draw each face as a separate line loop primitive. In immediate mode, this means enclosing each sequence of glVertex() calls for a particular face into its own glBegin()/glEnd() block.

So… Mutiple calls, one for each face. I am assuming that entails putting the glBegin()/glEnd() block inside my for loop that loops through the faces array, right? Instead of just before/after. I did try it. The entire mesh just disappears. >.< Is there another way to loop through calls like that?

Yeah. Here’s the pseudocode:


for each face{
	glBegin(GL_LINE_LOOP);
	for each vertex in face{
		glVertex(...);
	}
	glEnd();
}

You need to call glEnd() after the face is done. Otherwise OpenGL will just suppose you’re continuing to supply vertices to the same line loop.

Note that you can use single glBegin()/glEnd() block only if you draw primitives that have known number of vertices like triangles or quads. In that case OpenGL will automatically finish the primitive and begin the new one, even if there was no explicit glEnd() call. Line loops, however can have arbitrary number of vertices and need to be finished explicitly.

Your code might work if all of the faces are certain to be triangles (or quads):


glBegin(GL_TRIANGLES);
for each face{
	for each vertex in face{
		glVertex(...);
	}
}
glEnd();

But in the case of general purpose obj loader you can’t assume this because obj supports faces that can consist of any number of vertices.

BAHAHAHA! I found the issue. You were tooootally right when you said I was calling them all continuously - I wasn’t calling glVertex3f() THREE times. “Hey look, here’s x,y,z for one vertex, let’s just forget about the rest of the triangle shall we…”

Excellent. I can move onto sorting out my final (Hopefully that’s the last… Wishful thinking sometimes… =P) issue regarding texture binding, now that the wireframe’s are pulling through correctly. That’s another post though, heh.

Thank you so much!