First off, I consider myself pretty adept with both OpenGL as well as WinAPI, so I've hopefully managed to exclude any dead obvious explanations (then again, you'll never know...).
I'm trying to convert a GLUT-based sample application to a straightforward WinAPI-based application. I've never really taken an interest in GLUT and it's always seemed as something overly straightforward to me. However, in this case something (probably really simple) is happening that is genuinely puzzling me. I've narrowed the problem down to what is most likely the window creation code. The sample application uses the stencil buffer to segment a projective texture, so the bulk of the attention should rightfully be on the stencil buffer. However, GLUT requires an additional alpha bit (GLUT_ALPHA) to be specified for the window to work in RGBA mode. Specs say: "Bit mask to request a window with an alpha component to the color buffer(s)."
This makes little sense to me since the window is (in Windows) initialized through CreateWindow() and the pixel format descriptor should already include the RGBA mode, which should ensure the presence of an alpha channel. Just to be sure I wasn't misunderstanding, I tried setting the alpha buffer in the pixel format descriptor to 1, which only seemed to make matters worse (no projection drawn at all).
The effect of the demo (sadly I am not in a position to post screenshots) is like this:
I
The original demo using GLUT draws the projected texture properly with appropriate bits cut out using a simple stencil test. The initialization code looks like this:
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH|GLUT_RGB|GLUT_ALPHA|GLUT_STENCIL);
II
My adoption of that code draws the projected texture properly, but does not render the occluded areas properly (no occluding occurs through the stencil buffer) at all. That is, the projection blasts through everything as if no stencil tests were ever performed. The pixel format initialization code looks like this:
PIXELFORMATDESCRIPTOR pfd= {
sizeof(PIXELFORMATDESCRIPTOR), 1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA, //4-component mode
24, //color depth
0, 0, 0, 0, 0, 0,
0, //no alpha buffer
0, 0, 0, 0, 0, 0,
24, //depth buffer
1, //stencil buffer
0,PFD_MAIN_PLANE, 0, 0, 0, 0 };
I'm fairly certain the problem is not in the stencil buffer, however, because I reverted to trying the code out without any alterations at all other than switching the GLUT windowing code to my own. I could probably explain the problem more closely, although without the ability to post screenshots, I'm feeling a little helpless without any suggestive questions. As I mentioned, the problem is most likely in the GLUT_ALPHA flag - can someone at least explain what that does, because even Google doesn't seem to know what the heck it really is.
Thank you for your time
[Edited by - irreversible on November 12, 2005 7:16:05 AM]