I decided to move my Android project to C++, and I have a problem. In the Java code I was loading my texture without an alpha value and the black color was actually my transparent color, but now I can’t do this. Black color is just black, not transparent.
I am loading the texture as this:
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*) image_data);
The internal format
GL_RGBhas only three components. It has no alpha. Therefore, if you attempt to access the alpha and do something with the non-existent alpha, OpenGL will fill it in for you. With 1.0, which is probably not what you wanted.If you want alpha, you need to provide alpha. OpenGL will not magic it into existence for you, nor will it assume that black means “transparent.”
Alternatively, you didn’t enable blending or alpha testing.