PDA

View Full Version : Texture mapped text woes...


spaceb
2005.04.08, 06:47 PM
Hi - I'm having some trouble getting texture mapped text to draw on a background without having the rectangle that I'm drawing it on be shown (in OpenGL). Here's the test code:

static void _DrawScreen(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);

glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ZERO);

glColor3f(0, 0, 1);
glBegin(GL_QUADS);
glVertex2f(10, 10);
glVertex2f(10, 10 + _Info.Height);
glVertex2f(10 + _Info.Width, 10 + _Info.Height);
glVertex2f(10 + _Info.Width, 10);
glEnd();

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, _TexID);

glColor4f(0, 1, 0, 1);
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex2f(10, 10);
glTexCoord2f(0, 0);
glVertex2f(10, 10 + _Info.Height);
glTexCoord2f(1, 0);
glVertex2f(10 + _Info.Width, 10 + _Info.Height);
glTexCoord2f(1, 1);
glVertex2f(10 + _Info.Width, 10);
glEnd();

// glPrint(10, 10, "test");
}

I know that the alpha values in the texture are right, because the white background in the png file isn't being drawn (green is being used).
I basically want the rectangle behind the text to be transparent anywhere that the alpha value in the texture is 0. If I set the alpha to 0 in glColor4f, nothing at all is drawn (regardless of the alpha in the texture). What I'm saying is that I simply want the alpha value in the texture to always override the alpha value in the glColor4f(). Does anyone know how I can do this? Thanks in advance!

ThemsAllTook
2005.04.09, 02:43 AM
I don't think you want GL_ZERO in your blend func. Try setting it to GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA.

- Alex Diener

spaceb
2005.04.10, 01:32 AM
That did it (along with taking out the glTexEnvf() call). I didn't realize that GL_BLEND and the GL_DECAL modes shouldn't be used at the same time. This also has the added effect of changing any white parts of the text texture to whatever the current OGL color is. Very neat!