OpenGL Alpha Blending

I found 5349574673 pages about alpha blending and I still canโ€™t get the desired result. I am trying to correctly display gif / png files (with transparency / transparency) using opengl.

Here is my initialization bit:

glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); //I've seen this on most tutorials glDisable(GL_DEPTH_TEST); //it a 2D game //...loading matrices and so on 

I am SURE that images have transparency and load correctly.
glBlendFunc (GL_ONE, GL_ONE); works, but I canโ€™t say if it does anything on the alpha channel, since it will look like black => mixing works
glColor4f (1f, 1f, 1f, 0.3f); works fine, i can draw transparent things

PS I am using this example http://lwjgl.org/wiki/index.php?title=Space_Invaders_Example_Game for training

EDIT I used other textures encoded using GIMP and other texture loaders, and now it works great.

+6
source share
1 answer

Your mix setting is correct. However, for blending to work, the texture must contain an alpha channel, correctly estimated, of course. And then the alpha channel data must be saved by the image loading process. Can we see the image upload code and texture generation code, please?

+5
source

Source: https://habr.com/ru/post/900010/


All Articles