Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to draw transparent polygon in openGL

Tags:

opengl

I need your help. I know there is alpha in openGL, and it's help me to draw polygon on transparent mode, but I do not know how to do that, what should enable to allow opengGL to draw that polygon.

and thanks for any help.

like image 767
Hitman Avatar asked Jun 26 '10 18:06

Hitman


2 Answers

It's simple:

glEnable(GL_BLEND); //Enable blending.
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Set blending function.

That's the basic, that blending function is the basic and should be fine for you, but there are others.

Then, you need to be sure that your window/framebuffer contains an alpha channel, and that the polygons you draw also contain alpha information.

like image 138
Dr. Snoopy Avatar answered Oct 31 '22 14:10

Dr. Snoopy


It is exactly as Matias says, but you should also remember that to get the "transparency" work as it is supposed, all the non-transparent primitives in the scene must be drawn first, and the transparent ones must be drawn in the correct order, from the back of Z-buffer towards the front.

The reason for this is that OpenGL doesn't really support transparency, it emulates it through alpha-blending, and so if a new object is drawn behind a "transparent" primitive after it has already been rendered, the new object will not be visible through it.

like image 20
Rafaello Avatar answered Oct 31 '22 13:10

Rafaello