Sign in to follow this  
Civilwar

Display list performance

Recommended Posts

Civilwar    137
Hi,

I am creating a simple 3D game, but I found a problem:

When I place 30 trees of ~1000 triangles (1 tree = 2 display lists (branches + trunk)), FPS are already below 50 - which is pretty bad :(

So, my question is:

Are display lists just a bad technique, or I am doing something wrong? Should I use VBOs instead?

Thanks for answers.

Share this post


Link to post
Share on other sites
Danny02    279
1. nowadays u should use VBO, because display lists are deprecated
2. your problem in this case is that u have so many draw calls and probably drawing always the trunk and branches of each tree instead of first only the trunks and then the branches,
try to render all trees in 1 display list

Share this post


Link to post
Share on other sites
Aks9    1499
60 display lists is not a great number of calls to have any problem in drawing. I handled several thousands of calls per frame.

You are probably doing something wrong. Can you post your drawing code? Are you using only glCallList() for drawing?

If you are creating your lists in a draw call, that's the reason for a significant performance drop.

Share this post


Link to post
Share on other sites
Civilwar    137
I'm using Lib3ds to load 3ds models.

Here is how it creates display list for mesh.

[code] glNewList(mesh->user.d, GL_COMPILE);
Lib3dsVector *normalL=(Lib3dsVector *)malloc(3*sizeof(Lib3dsVector)*mesh->faces);
Lib3dsMaterial *oldmat = (Lib3dsMaterial *)-1;
Lib3dsMatrix M;
lib3ds_matrix_copy(M, mesh->matrix);
lib3ds_matrix_inv(M);
glMultMatrixf(&M[0][0]);

lib3ds_mesh_calculate_normals(mesh, normalL);

glBegin(GL_TRIANGLES);
for (int j=0; j<mesh->faces; ++j)
{
Lib3dsFace *f=&mesh->faceL[j];

Lib3dsMaterial *mat=0;
int tex_mode = 0;
if (f->material[0]) mat=lib3ds_file_material_by_name(file, f->material);

if( mat != oldmat )
{
if (mat)
{
if (mat->two_sided) glDisable(GL_CULL_FACE); else glEnable(GL_CULL_FACE);
if (mat->use_wire ) glEnable(GL_ALPHA_TEST); else glDisable(GL_ALPHA_TEST);
}
oldmat = mat;
}

int i;
if (f->user.i>0)
{
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,f->user.i);
}

glNormal3fv(f->normal);
for (i=0; i<3; ++i)
{
glNormal3fv(normalL[3*j+i]);
float scale=1;
if (mesh->texels>0)
{
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,mesh->texelL[f->points[i]][0]*scale, mesh->texelL[f->points[i]][1]*scale);
}
glVertex3fv(mesh->pointL[f->points[i]].pos);
}


}
glEnd();
free(normalL);
glEndList();
[/code]

Share this post


Link to post
Share on other sites
Aks9    1499
1. move all loading code out of the display list setting (it shouldn't make trouble, but I don't know what is called inside all those functions)

2. also move out texture related functions except texture coordinate setting. (why are you using glActiveTextureARB() if only GL_TEXTURE0 is used? Also glEnable(GL_TEXTURE_2D) is superfluous here.)

Try to enclose only loop and glNormal/glTexCoord/glVertex function calls inside glNewList/glEndList. What version of OpenGL are you using? Why there is aways ARB suffix? All those functions are in core since GL 1.3 or so.

Share this post


Link to post
Share on other sites
Civilwar    137
[quote name='Aks9' timestamp='1307988886' post='4822852']
1. move all loading code out of the display list setting (it shouldn't make trouble, but I don't know what is called inside all those functions)

2. also move out texture related functions except texture coordinate setting. (why are you using glActiveTextureARB() if only GL_TEXTURE0 is used? Also glEnable(GL_TEXTURE_2D) is superfluous here.)

Try to enclose only loop and glNormal/glTexCoord/glVertex function calls inside glNewList/glEndList. What version of OpenGL are you using? Why there is aways ARB suffix? All those functions are in core since GL 1.3 or so.
[/quote]

OMG!! I moved glBindTexture outside list and FPS increased from 50 to 500 :D :D


Thank you for advice. Too bad I can't give you more than one +rep.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this