Jump to content
  • Advertisement
Sign in to follow this  
cignox1

OpenGL my second step with openGL: improving perf.

This topic is 4499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Finally I was able to make my 3ds importer work (more or less) and now I can render some more interesting model. But framerate drops down to 10 with a 100/150 polys model (I own a geForce 6600); ok. The model I use is covered by a 512x512 texture, using uv coords. I use 2 lights, linear mapping (no mip mapping), perspective correction to nicest and so on. Then this is my rendering code:
bool Render()
{
    //OpenGL initialization commands
    glClearColor(0.0, 0.0, 0.0, 0.5);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //Reset the modelview matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    //Rotate the triangle
    glTranslatef(0.0f,-1.0f,-25.0f);
    glRotatef(angle,0.0,1, 0.0);
    angle += 0.2;

	glBegin(GL_TRIANGLES);// Drawing Using Triangles
	int c = 0;

	for(int i = 0; i < numfaces; ++i)
	{
        glNormal3f(normals[i*3], normals[i*3+1], normals[i*3+2]);
     
        float v[4]; v[0] = matt.diffuse_rgb[0]/256.0; v[1] = matt.diffuse_rgb[1]/256.0; v[2] = matt.diffuse_rgb[2]/256.0; v[3] = 1.0;
       
        glTexCoord2f(mapcoords[faceslist[c]*2], mapcoords[faceslist[c]*2+1]);
        glVertex3f( geom[faceslist[c]*3], geom[faceslist[c]*3+1], geom[faceslist[c]*3+2]);
		c++;
     
        glTexCoord2f(mapcoords[faceslist[c]*2], mapcoords[faceslist[c]*2+1]);
        glVertex3f( geom[faceslist[c]*3], geom[faceslist[c]*3+1], geom[faceslist[c]*3+2]);
		c++;
		
		glTexCoord2f(mapcoords[faceslist[c]*2], mapcoords[faceslist[c]*2+1]);
		glVertex3f( geom[faceslist[c]*3], geom[faceslist[c]*3+1], geom[faceslist[c]*3+2]);
		c++;
    }
	glEnd();// Finished Drawing The Triangle

    SDL_GL_SwapBuffers();
    frames++;
    return true;
}


I understand that these are my first steps in opengl (I did few things some years ago, but just to experiment, nothing more) and wonder how can these lines be a problem for a card that runs quake 4 at 40 fps :-) EDIT: I use SDL, if that matters. And with the 'cube' model (without textures and so on) I reach 150 fps.

Share this post


Link to post
Share on other sites
Advertisement
I think 150 poly model should be able to be drawn in immediate mode (i.e. calls to glVertex as opposed to glDrawElements) at 100's of fps. IMO there must be something wrong in another part of your code.
I am using a Geforce fx 5600 and am drawing a 3000+ polygon model in immediate mode at 50+ fps, using exactly the same technique you are (except for no SDL).

Share this post


Link to post
Share on other sites
One optimisation I see is this line:

float v[4]; v[0] = matt.diffuse_rgb[0]/256.0; v[1] = matt.diffuse_rgb[1]/256.0; v[2] = matt.diffuse_rgb[2]/256.0; v[3] = 1.0;

Can you divide by 256 in the initialization code instead? This will make it a little faster, but it should not be responsible for the huge performance loss you are seeing.

Also, you don't need to call glClearColor each frame. You can also probably take out the call to glMatrixMode as it should still be set to GL_MODELVIEW from the previous frame.

Just make sure you do those two things somewhere in your code.

Share this post


Link to post
Share on other sites
Thank you for the help. Of course, the code I posted is not a real project, only a small app made to test the 3ds importer. If I set off the texture, I get 90 fps. With the textures on, I get 10. The texture is a tga file, so BGRA (because it contains an alpha channel. The main problem is then something related to textures, but I don't know what.

Share this post


Link to post
Share on other sites
Have you updated your drivers recently? I know that with ATI cards, not having catalyst makes OpenGL crawl at abnormal speeds, particularly in immediate mode. I figure GeForce might behave the same way.

If you still have your default drivers, upgrade. It's worth a shot; my game runs well over 1500 FPS in immediate mode and features ~1000 textured polies, badly-optimized billboarding (read: multiple unecessary world matrix manipulations), multiple background layers (old-school style, which covers the entire BG), no poly sorting, and a few other things. If a 100 poly model crawls, something is wrong and it almost certainly isn't your code...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
...The texture is a tga file, so BGRA...


BGRA? I don't know much about OpenGL but that raises alarm bells for me. Try swapping the red and the blue channels and then use GL_RGBA for glTexImage2D and see if that improves your performance.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
...The texture is a tga file, so BGRA...


BGRA? I don't know much about OpenGL but that raises alarm bells for me. Try swapping the red and the blue channels and then use GL_RGBA for glTexImage2D and see if that improves your performance.


Drivers are updated to the latest version (anyway, I installed them 1 month ago). I tried using RGBA but I get exactly the same results...

Share this post


Link to post
Share on other sites
What are your computer specs and what OS are you compiling and running this on?

BGR or RGB won't make any difference. TGA is BGR, so you should be using that or else inverting all your color data in the texture.

The problem here is most likely your computer. Download some of the Nehe tutorials and tell us what FPS you get on those. If they are still low, the issue is with your computer and not with the code. If those are fast then the issue is with your code and not the computer.

Share this post


Link to post
Share on other sites
Quote:
Original post by wyled
What are your computer specs and what OS are you compiling and running this on?

BGR or RGB won't make any difference. TGA is BGR, so you should be using that or else inverting all your color data in the texture.

The problem here is most likely your computer. Download some of the Nehe tutorials and tell us what FPS you get on those. If they are still low, the issue is with your computer and not with the code. If those are fast then the issue is with your code and not the computer.


Well, athlon xp 2600Mhz+, 512Mb ram and geForce 6600. I run quake 4 and far cry without problems... As soon as I can I will try to compile a nehe example...

Share this post


Link to post
Share on other sites
everything you've described should run much much faster.
make sure you are only loading the texture once, creating the texture once etc. other than that it's anyones guess without seeing the code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!