Jump to content
  • Advertisement
Sign in to follow this  
Alex Dem

OpenGL Blending with two buffers

This topic is 1005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In a previous topic i have asked a question about not working blend in OpenGL.
It turns out that even though i have called glEnable(GL_BLEND) and glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) the blending does not change colors in any way despite that i have alpha values for translucent objects.

So what is coming to my thought is that the problem should be caused by using two different buffers for rendering .
What i am doing is the following:
1. On initializing of OpenGL i set draw buffer to front with glDrawBuffer( GL_FRONT )
2. Before rendering  objects i set draw buffer to back with glDrawBuffer( GL_BACK )

3. When drawing objects is complete i swap buffers to show the new scene, meanwhile the buffers have been cleared with GL_COLOR_BUFFER_BIT and GL_DEPTH_BUFFER_BIT.

4. Which comes to the conclusion that blending is performed on an empty or wrong buffer.

The question is:
How do i perform blending while using front and back buffers, when clearing buffers should be done and which openGl unctions should I use?

Share this post

Link to post
Share on other sites

I've just read your other thread, I would advise that whatever you are trying to do now is definitely the wrong way to go about this. You mention you are new to OpenGL so be weary of trying to strange things like this. This is pretty much just reiterating what others have said in your previous thread, to use transparency correctly you need to:


Enable depth testing, enable depth writing (these are two different things, this might be catching you out somewhere).

Draw all non-transparent objects.

Leave depth testing enabled, disable depth writing

Set your blending stuff up (enable blending, blending func etc)

Sort all your transparent objects by depth from camera

Render all your transparent objects (furthest objects first)


I'm not sure what the effect will be if you have triangles clipping through other triangles as obviously sorting them doesn't necessarily make much sense (part of them is closer, part is further).


Alpha blending is perfectly possibly and you shouldn't  have to do what you are attempting to do to 'work around' it. Try to solve the initial problem correctly instead.


It might also help to see your shader code.

Edited by Nanoha

Share this post

Link to post
Share on other sites

Don't draw to the front buffer. It causes artifacts.


The front buffer is conceptually the one you're showing in the monitor. So any tiny change in there will cause artifacts. Don't touch it. If you need more buffers, learn how to use framebuffer objects.

Share this post

Link to post
Share on other sites

Thank you all for the good advice. It will be in good use. However I found what was causing the problem with alpha blend. For the sake of other people that may face the same problem here what it was - I have called 
glEnable( GL_COLOR_LOGIC_OP );
glLogicOp( GL_COPY );

which have removed the colors that should have blended. When i removed these two lines - the colors began to blend properly.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!