Sunday, July 31, 2016

Rendering Gui Or Hud In A Separate Framebuffer

Rendering Gui Or Hud In A Separate Framebuffer

Hello, I have been trying to render the HUD for my game to a separate FrameBuffer so that I can apply my own shader effects to it that are separated from the 3D scene.

 

The problem is that I am having transparency issues. I use glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); with glClearColor(0.0f, 0.0f, 0.0f, 0.0f);, which creates a transparent black background for the HUD FrameBuffer before rendering the HUD.

 

Whenever I render a transparent HUD element to the FrameBuffer, the black gets mixed in with the original colors of the element, which is not what I want. It ends up making the HUD elements look darker than they are supposed to be when I mix the HUD FrameBuffer with the 3D Scene FrameBuffer.

 

I can change the color for glClearColor() and get different colored results, so I know that that is the root of the problem. I decided to use the blend function:

 

glBlendFuncSeparate(/*For color*/ GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
                                    /*For alpha*/ GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

 

which was requested by someone who had a similar issue. Unfortunately it isn't working for me. I am afraid that I might need to do something involving stencil buffers to get it to work, but I want to try to avoid that and find a simpler solution. Can anyone give me any pointers?

 

Also this is made with OpenGL 4.2 with c++ and compiled with MinGW.


No comments:

Post a Comment