Use only alpha channel texture in OpenGL?

Hey, I'm trying to make a constant color for the framebuffer and mix it using the alpha channel from the RGBA texture. I watched glBlendFunc and glBlendColor, but didn't seem to understand how to ignore the RGB values ​​from the texture. I think I will have to pull out the alpha values ​​myself and make a second texture using GL_ALPHA. Is there a better way to do this?

Thank!

+2
source share
2 answers

I use color coding. This is the code I use so that the transparent areas of the texture square are not selected:

glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);

glAlphaFunc(GL_GREATER, 0.5f);

glColor3ub(myColor[0], myColor[1], myColor[2]);

drawTexturedQuad();

, , , RGB , ( myColor), , ALPHA .

+1

glBlendFunc, GL_SRC_ALPHA GL_DST_ALPHA - ( ). .

OpenGL:

0

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


All Articles