Customizing Win32 OpenGL Window with GL_RGBA Color Buffer

I am trying to set up an OpenGL window with an alpha channel in its color buffer. Unfortunately my current setup creates a GL_RGB back and front buffer (as reported by gDEBugger, and as shown by my experiments).

I installed the window like this:

PIXELFORMATDESCRIPTOR pfd;
ZeroMemory(&pfd,sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24; //note by docs that alpha doesn't go here (though putting 32 changes nothing)
pfd.cDepthBits = 24;
pfd.iLayerType = PFD_MAIN_PLANE;

      

I have also tried more specifically:

PIXELFORMATDESCRIPTOR pfd = {
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA,
    24,
    8,0, 8,8, 8,16, 8,24, //A guess for lil endian; usually these are 0 (making them 0 doesn't help)
    0, 0,0,0,0,
    24, //depth
    8,  //stencil
    0,  //aux
    PFD_MAIN_PLANE,
    0,
    0, 0, 0
};

      

I understand that when I later call SelectPixelFormat, it returns a format with no alpha channel (although, why, I don't know).

I should clarify that when I say alpha buffer I mean just a simple alpha buffer for rendering purposes (each color has an alpha value from which chunks can be checked, etc.). I am not referring to a semi-transparent window or any other effect. [EDIT: No, I'm not interested in making the window transparent. I just want the alpha channel for the default framebuffer.]

[EDIT: This is part of the cross platform window I am writing to. My code is always portable. I am not using a library that provides this functionality as I need more control.]

+3


source to share


1 answer


There are two key points here:

  • You can do this with the default framebuffer. However, you need to request it correctly. The Windows default selection mechanism does not seem to weigh very heavily on RGBA. Your best bet is to list all the possible pixel mods and then select the one you want "manually". By doing this, I was also able to indicate that I needed a 24-bit depth buffer, an accumulation buffer, and an 8-bit stencil buffer.

  • The OpenGL context must be fully valid for alpha blending, depth testing, and any even remotely advanced methods to work. Curious that I was able to get the displayed triangles without a full OpenGL context, which led to my confusion! Maybe it was emulated in software? I figured it out when glewInit (let alone building multiple VBOs) failed. The key point is that the OpenGL context must be valid. In my case, I was not setting it up correctly.



This issue was in the context of my writing a currently lightweight cross-platform toolkit for windows. It currently supports Windows via Win32 APIs, from Linux to X11, and I've just started porting Mac OS to X11.

At the request of some in the comments, I hereby state my modest efforts that others can draw from this. Mac support isn't working yet, menus aren't implemented on Linux, and user input on Linux is only halfway there. As of 1/18/2013, this can be temporarily found here (people of the future, maybe I put new versions on my site (look for "Portcullis")).

+2


source







All Articles