openGL SwapBuffers
-
I would like to check the following idea having problems or not... :) 1. Initiates openGL with double buffer enabled 2. Render something to back buffer and call SwapBuffers. 3. Render the same again. (To fill the other buffer) 4. Called SwapBuffers only for handling WM_PAINT. That is, no repeated rendering since there is no change in what to draw. So the point is that, rendering is done when needed to modify the drawing. But whenever repainting is needed the buffer is just swapped to retain the painting. I checked the same and its working fine. But rendering need to be done two times to update both front and back buffers. Is this way OK? If so how can I avoid the rendering two times?
- NS - [ODBaseBtn]
-
I would like to check the following idea having problems or not... :) 1. Initiates openGL with double buffer enabled 2. Render something to back buffer and call SwapBuffers. 3. Render the same again. (To fill the other buffer) 4. Called SwapBuffers only for handling WM_PAINT. That is, no repeated rendering since there is no change in what to draw. So the point is that, rendering is done when needed to modify the drawing. But whenever repainting is needed the buffer is just swapped to retain the painting. I checked the same and its working fine. But rendering need to be done two times to update both front and back buffers. Is this way OK? If so how can I avoid the rendering two times?
- NS - [ODBaseBtn]
-
No need to render twice, render once and copy.
// Back buffer to front.
glReadBuffer(GL_BACK);
glDrawBuffer(GL_FRONT);
glCopyPixels(GL_COLOR);// Front buffer to back.
glReadBuffer(GL_FRONT);
glDrawBuffer(GL_BACK);
glCopyPixels(GL_COLOR);Thank you very much... I am just entering to the world of openGL :) Could you please tell me that the idea of doing SwapBuffer only, in response to WM_PAINT, is good? Is there any problem in that? Or is there any better solution? Thank you.
- NS - [ODBaseBtn]
-
Thank you very much... I am just entering to the world of openGL :) Could you please tell me that the idea of doing SwapBuffer only, in response to WM_PAINT, is good? Is there any problem in that? Or is there any better solution? Thank you.
- NS - [ODBaseBtn]
Matters on what you are trying to do, you don't need to use wm_paint at all, you can update the render whenever you feel you need to. If you need to continually update the window, u can use a pump, ie:
bool quit = false; while(!quit) { PeekMessage(&msg, hwnd, NULL, NULL, PM\_REMOVE); if (msg.message == WM\_QUIT) { quit = true; } else { DoRendering(); TranslateMessage(&msg); DispatchMessage(&msg); } }
Or you can simply swap buffers when u only render, not on every paint.
-
Matters on what you are trying to do, you don't need to use wm_paint at all, you can update the render whenever you feel you need to. If you need to continually update the window, u can use a pump, ie:
bool quit = false; while(!quit) { PeekMessage(&msg, hwnd, NULL, NULL, PM\_REMOVE); if (msg.message == WM\_QUIT) { quit = true; } else { DoRendering(); TranslateMessage(&msg); DispatchMessage(&msg); } }
Or you can simply swap buffers when u only render, not on every paint.
-
Matters on what you are trying to do, you don't need to use wm_paint at all, you can update the render whenever you feel you need to. If you need to continually update the window, u can use a pump, ie:
bool quit = false; while(!quit) { PeekMessage(&msg, hwnd, NULL, NULL, PM\_REMOVE); if (msg.message == WM\_QUIT) { quit = true; } else { DoRendering(); TranslateMessage(&msg); DispatchMessage(&msg); } }
Or you can simply swap buffers when u only render, not on every paint.
-
Now got another problem... if we lock windows and then unlock the drawing in the buffers are lost... What should be done to handle windows lock/unlock conditions? Thank you.
- ns -
-
I get the feeling that the best approach for you is to use a FBO and do offscreen rendering. Google "opengl render to texture", you can bind a frame buffer at the start of your rendering, then blit it as needed.