JurgenRoeland's picture

QuickFont load font turns the screen blank.

Hi, I'm quite new to OpenGL.

I have written an application that makes a geographic mapping in c# using openTK opengl.
It works quite well and now it became necessary to add text on my screen for some labels.

I used quickfont library. added it as subproject and reference, added the font folder to my project.
what happens now is that whenever I try to load a font, all my screen goes black. My other drawings dissapear.
I'm not even using a print method to put anything on my screen.
the font seems to load ok, as I get a pointer and the data seems to be filled in.
I tried with loading various different fonts and always get the same result, my screen goes black. removing the font declaration and all comes back

this is what I add

controlsText = new QFont("Fonts/HappySans.ttf", 16);

controlsText being declared earlier in the members as QFont.

Does somebody have an idea in what direction I have to search why the drawing goes blank ?

pictures show before and after

thanks in advance,

J. Roeland

Inline Images
before adding create font
after

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mOfl's picture

I have never used QFont myself as it unfortunately (still) relies on the immediate mode, but there have been some threads in the past about problems with it. The root of these problems was that some states were not reset (correctly) by QFont. Try calling GL.Disable(EnableCap.Texture2D); and/or GL.Disable(EnableCap.Blend);, maybe this helps.

JurgenRoeland's picture

The GL.Disable(EnableCap.Blend)) does indeed allow to load the font and still see some image.

But, the image is very dark. I see the drawing, but it seems like someone switched of the light.

See the image below, compared to the first image in my original post.

The texture2D command did not make any changes to it.

Any idea why this blend makes the drawing go dark?

mOfl's picture

You did not add an image to your last post or at least I don't see it, so I can only guess what the result is. Do you know what blending means? Blending is a mechanism which allows several ways to blend in several images according to their colors and/or translucency (alpha) values through predefined blending functions. So blending a white map like yours with a completely black fullscreen quad would result in a black screen with alpha blending and a gray map with some color blending. It is a bit complicated to explain the blending functions without images, so I ask you to look up "blending openg" yourself to get a bit familiar with the blending functions. You always set them via GL.BlendFunc, which requires two parameters that tell OpenGL what values to blend from the first and second image. My guess is that the area containing the text of QFont extends over the whole screen and is black where there is no text. Instead of being translucent, the black background might be opaque, so the alpha blending does not work.

swax's picture

I had this same problem, just adding the line
...  = new QFont("Fonts/HappySans.ttf", 16);
in my code caused everything to get really dark.

I found that adding the line
GL.Disable(EnableCap.Texture2D);
to the end of the function
QuickFont.TexturePage.CreateTexture(BitmapData dataSource)
fixed my problem.

I'm new to OpenGL as well so I'm not sure if the fix is correct, but it makes sense that an enable call should be paired with a disable call to preserve the original state of the app.

JurgenRoeland's picture

indeed mOfl, I had no idea what blending did. thanks for the explanation.

However, the reply of swax above kind of solved the dissapearing drawing problem. Here is what I do actually and it also allows the loading of the font without the drawing to dissapear. I don't disable blending anymore with this.

public QFont controlsText;
public QFont mainText;
public BitmapData dataSource;
public QuickFont.TexturePage texturepage;
public void initializeFonts() {
try
{
OTKGL.GL.Disable(OTKGL.EnableCap.Texture2D);
dataSource = new BitmapData();
texturepage = new TexturePage(dataSource);
var builderConfig = new QFontBuilderConfiguration(true);
builderConfig.ShadowConfig.blurRadius = 1;
builderConfig.TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit; //best render hint for this font
mainText = new QFont("Fonts/times.ttf", 14, builderConfig);
controlsText = new QFont("Fonts/HappySans.ttf", 32, new QFontBuilderConfiguration(true));
texturepage.CreateTexture(dataSource);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}

The problem I'm faced with now is that my text gets drawn but removes again all the other drawings.

At first, I see a blink of my image being there and then the text seems to 'take over' and erases all the background.
All my text seems to be there but it is upside down. Rotating seems to rotate along the wrong axis (180 degrees mirrors my text)
I use this now to print
if (m_Parent.m_GeoDataContainer.switch_Names_on)
{
OTKGL.GL.PushMatrix();
// OTKGL.GL.Rotate(180, m_WorldPosPoint.getX(), m_WorldPosPoint.getY(), 4.0f);
OTKGL.GL.Translate(m_WorldPosPoint.getX(), m_WorldPosPoint.getY(), 4.0f);
FontManager.mainText.Print(m_Name, 100, QFontAlignment.Left);
OTKGL.GL.PopMatrix();
}

Another question. Is it possible to make the text being static in size (so irrelevant of the distance of the eyepoint). Now it sizes as I zoom as it is mapped as texture to the world coordinates.

picture with the print on:
jurgenroeland.brinkster.net/joomla/images/capture1.jpg

picture of the same area with the print off :
jurgenroeland.brinkster.net/joomla/images/capture2.jpg

Thanks

james_lohr's picture

Yes, I'm aware of this issue. I will use GL.PushAttrib() / GL.PopAttrib() in the next release to eliminate this issue. Personally in my own code I don't use them for the sake of performance; however, at the very least I'll enable them by default and allow on option to disable them if you want the tiny performance gain.

Until then, assume that any QFont method calls may not preserve color and blend mode.

>>But, the image is very dark.

The color is not preserved either, so try calling: GL.Color4(1.0f,1.0f,1.0f,1.0f);

>>All my text seems to be there but it is upside down.

You should be calling QFont.Begin(); and QFont.End(); when rendering text. However, note that this will set an orthogonal transformation with dimensions equal to that of the viewport. So, you will need to translate the text accordingly. This is all done in the same manner as the TextPrinter, so questions directed at QFont about the orthogonal transformation and how to transform coordinates from 3D into viewport coordinates so that text can be rendered relative to a point in 3D space will have identical answers/solutions .

swax's picture

Hey I put my fixes up on github so I can keep track of my changes from the original source. Could you move official development of this library to github?

https://github.com/swax/QuickFont

puklaus's picture

Is display lists implemented? I made some changes (it uses dlists now) to quickfont and could give a patch if someone interested. Even better if creating all characteris in vbo but I was lazy and didnt do that (actually dont know how to implement it "right" way).

puklaus's picture

and this to axiom3d plugin, I would be happy :)
(it uses otk already with opengl, but it uses direct3d too, so wont work right away, most simplest way)