Hey,
According to the tutorial, I should draw a white rectangle over the whole area (to clear the backbuffer, then draw the primitives to the backbuffer, then present the backbuffer to the window. This needs to be done as first clearing Windows, then presenting backbuffer = 2 draws = still flickering).
So, the updated code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
case WM_PAINT:
hdc = backbuffer->getDC();
oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(WHITE_BRUSH));
Rectangle(hdc, 0, 0, 640, 480);
if(MouseDown)
shape->draw(hdc);
for(vector<Shape*>::size_type i = 0; i < shapes.size(); i++)
shapes[i]->draw(hdc);
backbuffer->copy();
SelectObject(hdc, oldBrush);
return 0;
|
This works and the flickering effect is gone (that was what I was trying). The drawing works fine now (there is still a small problem which I'm trying to find out now), but is this logic? Isn't this a HUGE memory waste now?
- A new, white rectangle is drawn in the backbuffer ("clearing" it)
- The shapes are drawn in the backbuffer
- The backbuffer is presented
But, on the next paint message, a new rectangle is drawn to the backbuffer to clear it. But the old shapes aren't removed from it; the rectangle is only drawn OVER these primitives. So with every paint message, the shapes from the previous paint message are presented too.
Or am I seeing this wrong?
Other than this, the program still hangs when trying to exit it/opening a dialog box. For some reason, I can open the dialog with pressing ctrl when the program hangs.
Thanks
EDIT:
The program uses about 25% CPU, so something is still terrible wrong with it.