juliuswang's picture

Text Size Issue?

Hi Guys,

I am working on a multi Window GL Environment currently and I have some issue with the TextPrinter function.
The situations is, I have a function to draw different size of Text to the Screen, as :

public enum FontSize
{
Small = 0,
Mediam = 1,
Large = 2,
Larger = 3,
Huge = 4
}

// Used to cache the strings we want to print.
private static TextureFont[] fonts = new TextureFont[]
{
new TextureFont(new Font(FontFamily.GenericSerif, 8.0f)),
new TextureFont(new Font(FontFamily.GenericSerif, 16.0f)),
new TextureFont(new Font(FontFamily.GenericSerif, 24.0f)),
new TextureFont(new Font(FontFamily.GenericSerif, 48.0f)),
new TextureFont(new Font(FontFamily.GenericSerif, 128.0f)),

};

private static TextHandle textHandle;
private static TextPrinter textPrinter;

///
/// Print Text to the Screen using Absolute Positon Value
/// NOTE: The Font Context only be created once, so IF close the intial window
/// the FONT will be missing. THIS is an *issue* in OPENTK 0.91z
///
/// String to Screen
/// X
/// Y
public static void PrintTextAtAbsolutePosition(string outputString, float x, float y, FontSize fontSize)
{
textPrinter = new TextPrinter();
textPrinter.Prepare(outputString, fonts[(int)fontSize], out textHandle);
textPrinter.Begin();
GL.Translate(x, y, -1.0);
textPrinter.Draw(textHandle);
textPrinter.End();
}

It runs good under normal circumstance, however, it will pop

"There is not enough space to add this item. Consider calling the Clear() method."

Could anyone help me on this?

Thanks,
Julius


Comments

Comment viewing options

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

BTW:

It runs good if I use the largest fontsize at the first time, for example the 128.0f one.
If not, If I use other window that uses less than that, it will cause the issue if later I try to use this font size.

Thanks,

the Fiddler's picture

This occurs because the TextPrinter in 0.9.1 can only use a single glyph sheet for caching glyphs. The error you are observing means that the sheet has run out of space. Specifying a larger font size will create a larger sheet, which will delay the issue.

This issue has been fixed in the text branch.

juliuswang's picture

Fantastic. Thanks for the insightful and in time rescue!
I will try to use a larger font size or compile the new text branch.

Anyways, thanks so much man!!

the Fiddler's picture

As a workaround, you can load a single glyph of a 128.0f font (I'd suggest sth like "i" to avoid wasting space), then switch to normal rendering. This will cause the TextPrinter to use the largest possible texture size.

The text branch should be in a working state now, but it lacks just a bit of polish to make it ready for testing. Feel free to build and test it, but don't base your code around it just yet (a couple of parameters will change).

juliuswang's picture

I will try this, now. ;)
Thanks, sir!

I tried to build the text branch, using build net, it always return a error when compiling the Utilites.:P

juliuswang's picture

Neat. The workaround is fantastic!!
I am looking forward to the new build man!!! :)

Thanks!

(Under a strict paper deadline now...your help is greatly appreciated!)

the Fiddler's picture

Strange, I'm not getting any errors here. Try checking out again, the latest revision is 1524.

If the error persists, can you please copy the text here? Thanks!

juliuswang's picture

Build net:
error: Traced with VS2008
OpenTK Build script has encountered a problem and needs to close. No process is associated with this object.

However, I could use Build VS
and using VS2008 to build the new Version.

Thanks