I have a weird problem. I am using an alpha texture to render text in my scene.
I am trying to add inverse text to the system. Here is my vertex shader:
#version 450
layout (location = 0) out vec2 texpos;
layout (location = 1) in vec4 coord;
void main(void) {
gl_Position = vec4(coord.xy, 0.9, 1);
texpos = coord.zw;
}
I have modified my fragment shader to look like this:
#version 450
layout (location = 0) in vec2 texpos;
layout (location = 1) uniform sampler2D tex;
layout (location = 2) uniform vec4 color;
layout (location = 3) uniform int inverse;
void main(void) {
if( inverse == 1 )
{
gl_FragColor = vec4(0, 0, 0, texture2D(tex, texpos).a);
}
else
{
gl_FragColor = vec4(1, 1, 1, texture2D(tex, texpos).a) * color;
}
}
If I do nothing else, the text I flag as inverse is rendered as black. That’s cool.
My problem starts when I try to draw a light color quad under where the text will be rendered.
If I add the following code before the text render module is called, the text does not appear over the quad.
if( Inverse )
{
width = pixel_width( a, text );
glColor4fv( &outln_color.r );
glBegin( GL_QUADS );
glVertex3f( x-sx, y-sy, 0.000 );
glVertex3f( x+sx+width*sx, y-sy, 0.000 );
glVertex3f( x+sx+width*sx, y+sy+a.h*sy, 0.000 );
glVertex3f( x-sx, y+sy+a.h*sy, 0.000 );
glEnd();
glColor4fv( &Current_Color.r );
glBegin( GL_QUADS );
glVertex3f( x, y, 0.100 );
glVertex3f( x+width*sx, y, 0.100 );
glVertex3f( x+width*sx, y+a.h*sy, 0.100 );
glVertex3f( x, y+a.h*sy, 0.100 );
glEnd();
}
As you can see, the quad is well “below” where the text should be rendered. What am I doing wrong?