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.
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.
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.
精彩评论