Sign in to follow this  
irreversible

OpenGL GLUT to WinAPI - alpha bitplane problem?

Recommended Posts

irreversible    2860
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]

Share this post


Link to post
Share on other sites
irreversible    2860
Calling glGetIntegerv() for GL_STENCIL_BITS returns 8 regardless of the number of bits defined in the pixel format descriptor, so I suppose the buffer is always initialized to 8 bits (at least on my GF2).

What's more iteresting, is that calling glGetIntegerv() for GL_ALPHA_BITS in the GLUT implementation returns 8. However, setting the alpha buffer 8 bits (similarly to the stencil buffer) in the WinAPI version causes no projected texture to be drawn at all. There are also some other discrepancies if the alpha buffer is enabled, but those fall beyond the scope of my question in this case.

The behaviors simply do not match, so I guess there's something more that I'm missing...

Share this post


Link to post
Share on other sites
zedzeek    528
all available hardware i know supports only 8 bit stencil (perhaps one of the professional cards has support for greater)
why do u need more than 8bit?

Share this post


Link to post
Share on other sites
irreversible    2860
LilBudyWizer - yes. I did not alter the render code, though. At least not consciously (that is, unless GLUT does something behind the scenes, everything should be the same).

zedzeek - I don't need more than 8 bits. I just wanted to express that setting either the alpha or stencil bits to 1 (or any other number) in the PFD automatically uses 8 bits for the respective buffer, that's all.

Share this post


Link to post
Share on other sites
LilBudyWizer    491
I guess the second question is do you have an alpha buffer? Overall I think the starting point is verifying the buffers are there and working as intended. If they are there and working as intended then there really isn't much room for you to have done something wrong in the setup.

Share this post


Link to post
Share on other sites
irreversible    2860
Incidentally - I was browsing around in docs on PIXELFORMATDESCRIPTOR and - I don't know how I missed this before, but:

cAlphaBits
Specifies the number of alpha bitplanes in each RGBA color buffer. Alpha bitplanes are not supported.
cAlphaShift
Specifies the shift count for alpha bitplanes in each RGBA color buffer. Alpha bitplanes are not supported.

This is really really confusing because GLUT_ALPHA says:

GLUT_ALPHA
Bit mask to request a window with an alpha component to the color buffer(s).



It is stated that GLUT will not initialize the alpha channel properly unless GLUT_ALPHA is specified, even though GLUT_RGBA may be specified (looking up GLUT_RGBA in glut.h, we'll find that it's defined as:

#define GLUT_RGBA GLUT_RGB)

This makes no sense, simply because PIXELFORMATDESCRIPTOR doesn't seem to provide a means to initialize the color buffer without an alpha component anyway (the only eligible format choice for OpenGL is PFD_TYPE_RGBA, which should already include the four channels). Does GLUT somehow implement an additional alpha channel internally if GLUT_ALPHA is specified? If so then how exactly.


Furthermore - calling:

glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH|GLUT_RGBA|GLUT_ALPHA|GLUT_STENCIL);
glGetIntegerv(GL_STENCIL_BITS, &stencil);
glGetIntegerv(GL_ALPHA_BITS, & alpha);

returns stecil and alpha both as 8 bits.

Failing to specify the alpha bitplane in the PIXELFORMATDESCRIPTOR in a Windows-specific example will return alpha as 0 (however, it will be 8 if the alpha bitplane is specified). Again, this makes little sense if you think about it for a moment.

Has no one really had a problem similar to this?

Share this post


Link to post
Share on other sites
zedzeek    528
GLUT_ALPHA is used for creating a window with destination alpha ie u wanna store the alpha info in the window
eg it lets u do blending like GL_DST_ALPHA GL_ONE_MINUS_DST_ALPHA

without it u can still use textures etc with alpha channels + blending like SRC_ALPHA (source)

wiht 98% of things u dont need destination alpha

Share this post


Link to post
Share on other sites
irreversible    2860
Resolved. It was a semicolon. I'd like to kick myself right now, but I won't because experience has shown me that life's like that most of the time anyway. I'd like to thank everyone who replied in this thread. The both of you, that is :).

PS - OpenGL specs on PIXELFORMATDESCRIPTOR apply to the generic GDI implementation, not the generic hardware-accelerated case. That is, alpha bitplanes aren't supported in GDI only - something that the docs fail to mention.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
    • By C0dR
      I would like to introduce the first version of my physically based camera rendering library, written in C++, called PhysiCam.
      Physicam is an open source OpenGL C++ library, which provides physically based camera rendering and parameters. It is based on OpenGL and designed to be used as either static library or dynamic library and can be integrated in existing applications.
       
      The following features are implemented:
      Physically based sensor and focal length calculation Autoexposure Manual exposure Lense distortion Bloom (influenced by ISO, Shutter Speed, Sensor type etc.) Bokeh (influenced by Aperture, Sensor type and focal length) Tonemapping  
      You can find the repository at https://github.com/0x2A/physicam
       
      I would be happy about feedback, suggestions or contributions.

    • By altay
      Hi folks,
      Imagine we have 8 different light sources in our scene and want dynamic shadow map for each of them. The question is how do we generate shadow maps? Do we render the scene for each to get the depth data? If so, how about performance? Do we deal with the performance issues just by applying general methods (e.g. frustum culling)?
      Thanks,
       
  • Popular Now