CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Opengl; Write to Bitmap and alpha channel

    Hello,

    I'm writting a program that needs OpenGL to render to a Bitmap rather than a window.
    However, when I specify PFD_DRAW_TO_BITMAP in the PIXELFORMATDESCRIPTOR, it seems that alpha bits are not written to the bitmap. Colors work as expected... and I know it's rendering properly, since I have a few read pixel loops to varify the results. This is really frustrating and about to switch to Direct3D if there isn't a solution. I can only use Opengl version 1.2... and I can't use glReadPixel or Transfers of any kind since I get 1/3 speed increase in my algorythims not using them. The whole point of DRAW_TO_BITMAP was to elliminate the pixel transfer overhead.

    I have tried many variations to the code below, including zero alpha bits, alpha shift's, stencil bits, flags, depthbits and color bits. Nothing seems to work what so ever. Only when using the PFD_DRAW_TO_WINDOW are the alpha bits written to the main buffer.

    PIXELFORMATDESCRIPTOR pd;
    ZeroMemory(&pd, sizeof(pd));
    pd.nSize = sizeof(pd);
    pd.nVersion = 1;
    pd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
    pd.iPixelType = PFD_TYPE_RGBA;
    pd.cColorBits = 32;
    pd.cDepthBits = 32;
    pd.cAlphaBits = 8;
    pd.cAlphaShift = 0;
    pd.cBlueBits = 8;
    pd.cRedBits = 8;
    pd.cGreenBits = 8;
    pd.cStencilBits = 8;
    pd.iLayerType = PFD_MAIN_PLANE;
    int format = ChoosePixelFormat(cubeDC, &pd);
    if (!format) {
    ErrorCode("ChoosePixelFormat");
    return false;
    }


    In creating the Bitmap itself, I have also tried many variations to no avail:

    cubeDC = CreateCompatibleDC(MainWindowDC);
    if (!cubeDC) {
    ErrorCode("CreateCompatibleDC");
    return false;
    }
    //SetBkMode(cubeDC,TRANSPARENT); yeah, even tried this!

    BITMAPV5HEADER bh;
    ZeroMemory(&bh,sizeof(bh));
    bh.bV5Size = sizeof(bh);
    bh.bV5Width = CubeResolution;
    bh.bV5Height = CubeResolution;
    bh.bV5Planes = 1;
    bh.bV5BitCount = 32;
    bh.bV5Compression = BI_BITFIELDS;
    bh.bV5RedMask = 0x00FF0000;
    bh.bV5GreenMask = 0x0000FF00;
    bh.bV5BlueMask = 0x000000FF;
    bh.bV5AlphaMask = 0xFF000000;
    cubeBM = CreateDIBSection(cubeDC, (BITMAPINFO *)&bh, DIB_RGB_COLORS, &cubeBits, NULL, 0);
    if (!cubeBM) {
    ErrorCode("CreateDIBSection");
    return false;
    }
    DeleteObject(SelectObject(cubeDC, cubeBM));



    Thanks, Any help on this would be greatly appreciated!
    Dave

  2. #2
    Join Date
    Nov 2007
    Posts
    613

    Re: Opengl; Write to Bitmap and alpha channel

    I'm unfamiliar with opengl, but from my experience using other graphic functions, I noticed that no graphic function will handle the alpha chanel if it's not specially designed to do so.

    For what you want to achieve, try to find opengl functions explicitely designed to deal with transparency.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured