PDA

View Full Version : Texture trouble



Fastjack
01-16-2011, 07:00 AM
I'm trying to texture a rectangle, easy enough. But the problem is: there's transparency in the image, and black, and other colours. What's black also becomes transparent.
I use:

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
glEnable(GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexParameteri(textureTarget, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(textureTarget, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(textureTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glEnable(textureTarget);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(0, h);
glTexCoord2f(0, im.imgh); glVertex2f(0, 0);
glTexCoord2f(im.imgw, im.imgh); glVertex2f(w, 0);
glTexCoord2f(im.imgw, 0); glVertex2f(w, h);
glEnd();
glDisable(textureTarget);
glDisable(GL_BLEND);

Thanks for helping out.

mhagain
01-16-2011, 07:16 AM
That's happening because it's what you've told OpenGL to do, specifically in these lines:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
glEnable(GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

ZbuffeR
01-16-2011, 08:11 AM
Fastjack, can you explain what results you want ?

Fastjack
01-19-2011, 05:22 AM
I want the image completely displayed, except the parts that are transparent. Black should be displayed as black, transparent should be transparent, other colours should be other colours. I'm not sure what the right settings are for this effect.

ZbuffeR
01-19-2011, 12:02 PM
Then you need glBlendFunc(SRC_ALPHA, ONE_MINUS_SRC_ALPHA)

or GL_ONE, ONE_MINUS_SRC_ALPHA if your textures have premultiplied alpha.

Fastjack
01-20-2011, 03:11 PM
neither work, first turns transparent black, second turns black transparent

ZbuffeR
01-20-2011, 03:17 PM
Sorry for you then, because it means you are doing something else wrong.
Are you certain you draw the translucent part last ? Otherwise the depth buffer can get in the way.
Are you certain that alpha is 0 for transparent texels, and 255 for fully visible texels ?

Fastjack
01-21-2011, 10:25 AM
I am drawing the translucent part last.
To my astounishment the alpha is not 0, but very low (0x01) for transparent texels, 255 for fully visible texels.

I don't know what to do...

ZbuffeR
01-21-2011, 11:27 AM
Reduce your code to the smaller compilable Glut program still showing your problem, and post it here.