PDA

View Full Version : bitblt to window with opengl context



blueskyday
06-21-2004, 06:21 AM
Ive just used BitBlt to a window that has an opengl double buffered context and (surprisingly) it worked.

I thought this wasn't possible! :confused:

Was I wrong or is this most likely a 'feature' of my cards opengl implementation?

Any help greatly appreciated!

itzike
06-21-2004, 06:44 AM
can you publish the specific code please?

blueskyday
06-22-2004, 07:58 AM
I suppose I should explain a bit more, sorry!

I can't put all the code up but basically Ive been using code similar to below in a well tested app for the past few years. The opengl context in this case is:
double buffered
cols 32, Z 24, alpha 8

The card is a (dont laugh) GeForce2 Mx 200 on xp pro.

//old code:
case WM_PAINT:
{
PAINTSTRUCT ps;

BeginPaint(ghWnd, &ps);

RenderScene(); //all opengl calls
SwapBuffers(ghDC);

EndPaint(ghWnd, &ps);
}
return 0;
break ;

This works ok until I get overlapping windows and the scene is complicated and of course it slows down (but thats another story). Anyway, in the msdn docs it states you can't perform gdi calls on a double buffered window but the other day I thought Id give it a go. Not as a replacement for the old code but just to see if it would work:

//test code
case WM_PAINT:
{
HDC hdcSrc;
PAINTSTRUCT ps;
HBITMAP hbmOld;

hdcSrc = CreateCompatibleDC(ghDC);
hbmOld = SelectObject(hdcSrc, ghCaptureBmp);

BeginPaint(ghWnd, &ps);

BitBlt(ghDC, 0, 0, swidth, sheight, hdcSrc, 0, 0, SRCCOPY);

EndPaint(ghWnd, &ps);

ghCaptureBmp = SelectObject(hdcSrc, hbmOld);
DeleteDC(hdcSrc);
}
return 0;
break ;

where ghCaptureBmp is a handle to a bitmap that has the same color depth as the system (and consequently the opengl context).

Anyway it worked - which was a bit of a surprise.

Now either 1) Ive always misunderstood the limitation on gdi calls to windows with opengl contexts that are double buffered or 2) the docs are wrong or 3) my card is odd.

Anybody any ideas?

Thanks in advance!

Andy

V-man
06-28-2004, 02:47 PM
GDI calls on on a double buffer don't work in the sense that the drawing doesn't occur on the backbuffer, since GDI is not aware of the backbuffer.

The second problem is that swapbuffer and GDI are not synced so you may see some flashing when you use GDI.

It's best not to mix them, cause even if it works with some card and driver, the next card or next driver update will give different behavior.

Hope this helps explain MSDN better.