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

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.

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…

How can apply colors if I want to use VBO (or glDrawArrays) ?

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.

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

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.

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.