views:

1199

answers:

6

Hi!

How can we run a OpenGL applications (say a games) in higher frame rate like 500 - 800 FPS ?

For a example AOE 2 is running with more than 700 FPS (I know it is about DirectX). Eventhough I just clear buffers and swap buffers within the game loop, I can only get about 200 (max) FPS. I know that FPS isn't a good messurenment (and also depend on the hardware), but I feel I missed some concepts in OpenGL. Did I ? Pls anyone can give me a hint ?

+2  A: 

AOE 2 is a DirectDraw application, not Direct3D. There is no way to compare OpenGL and DirectDraw.

Also, check the method you're using for swapping buffers. In Direct3D there are flip method, copy method, and discard method. The best one is discard, which means that you don't care about previous contents in the buffer, and allow the driver to manage them efficiently.

Mad Fish
ohh... great ! because I don't want the previouse data. Pls can anyone tell me how to do it in openGL ?
Morpheus
A: 

One of the things you seem to miss (judging from your answer/comments, so correct me if I'm wrong) is that you need to determine what to render.

For example as you said you have multiple layers and such, well the first thing you need to do is not render anything that is off screen (which is possible and is sometimes done). What you should also do is not render things that you are certain are not visible, for example if some area of the top layer is not transparent (or filled up) you should not render the layers below it.

In general what I'm trying to say is that it is in most cases better to eliminate invisible things in the logic than to render all things and just let the things on top end up in the rendered image.

kkaploon
Hey! Thanks for the responce. I have done all those optimizations (as far as i know about the OpenGL - btw, I know only little about OpenGL) I wont draw anything outside the screen and non-visible areas. And also I wont use depth-test when i can (say the ground layer). hmm... but i think, I'm doing something wrong...
Morpheus
+2  A: 

I'm getting roughly 5.600 FPS with an empty display loop (GeForce 260 GTX, 1920x1080). Adding glClear lowers it to 4.000 FPS which is still way over 200... A simple graphics engine (AoE2 style) should run at about 100-200 FPS (GeForce 8 or similar). Probably more if it's multi-threaded and fully optimized.

I don't know what exactly you do in your loop or what hardware that is running on, but 200 FPS sounds like you are doing something else besides drawing nothing (sleep? game logic stuff? greedy framework? Aero?). The swapbuffer function should not take 5ms even if both framebuffers have to be copied. You can use a profile to check where the most CPU time is spent (timing results from gl* functions are mostly useless though)

If you are doing something with OpenGL (drawing stuff, creating textures, etc.) there is a nice extension to measure times called GL_EXT_timer_query.

Some general optimization tips:

  • don't use immediate mode (glBegin/glEnd), use VBO and/or display lists+vertex arrays instead
  • use some culling technique to remove objects outside your view (opengl would have to cull every polygon separately)
  • try minimizing state changes, especially changing the bound texture or vertex buffer
Maurice Gilden
Hey! thanks for the tip. nope, I wont do anything other than drawing. I thought to use VBO, but all the features upto OpenGL 2.0 are available in my machine other than features in 1.5. So, i think i have to use GL_ARB_vertex_buffer_object ? is it? Sorry, I dunno much :(
Morpheus
Yes. GL_ARB_vertex_buffer_object = VBO. And as far as I know they didn't change anything between the extension and the OpenGL 2.0 specs.
Maurice Gilden
yeah..may be. But I can't use any of these, glBeginQuery: glBindBuffer: glBufferData: glBufferSubData: glDeleteBuffers: glDeleteQueries: glEndQuery: glGenBuffers: glGenQueries:
Morpheus
Ok sorry, they did change the names. All the above should have ARB at the end (e.g. glBindBufferARB). Also read http://stackoverflow.com/questions/14413/using-opengl-extensions-on-windows for how to use extensions.
Maurice Gilden
thanks... can you tell me pls that, will I able to get performance gain by VBO when I using about 3000 textures only (no 3Ds stuff) ?
Morpheus
+1  A: 

You are running in release mode, right?

Mark Simpson
in both modes results are same :(
Morpheus
A: 

And another thing, I wont use any fancy 3D, only drawing tons (tons == 3000) of 2D textures. So, is it possible to gain much performance by using VBO ?

Morpheus
If it's only 50-100 textures per frame I don't know what would be better, but if it's more try to combine those into as few textures as possible because that's where you waste most of your time.
Maurice Gilden
I'm very much like to do it, but I have animations as sheets, so there are already large textures. Therefore unfortunatly I can't combine those texture more than they exsist atm. ok..then I'll try VBO myself and then compare the performance.
Morpheus
A: 

If your textures are small, try to combine them in one bigger texture and address them via texture coordinates. That will save you a lot of state changes. If your textures are e.g. 128x128, you can put 16 of them in one 512x512 texture, bringing your texture related state changes down by a factor of 16.

karx11erx