Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Wireframe Loading Issue - Lines Out of Place

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2014
    Posts
    10

    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.
    Last edited by LunaLux; 01-27-2014 at 01:01 AM. Reason: Removed link to incorrect code

  2. #2
    Intern Newbie
    Join Date
    Jan 2014
    Posts
    40
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2014
    Posts
    10
    Quote Originally Posted by nenad* View Post
    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. =/

  4. #4
    Intern Newbie
    Join Date
    Jan 2014
    Posts
    40
    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.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2014
    Posts
    10
    Quote Originally Posted by nenad* View Post
    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?

  6. #6
    Intern Newbie
    Join Date
    Jan 2014
    Posts
    40
    Yeah. Here's the pseudocode:
    Code :
    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):
    Code :
    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.

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2014
    Posts
    10
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •