FTGL texture fonts only display black boxes when using multiple canvases

I use texture fonts in FTGL to render fonts on several canvases as labels for an axis, etc. My first plot goes well. However, all subsequent canvases make my texture fonts just black squares. I also noticed that some numbers are not displayed on the canvas, which is actually displayed. Center Time should display 8.3956, but instead displays the following.

enter image description here

Font selection 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 tried several things, such as clearing bits of color and depth, 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) to one of my routines that returns the width of the text, everything displays correctly (albeit slowly). From looking at the source code of FTGL, it doesn't seem that FaceSize () will manipulate openGL parameters other than calling glDeleteTexture (), so I'm a little confused why this works.

+4
source share
4 answers

It seems that alpha blending is turned off when you draw your next plots. Make sure you turn it on before making texts:

 glEnable(GL_BLEND); 
+1
source

This can happen if:

  • Thread of opengl render and thread ftgl :: Render do not match.
  • Enter full screen mode (you need to reset and reload all textures).
  • Incorrect Z value (order). First create a font, then an image or the first image, then select a font.
  • glDeleteTexture () can do this.
0
source

I have a similar problem and I solved it by adding the following:

 _font->FaceSize(fontsize); 

when updating text for rendering.

This function call removes the old textures, and the new text will display perfectly.

0
source

IIRC, OpenGL textures are created in context, and each window has a separate context. Since FTGL does not use the concept of shared contexts (I read a way there somewhere), the easiest way is to instantiate a new FTTextureFont for each window - and load each FaceSize after setting each of the windows (by calling glutSetWindow (id) on Freeglut, eg). This will immediately load the textures for all windows / contexts.

The only problem with FTTextureFont is that every time you change FaceSize, it reloads all glyphs using FreeType and creates the texture again. It is very slow. Someone has to fix it at some point. I am working on this issue by creating one FTTextureFont PER PER window size that I need to use in my application.

0
source

All Articles