I don't think I've got any syntax errors, just a problem with understanding how alpha is done on textured quads with OpenGL. (mesa 9.0 under centos 6.3, which is opengl 4.2 I think)
I've got a font face that has been uploaded with glTexImage (I've tried GL_ALPHA, GL_RED and currently GL_RGBA). I'm fairly certain the alpha channel is set on the letter and unset on the background, since I twiddled the pixels and set it manually).
So, just to clarify, the TexImage contains red 0xff0000 on the letter pixels, black 0x000000 on background pixels, and the alpha is set to 0xff on the red pixels, and 0x00 otherwise.
I did:
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);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE );
before
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
face->glyph->bitmap.width, face->glyph->bitmap.rows,
0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, new_buffer );
When showing the glyph with:
glBindTexture(GL_TEXTURE_2D, ascii_textures[100] );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
// Then draw the box
glBegin(GL_QUADS);
glTexCoord2i( 0, 0 );
glVertex2f( ... // bottom left
glTexCoord2i( 0, 1 );
glVertex2f( ... // top left
glTexCoord2i( 1, 1 );
glVertex2f( ... // top right
glTexCoord2i( 1, 0 );
glVertex2f( ... // bottom right
glEnd();
I get this (I'm drawing the red 'd' over the videos):
If I uncomment the glColor line, I get:
If I don't use the texture, I get a translucent dark box, so obviously blending is working.
It appears that OpenGL is pulling the alpha value from the glColor4f statement, but not from the texture.
Anyway to make it look at the texture and not the color?
What I'm really doing is trying to mask or clip the glyphs that I preloaded as textures, so other ways to go about this would be welcomed (though probably not glut fonts since I'll need complicated unicode glyphs at some point)