OpenGL effecient rendering

Hi all,

Strangely, my previous post asking the same question mysteriously disappeared.

My problem is that I want to have opengl render lets say, 60 fps. But I can't find an effecient way to do that. I use a window made with the winapi. Does anyone has good idea?

Thank you.
If you want more speed, use display lists, if you want some kind of a fps limiter use the sleep function to sleep a little bit between every frame, based on the amount of time it took to calculate that frame. Though i dont know how would you get the time elapsed while rendering the frame but im pretty sure you can find it quicly using google...
I'm already using the time that elapsed after the previous frame had to start render, so that movement is based on real time instead of amount of frames.

Display lists? Never heard of that, but I'll look into it, thank you.
Hmmm, display lists seems to be deprecated in OpenGL 3.1. I don't want to use deprecated functionality in order to remain forward compatibility with the newest versions.
But thank you anyway. Someone else got any good idea?

Here are the things I already tried (and failed in effeciency):
* Use PostMessage( WM_PAINT); in the WM_PAINT event handler. The window doesn't respond that well anymore (I was hoping actually it would put the message at the end of the queue so that every message would be handled properly).
* Have an extra thread post the WM_PAINT message. Same problem.
* Have an extra thread use the SwapBuffers function (I'm using double buffers so SwapBuffers is used to render the just drawn frame). This doesn't work, apparantly SwapBuffers has to be called from the same thread.

And BTW, I would know where to put and how to use the sleep function in order to get a steady frame rate.

Thank you.
Ow and BTW, I'm starting to transform my engine little by little to use the pipeline that it is meant for it nowadays. Vertex buffer in video card memory with shaders. I only need to know how to call my render function properly.
Not sure if i get what you want correctly but if you want to limit the amount of times you render your scene to 60 times per second you can just do this around you call to where ever you render your scene:

static float elapsed = 0;
elapsed += getElapsedTime();
if (elapsed > 1/60)
{
//Render Scene
elapsed = 0;
}

Looking at your question again makes be doubt this is what you asked for so maybe you can elaborate your question a bit more?
There is no easy, general method to make the rendering faster. I wouldn’t count that changing window API or something will noticeably improve efficiency. You also didn’t provide any details about your program, so it’s hard to give you any specific advice. So instead I will give you some general ones:

1) Optimize the rest of your program so that the renderer has more time for its own processing.

2) Efficiency of rendering depends most on the amount of data you pass to the renderer. Try not to render polygons that are not visible (outside of the screen boundaries or hidden after other polygons), use lower detail models for far object, etc.

3) Don’t do what is not needed / has no visible effect. Try to design you program so that you can remove some costly operations (i.e. clearing buffers). Don’t repeat the same actions. Make the state changes (like changing the current texture) as rare as possible.

4) Try to move as much processing as possible outside the rendering loop (i.e. do costly calculations only once if possible).

5) Try to limit the amount of vertices the reneder needs to process. Use rendering method that allows you to process “shared” vertices once (i.e. vertex/polygon arrays).

6) Take advantage of OpenGL extensions.

7) Read about some high-quality engines and/or study their code. This way you can greatly improve your knowledge on the matter, and also find some very useful and rarely mentioned “tricks” to make the rendering a little faster.

… and many more I can’t think about right now. It would be better if you could describe your program more: what you render, what algorithms / data structures you use, etc.
Last edited on
Topic archived. No new replies allowed.