one thread and OpenGL screen refresh

Started by
4 comments, last by V-man 15 years, 7 months ago
Hi, My application runs with one single thread. This means I have my window and dialog messages handling, then some calculation to move objects, then the rendering. After rendering the loop starts again with the messages handling and so on. This works very nicely and I don't have any major problem. This also gives me very consistent and smooth renderings (compared to a rendering thread in parallel to a calculation thread). My only problem is when I for instance move one dialog to a different position: then, the background (the OpenGL view) doesn't get refreshed until I release the mouse button. The solution I have come up with is to swap the rendering buffers everytime the dialog moves (I do this in the dialog's 'WindowProc' by monitoring the 'WM_WINDOWPOSCHANGING' message). I swap the rendering buffers twice in order to just refresh the background, because the two buffers might not contain the same image. So I do: SwapBuffers(mainWindow->hDC); SwapBuffers(mainWindow->hDC); However the first swap is also visible (escpecially on slow computers) and this makes my OpenGL content 'shake' when I move a dialog. How can I avoid this? Is it possible to swap the buffers without actualizing the window (for the first swap)? Or is it possible to obtain two swaps at once? Or to simply copy the current buffers's content to the window? Thanks
Advertisement
If you move a dialog window and the GL window doesn't refresh, then yuo aren't handle rendering when WM_PAINT messages are sent. The problem is your applications. Personally, I've never had any problems.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
either way, you also render the whole scene if it hasn't changed?!
Yes, I always render the scene when a WM_PAINT message is sent.
If you want to backup your scene, you need to render to a FBO and then do FBO blitting or render to texture and render a texture quad that covers the scene.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Ok, so is rendering to FBO supported by all systems/graphiccards? It seems a litle bit overkill to me, I just need to copy the last displayed buffer to the screen. Isn't there a simpler way of doing this?
Or would someone have a quick code sample ready for what I want to do? (using the FBO and doing the blitting) I would appreciate a lot.
Another related question: if I render to the FBO, is that like rendering to an internal buffer that I can then use for other things (e.g. check the depth values, etc.)? I know that when checking the regular OpenGL buffer, it only works when there is no other window in the way...

Thanks
It depends on what you are targetting. It seems as if all drivers that support GL 2.0 or 2.1 support the FBO extension. In GL 3, it became core and some changes are made like relaxing the restrictions.

Much older cards like TNT, Geforce 256 are no longer supported by nVidia.
However, they support p-buffers but that's not easy to work with.

An FBO is an offscreen buffer. So is p-buffer.
Examples can be found in the extension spec.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement