Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw Transparent Polygon in OpenGL-ES 2.0?

I want to draw a semi transparent(say , alpha = 0.5) polygon in openGL-es 2.0 . How to do that?. Few things i tried. 1.I made gl_Fragcolor.w= 0.5 in fragment shader. 2.Disabled Depth related things.

I don know how to enable blending in openGL-es 2.0. I read it somewhere it is implemented automatically. is it so?. Any small help is appreciated.

like image 933
Vignesh Avatar asked Dec 27 '22 15:12

Vignesh


1 Answers

You have to enable alpha blending. For a faq on how to do that: https://www.khronos.org/opengl/wiki/Transparency_Sorting .

To enable the effect you want:

glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Note that enabling alpha blending will hurt performance somewhat - so only do it on the triangles that must have alpha blending enabled.

like image 119
Arne Bergene Fossaa Avatar answered Jan 03 '23 15:01

Arne Bergene Fossaa