# Win32 GDI DoubleBuffering question

This topic is 4879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok im trying to implement double buffering and its not working and i cant find any articles on the toic, so here is what i am doing
HDC screenDC = GetDC(NULL);
HDC backDC = CreateCompatibleDC(screenDC);

TransparentImage( backDC,
(LONG)posX, (LONG)posY, (LONG)width, (LONG)height, bitmapDC,
0, 0, (LONG)width, (LONG)height,
RGB(255, 0, 255));	//Going to make this constant for now

BitBlt(screenDC,
0, 0,
GetDeviceCaps(screenDC, HORZRES), GetDeviceCaps(screenDC, VERTRES),
backDC,
0, 0,
SRCCOPY);
ReleaseDC(0, backDC);


##### Share on other sites
Try changing this:

HDC screenDC = GetDC(NULL);

to this:

HDC screenDC = GetDC(HWND);

Where HWND is the handle to your window.

Hope this helps!

##### Share on other sites
That previous post was from me. Again, I hope it helps you out.

##### Share on other sites
Thank you, that was exactly what i was looking for.

thanks again.

##### Share on other sites
Just thought I'd mention that when you do get double-buffering working that it'll only be able to eliminate the flickering; you still may notice some shearing. There's unfortunately no way around this, as there's no way to force windows into copying the backbuffer during the vertical retrace, even though there really should be. You're also out of luck in detecting it yourself and trying to copy manually during the retrace because a) GDI doesn't expose the raster state to applications, and b) even if you knew it was happening, windows is message-based (read: not real-time) so theres no guarantee you'd get the messsage fast enough anyhow. The only way to respond to real-time events is to have the support of something at a lower level, like a device driver as OpenGL and DirectX do. I have seen one successful implimentation (which was a clever hack) which had the application spawning a custom device driver in a thread which implemented a callback to the render function though.

In any event, flickering is the real enemy, shearing isn't too bad and its the same effect you'd see in any game if you have the V-sync disabled.

##### Share on other sites
Yeah i havnet noticed too much shearing, this is actually for the pocketPC. I really dont want to right my own blitters and get into the game api so i am going to use GDI stuff for very simple games, like the 80's rerto classics. But so far just double buffering tends to work pretty well, and elimenates the flicker all together.

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 104
• 11
• ### Forum Statistics

• Total Topics
632979
• Total Posts
3009682
• ### Who's Online (See full list)

There are no registered users currently online

×