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 8 of 8

Thread: obj laoder performance

  1. #1
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    52

    obj laoder performance

    Hi everyone,

    I'm developed a simple demo of a tron arcade-like game.
    I wrote an obj loader to draw my cycles, my problem is that I have a great loss performance when I draw more then one cycle at the same time (I need no more then two cycles).
    How can I solve this problem?

    I draw my cycles using immediate mode (glBegin,glEnd), should I use VBOs? Can I improve performance using immediate mode?

    thank you

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171
    How can you improve immediate mode performance? Try and batch as much as possible into the same begin..end block. Avoid switching materials as much as possible.
    Of course that's all rubbish compared to doing it properly. By the time you have read your OBJ model you have already extracted the data and presumably stored it somewhere (a vertex array, normal array, etc). So why don't you just upload those into a buffer object - now rendering will be significantly quicker.

  3. #3
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    52
    the problem was that I call glBegin for each obj model face.

    Now I've noticed a new problem, after playing for several minutes there's a bad framerate loss even If I remove all algorithm expect the cycle movement one...

  4. #4
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    52
    How can apply colors if I want to use VBO (or glDrawArrays) ?

  5. #5
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171
    How can apply colors if I want to use VBO (or glDrawArrays) ?
    By creating a vertex array containing the per-vertex colour, in the same way you'd create a per-vertex array containg the x,y,z values.
    Instead of drawing per face with begin..end, get all the triangles for each material grouped as one array, or even better as a bunch of indicies. Then you can draw all triangles for each material with one drawelements call. This means you'll need to pre-process the OBJ model after you have loaded it to groups of triangles by material reference.

  6. #6
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    52
    Thank you, I use glDrawArray (no indices) and it works fine, I apply normals, vertexs and colors. I made a lot of initialization stuff in my display Func (glGenBuffer, glBufferData, etc..), now I make initializations only once and I solved the other bad performance problem (70% of CPU usage against 20%!), the game crash no more (and no framerate decrease).

    Last quastion: using VBO how can apply material params? Using glBegin..glEnd I put

    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat->Ka);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat->Kd);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat->Ks);
    before "glColor" for each material.
    Now how I can pass to Opengl the same informations? Without passing them I cannot "turn on" light in my scene
    Last edited by Vincent22; 05-25-2012 at 08:00 AM.

  7. #7
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171
    I think at some point you're going to have to come to the conclusion that you need to support GLSL shaders. Per-vertex lighting using the fixed function rendering is actually rubbish anyway! Switching to per-pixel lighting is the way to do things these days and the materials you supply would be in the form of textures (specular map & normal map) and a albedo texture (the usual diffuse texture map).
    It looks like you may have reached the end of the road for the FF pipe line and now you need to reach into the world of shaders. These are way more powerful and you'll get the results you want.

  8. #8
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    52
    Yes I know Bionic.

    Actually my "demo" should be in its final form for wednesday so I don't have the time to improve my GLSL knowledge, but I'll follow your suggestion in the future.

Posting Permissions

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