Results 1 to 6 of 6

Thread: Efficiency problem with OBJ loader

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009

    Efficiency problem with OBJ loader

    I am making a simple OBJ loader that basically works like this. I parse the text file and store all the vertices/normals/faces etc in some data structures. Then in my draw function I extract the faces and make array lookups based on the positions given by the faces. I originally had implemented the Draw function to just draw quads but when I wanted to make my program work with faces of any number of vertices I had to switch to polygons and this killed my efficiency. My original code was something like this (The pseudo code is based on common lisp but its pretty basic so should be okay):

    (glBegin GL_Quads)

    loops to extract and draw


    But since now my new code has to accept faces of any number it looks more like this:
    //start loops
    (glBegin GL_polygon)

    //Draw stuff

    //end of loops

    I think because I am beginning and ending the polygon every loop cycle instead of building the draw list and drawing at the end I am killing my frame rate ( it dropped by a factor greater then 10). Is there a way I can just start the GL_polygon before the loop and then every time through just tell it how many vertices to expect then end the polygon after my loop? Or is there some other more efficient way to do this? Thanks.

  2. #2
    Member Contributor
    Join Date
    Jul 2004

    Re: Efficiency problem with OBJ loader

    You can try using display lists. Google for a tutorial, or here's one:

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Los Angeles

    Re: Efficiency problem with OBJ loader

    I import many, many OBJ files into my OpenGL simulations. Most of them are defined in Display Lists on the first iteration through the draw routine. As long as you don't have to interactively change vertex coordinates in your geometry, I'd recommend this. Are you creating the OBJ files yourself with a modeler? If so, try triangulating all of the polys before writing out the OBJ. That way you can use GL_TRIANGLES instead of GL_POLYGON in your GL_Begin statement. If you are not creating the models yourself you may be able to triangulate them using some free software such as the evaluation version of Deep Exploration (1 month only), or some other package.

    Good luck.
    Am I doing your homework for you?

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Watford, UK

    Re: Efficiency problem with OBJ loader

    Since GL_POLYGON requires convex polygons, why not simply convert the poly to triangles?
    For a clockwise 5-point poly, the triangle indices are:
    0 1 2, 0 2 3, 0 3 4

    For a clockwise 6-point poly, the triangle indices are:
    0 1 2, 0 2 3, 0 3 4, 0 4 5


  5. #5
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Nov 2010

    Re: Efficiency problem with OBJ loader

    as others have mentioned use quads or triangles instead of GL_POLYGON
    I remember reading in some opengl performance pdf,
    GL_POLYGONS == bad

    then again if youre comparing immediate mode (what u have now) with display lists (what u had first) then it will be slower, yes 10x sounds possible
    solution use VertexArrays,or VBOs to improve the speed

  6. #6
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008

    Re: Efficiency problem with OBJ loader

    I found these pages very helpful when making the jump from immediate mode to array / buffer objects..

Similar Threads

  1. Wavefront Object Loader Problem
    By vgamemaster in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-12-2012, 01:33 AM
  2. obj loader problem
    By Vincent22 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-25-2012, 03:59 AM
  3. vbo obj loader, problem with textures
    By newone in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-07-2012, 04:45 AM
  4. Wavefront obj loader material problem
    By lenka in forum OpenGL ES
    Replies: 0
    Last Post: 11-14-2010, 09:53 PM
  5. Texturing loader problem...
    By Me6 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-24-2004, 07:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean