When I try to display texture on object it works but only with GL_BLEND disabled. When I enable blending:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
The texture is just not visible anymore. Black screen.
I have really no idea whats going on. Its same for JPG and for PNG with alpha channel.
EDIT (more details):
Well, its hard to paste the code (objects, objects eveywhere and huge) but it goes something like this:
//initialization – i commented everything else
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//preparing texture
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
int Mode = GL_BGR;
int nOfColors = image->format->BytesPerPixel;
if (nOfColors == 4) {
if (image->format->Rmask == 0x000000ff)
Mode = GL_RGBA;
else
Mode = GL_BGRA;
} else if (nOfColors == 3) {
if (image->format->Rmask == 0x000000ff)
Mode = GL_RGB;
else
Mode = GL_BGR;
}
// glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, image->w, image->h, 0, Mode, GL_UNSIGNED_BYTE, image->pixels);
glDisable(GL_TEXTURE_2D);
//drawing
glColor4f(1.0f,1.0f,1.0f,1.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, _i );
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(x, y);
glTexCoord2f(1, 0);
glVertex2f(x + width, y);
glTexCoord2f(1, 1);
glVertex2f(x + width, y + height);
glTexCoord2f(0, 1);
glVertex2f(x, y + height);
glEnd();
glBindTexture( GL_TEXTURE_2D, NULL );
glDisable(GL_TEXTURE_2D);
EDIT2
“black screen” may be little confusing – i meant that nothing is displayed (my background is black but it doesnt matter) – if i turn blending off i get nice texture on screen – with blending on nothing but background color
So it finally started to work after i changed my image loading library to DevIL. Previous had problems with alpha channel it seems.
Thanks all for your help