foboi1122 foboi1122 - 1 month ago 18
C++ Question

FTGL texture fonts display only black boxes when using multiple canvases

I am using texture fonts in FTGL to render fonts into multiple canvases as labels for axis and such. My first plot comes out fine. However all subsequent canvases render my texture fonts as simply black squares. I've also noticed that some numbers do not display on the canvas which actually renders. The "Center Time" should display 8.3956 but displays the following instead.

enter image description here

The font rendering is as follows:

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
PushGLMatrices();
GrSetPixelProjection();
glTranslatef(pixelX, pixelY, 0.0);
glRotatef(ang, 0.0, 0.0, 1.0);
savedFont->Render(label);
PopGLMatrices();


where

void PushGLMatrices()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
}

void PopGLMatrices()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}


I've tried a few things such as clearning color and depth bits, and glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); but that didn't seem to help. For some reason, if I add FTTextureFont::FaceSize(int) into one of my routines which returns the width of the text, everything displays correctly (albeit slowly). From looking at the FTGL source code, it doesn't seem like FaceSize() would manipulate the openGL parameters except for a glDeleteTexture() call, so I'm a bit confused why this works.

Answer

It seems alpha blending is disabled when you draw your subsequent plots. Make sure you have enabled it, before you render texts:

glEnable(GL_BLEND);