Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: bitblt to window with opengl context

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    3

    bitblt to window with opengl context

    Ive just used BitBlt to a window that has an opengl double buffered context and (surprisingly) it worked.

    I thought this wasn't possible!

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

    Any help greatly appreciated!

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    Israel
    Posts
    18

    Re: bitblt to window with opengl context

    can you publish the specific code please?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    3

    Re: bitblt to window with opengl context

    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

  4. #4
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: bitblt to window with opengl context

    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.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •