I’ve been trying for the past day or so to get alpha-blending working
with textures. The situation is as follows:
I have a main texture that is updated and sent to the SDL window each
frame. I’d like to use textured fonts, and as such, I’ve created a
font texture holding 256 glyphs. So when I draw fonts, I use
glTexSubImage2D to cut out the appropriate font, and draw it over the
texture shown onscreen.
My problem is with alpha-blending. I want the current glyph (8x8
pixels) to be drawn, but only the parts that make up the foreground of
the glyph. So I assumed that I’d set the foreground color to
0x808080FF (indicated a light grey with full opacity) and the
background to 0x0 (indicating full transparency).
It doesn’t seem to be working out. The following is part of the code:
glTexCoord2f(0.0, 0.0); glVertex2i(xorig, yorig );
glTexCoord2f(1.0, 0.0); glVertex2i(xorig+8, yorig );
glTexCoord2f(0.0, 1.0); glVertex2i(xorig+8, yorig+8);
glTexCoord2f(1.0, 1.0); glVertex2i(xorig, yorig+8);
When I do this, it never seems to use the colors in the glyph texture,
but uses some other color. It seems that glEnable(GL_BLEND) turns on
alpha-blending for the whole texture, but it doesn’t use the alpha
setting of each pixel in the texture.
I’m pretty sure this has something to do with glBlendFunc(), but I’m not
having much success understanding that either.
Any help is greatly appreciated, because I’ve lost enough hair over