I've seen people who've written in code where the graphics of a scene are rendered in response to WM_PAINT. I only ever rendered the scene once all Windows messages were done translating, and then rendered the scene. Is this the wrong way to go about it, or should I only use DirectX rendering in response to WM_PAINT?
WM_PAINT response code is a convenient place to put rendering routines, especially when rendering in a window, but I believe - it is not the best.
WM_PAINT message is recieved by window message loop when system wants to update its contents, eg. during moving or resising window or when window content is showed again due to closing other overlapping window. Rendering in response to WM_PAINT assures that rendered content stays accurate. It is up to programmer to assure that WM_PAINT is posted to window's message queue often enough, to keep up to the desired rendering framerate. It can be achieved by calling
It is not necessary to do it that way, as in fact- posting and processing window messages can introduce a significant delay to rendering pipeline.
Better way is to call rendering routines from the message loop itself, something like this: