Raising 3D Game Frame rate

Started by
15 comments, last by i_luv_cplusplus 16 years, 6 months ago
I made a 3d game/engine, and it is currently displaying maybe 7-9k polygons. My frame rate is really bad, dipping down as low as 10 fps. I am trying to find some ways of techniques to raise my frame rate. I am using 256x256 textures, and i tried reducing them all to 128x128, and that bumped it up to about 15 fps at the lowest. Are textures the biggest source of rendering lag? what is the normal resolution for textures? Are there any setings i could do like face culling that would help? and how much would it help. I have noticed in games how they cut corners to lower the FPS, like not displaying "extra scenery" like barrels unless you are pretty close, like in Half Life 2. Does this help a lot? Also, does the size of the polygon effect the rendering time? I am using OpenGL if that matters. Obviously in the top end games they are displaying tons more polygons than I am, so i must be doing something really wrong. Any ideas or comments on this subject would be greatly appreciated. I want to at least double my fps, so i can add more stuff with out slowing the computer to a hault, thx.
Advertisement
Modern games might use 7k-9k triangles on a single model, and have up to 500k triangles in a scene... so yeah, assuming you have a new-ish gfx card, you can definately improve your FPS.

My guess would be that you're rendering your triangles using old, CPU-powered draw methods (e.g. glVertex3f calls).

If this is the case, look into indexed meshes and triangle strips (techniques to reduce the overall size of your mesh data), and vertex buffer objects (a technique to store your mesh in video RAM, so that the CPU doesn't have to transfer the data from system RAM every frame).

As a reduction in your texture sizes gives such a big boost in framerate there's a couple more things you should look into:

1. Are you using mip mapping?
2. How many textures are you using? Are you running low on video ram?

Also what graphics card are you using?
Also, are you sorting your polygons by render state to minimize the amount of times you bind shaders and textures?
most important question: are you actually getting hardware acceleration ? e.g. have you installed your graphics drivers and what does glGetString(GL_VENDOR); return ?
And I also read somewhere that "you can really render objects fast, if you don't render them at all". So if you don't need to render something (like wall behind your back) then don't render it. That is culling, and it helps you a lot. It is worth to implement. Textures of 256x256 are ok. Also calling object render functions lot of times is LOT SLOWER than batching objects and render them in one or two calls.
There is one good engine that was made from good idea and batch a lot. It is Cube Engine. It is made in OpenGl so I think you can learn something from it (it is open source [smile]),
Quote:Original post by streamer
And I also read somewhere that "you can really render objects fast, if you don't render them at all". So if you don't need to render something (like wall behind your back) then don't render it. That is culling, and it helps you a lot.


does glEnable(GL_CULL_FACE); do this sufficiently? or should i write my own.



Quote:Original post by Adam_42
1. Are you using mip mapping?
2. How many textures are you using? Are you running low on video ram?

Also what graphics card are you using?


This is not a problem on just my computer, I have tested my game on 4 different ones, and it is slow on all of them. This is more about properly coding it than my computer sucking(which it REALLY does :( ).



Quote:Original post by Hodgman
Modern games might use 7k-9k triangles on a single model, and have up to 500k triangles in a scene... so yeah, assuming you have a new-ish gfx card, you can definately improve your FPS.

My guess would be that you're rendering your triangles using old, CPU-powered draw methods (e.g. glVertex3f calls).


Wow, i didnt realize how low polygons i actually have. Yes I am using glVertex3f, but that is because I load and run my 3d models in the same format that they are in the .obj file. I am rebinding the texture and making a new GL_triangle this for each triangle in the model, which I am guessing now is a REALLY slow thing to do. Should i write some way to organize the triangles so that they could be used with a triangle strip, and is there some better file format than .obj that mignt do some of this for me?

EDIT: I fixed so it only binds the texture once for each model, and the fps on my comp raised form 1 to 5!(Im on a windows 98 computer, so the important fact is that it raised so much, not that it is 5 lmao, yes i need i new comp). Keep the tips coming, thx!


I am set on making my own engine for the game, so I want to learn how to do all of this stuff. I will google all the stuff you guys have suggested.

Some more question:
-Is there a rendering difference between different shapes, like gl_polygon, gl_trinagles, gl_quads?
-What is the normal frame rate for games? Ive heard 60, is that good enough?

Thx for all of the posts! I really appreciate it.

[Edited by - bovinedragon on October 2, 2007 8:28:12 PM]
Quote:Original post by bovinedragon
Yes I am using glVertex3f

You can replace all of your glVertex3f calls by using VBO's (assuming your graphics card supports this feature).

glVertex is slow, because it requries the CPU to do a lot of work constructing the mesh every frame, and has to transfer this mesh data from RAM to the video card every frame. If you use a VBO, then the CPU hardly has to do a thing, and there is no transfer from RAM anymore.

Quote:should i write some way to organize the triangles so that they could be used with a triangle strip, and is there some better file format than .obj that mignt do some of this for me?

NVidia provides a free library that can do this for you on the fly, called NVTriStrip. I'm not sure how hard it is to use though - the amount of effort it might take you to use this library might not pay off in a big FPS improvement.

Quote:-Is there a rendering difference between different shapes, like gl_polygon, gl_trinagles, gl_quads?

If you use quads/polies, then the driver will automatically convert your quads/polygons into triangles on the fly, which is slow. You should always use triangles, lines or points.

Quote:-What is the normal frame rate for games? Ive heard 60, is that good enough?

Anything above 24fps is good enough, 30fps is average, 60fps is great.

Quote:Original post by bovinedragon
Quote:Original post by streamer
And I also read somewhere that "you can really render objects fast, if you don't render them at all". So if you don't need to render something (like wall behind your back) then don't render it. That is culling, and it helps you a lot.


does glEnable(GL_CULL_FACE); do this sufficiently? or should i write my own.

for a 7-9k poly scene this is good enough. When you have more models / polygons on screen look into frustum culling, which will stop every model that won't be on the screen from being rendered.


Quote:
I am rebinding the texture and making a new GL_triangle this for each triangle in the model, which I am guessing now is a REALLY slow thing to do. Should i write some way to organize the triangles so that they could be used with a triangle strip, and is there some better file format than .obj that mignt do some of this for me?

1. If you can already load .obj files, then stick with them for now.
2. Don't call glBegin() for every triangle ! This might be the biggest slow-down in your code at the moment. Do it once for each model, like the the texture binding, and then just call glVertex* as often as you have to.
3. As you already have the triangle and vertex information, putting all that in a vertex array once intead of drawing it should be pretty straight forward.
4. When you have a vertex array using a VBO to upload it to video memory is only a little more work.
5. Then you can remove all duplicate vertices from your vertex array and build an index buffer to go allong with the vertex buffer, which will save some memory and might give another speed increase.
6. Optimize vertex/index order to utilize the vertex cache as good as possible. I think both ATi and NVIDIA have tools for this on their homepages.
Just because you are loading obj files it doesnt mean that you cant use glDrawArrays or glDrawElements in OpenGL or VBO's. When you are loading an obj just construct the structure in such a way that you can send the data in one go during a render call for each model using glDrawArrays or glDrawElements. If you can manage that then you can easily modify the code to use VBO's. That should probably give you a major framerate boost from glVertex3f calls.

Coming to OpenGL culling, you want to reduce the amount of data you are sending down the card before the driver does that work for you so do it on a high level basis once and then let the card do it for more finer based culling. But only worry about that when you get to more triangles than what you currently have. For the number of triangles you have OpenGL culling should work just fine.

The more applications I write, more I find out how less I know

This topic is closed to new replies.

Advertisement