Simply, I am working on rendering text using the new OpenGL style, so putting everything within the shaders basically. What I do is I get a texture containing all of the glyphs from a bitmap containing all the glyphs like this:
glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, Z.shape[1], Z.shape[0], 0, GL_ALPHA, GL_UNSIGNED_BYTE, Z )
where Z is a numpy array containing the bitmap information.
Then when I render it, I pass the shader the position of the glyph I want to render within the texture so it only grabs that portion of the texture. So far so good.
As you can see, it is set up so that the glyphs should be able to blend with glColor so that one can set the color of the font before rendering. This doesn’t work. After doing some testing with explicitly setting the alpha within the shader, it appears that the only alpha value to have any effect at all is the value 0, which makes that pixel completely clear, as one would expect. All other values just leave the pixel looking exactly the same as it would with 1 alpha value (usually means a flat black color, but testing shows that every other color leaves it as that color).
So, the only thing I can assume is that it doesn’t know what it is supposed to blend the alpha channel with and so just blends it with… nothing I guess. I thought I set it up for that in the beginning of my code with this (Python by the way):
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )
glDisable(GL_LIGHTING)
glEnable( GL_DEPTH_TEST )
glEnable( GL_BLEND )
glEnable( GL_COLOR_MATERIAL )
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE )
glBlendEquation( GL_FUNC_ADD )
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
but experience is telling me otherwise.
Just for completeness’ sake, here are my vertex and fragment shaders:
//Vertex shader
#version 110
attribute vec4 position;
attribute vec2 relativeposition;
varying vec2 texcoord;
void main()
{
gl_Position = position;
texcoord = relativeposition;
}
//Fragment shader
#version 110
uniform sampler2D texture,textures;
varying vec2 texcoord;
void main()
{
gl_FragColor = texture2D(texture, texcoord);
}
So anyways, does anything jump out that I’m missing for doing this? Thanks.