Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL - How Transparency works?

Tags:

opengl

Do i need Alpha channels for transparency to work in OpenGL? can i use glBlendFunc or anything else to make somehow the Black or White color transparent/not visible? if yes, how to do it?

like image 711
Tenev Avatar asked Oct 15 '22 02:10

Tenev


2 Answers

No, you don't need an alpha channel in your textures. Call discard in your fragment shader for all fragments that match your transparency rule.

like image 133
Malte Clasen Avatar answered Oct 23 '22 08:10

Malte Clasen


Yes, you need alpha channels to use transparency. You can emulate the behaviour of color keying using shaders, or processing the image and replacing the color key with pixels with alpha = 0.0.

Notice that GPUs always allocate RGBA textures, even if you want a RGB texture. The alpha channel is still present in hardware.

like image 25
Dr. Snoopy Avatar answered Oct 23 '22 08:10

Dr. Snoopy