Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw OpenGL content while resizing win32 window

Tags:

winapi

opengl

While resizing win32 window, with OpenGL context, it just shows black on the newly exposed area. I do get WM_PAINT message while resizing, and I do try to render new content, but it seems as if SwapBuffers does nothing, while resizing.

How should window resizes be handled correctly, so that there is no "broken" content while resizing?

like image 515
scoopr Avatar asked Jul 06 '11 07:07

scoopr


1 Answers

This usually happens if you have a background brush configured for your window's class (see the WNDCLASS or WNDCLASSEX structure). If there's a brush, the system will clear the window right after each redraw step, then send the WM_PAINT. In case of V-Synced SwapBuffers your picture may have been overdrawn by the next resizing step before the buffer swap happened, or just right after it, but before that part of the screen was sent to the display device.

Either way, the solution is to set the background brush of the window to NULL. Also tinkering with the WM_ERASEBKGND message handling may give results.

EDIT due to comment

If the content of the last frame stays visible, you probably just don't react to resizing with a redraw. The easiest solution to this is calling the drawing function from the WM_SIZING (or the WM_SIZE, just try both) message handler.

like image 104
datenwolf Avatar answered Nov 05 '22 13:11

datenwolf