Domanda

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.

È stato utile?

Soluzione

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);

Altri suggerimenti

It could happen when:

  1. Thread of opengl render and thread of ftgl::Render are not same.
  2. Enter in fullscreen mode(need to reset and reload all textures).
  3. Not correct Z possition(order). First render font then image or first image then font.
  4. glDeleteTexture() can do it.

I have a similar problem and I solved it by adding this:

_font->FaceSize(fontsize);

when update text to render.

This function call delete old textures and new text will show fine.

IIRC, OpenGL textures are created within a context, and each window has a separate context. Since FTGL doesn't use the concept of shared contexts (I read somewhere there's a way to do this), the easiest way is to instantiate a new FTTextureFont for every window - and load each FaceSize after setting each one of the windows (by calling glutSetWindow(id) on Freeglut, for example). This will load the textures for all the windows/contexts at once.

The only problem with FTTextureFont is that everytime you change the FaceSize it will reload all the glyphs using FreeType and generate the texture again. This is extremely slow. Someone should fix that at some point. I work around that problem by creating one FTTextureFont PER window PER size that I need to use in my application.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top