
TextureFont v0.1
Posted Sunday, 21 June, 2009 - 02:48 by objarniI finished a rough version of the TextureFont class. The WriteCharacter/WriteString got a little tidier aswell as more optimized. For example I moved out the "Begin/End"-calls from WriteCharacter to WriteString. WriteString is the only public API for the class, example code:
private void DrawText() { string text = string.Format("Hello! FPS={0:000.0}", fps); // Assume orthogonal 0,0,width,height projection matrix GL.Color3(Color.Khaki); GL.Translate(w / 2, h / 2, 0); // place text at center of view double scale = h * 0.05; // make it 5% of the height of the view GL.Scale(scale, scale, scale); GL.Rotate(rotation, 0, 0, 1); TextureFont texFont = new TextureFont(texture); texFont.WriteString(text); }
The TexUtil.cs file can be downloaded here, I'm releasing it under same license as OpenTK, if you are interesting in using this functionality.

- objarni's blog
- Login or register to post comments


Comments
Re: TextureFont v0.1
Serinus - you should also consider moving the CreateTextureFromFile-call to some kind of setup-logic of you application (Main/constructor/OnLoad or similar..)
Right now you are re-loading the .png file *every frame* = extremely slow :)
Make the 'int texture' variable an instance variable instead of a local variable in OnUpdateFrame.
Re: TextureFont v0.1
Thank you. It's faster then TextPrinter.
But I have a problem when I try to draw lines and write string : the lines didn't display!
Could you help me find out the problem?
Thanks!!!
Re: TextureFont v0.1
Try disabling textures before drawing the lines.
Re: TextureFont v0.1
It work very well, thank you so much!!!