Kamujin's picture

Font guidance requested

I am working on porting my GUI code to OpenTK.

I am doing the font parts now. I have been reviewing the OpenTK system for TextPrinting and I need some guidance.

It appears that OpenTK's Font system is designed to work in immediate mode. My GUI uses Framebuffers, VBO's, and GLSL. It seems that the basic design of the TextPrinter is to convert a string into a series of texture mapped vertexes. Since, I am already managing the matrices for the other GUI elements, would I be painting myself into a corner to limit my use of TextPrinter to producing the texture mapped vertexes and do the drawing myself?

Thanks in advance.


Comments

Comment viewing options

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

The TextPrinter actually uses display lists for "cached" text (i.e. text drawn through a TextHandle) and immediate mode for uncached text. A VBO implementation has also been stubbed (but not yet implemented) - once that is ready, OpenTK will choose the best implementation automatically, i.e. VBOs if the hardware supports them, display lists otherwise.

What TextPrinter.Begin/End do is set up the correct state for text printing (enable blending, texturing and prepare an orthographic projection where for pixel-perfect rendering).

If I understand correctly, you wish OpenTK to perform text layout, load glyphs etc, and then pass this data to you for the actual rendering? There is a clean solution to this: implement an ITextPrinterImplementation, and pass that to the TextPrinter constructor. ITextPrinterImplementation has a couple of functions which receive a vertex array, and index array, plus the texture to bind.

It might be altered slightly in the future, because a single texture might not be enough, but I think this covers what you need to do? Check the latest code from SVN to try this.

Edit: If you actually code a VBO implementation, it would be great if you donated the code, so that other could benefit too! :-)

Edit 2: Sorry, I made a little mistake: the ITextPrinterImplementation does not take the texture for the font - this is handled internally by OpenTK.

Kamujin's picture

Thanks, I will look at the head version more closely.

I am currently porting a GUI system to OpenTK. I plan to make it available as example with no restrictions on copy or modification. Its not general purpose enough for every use, but it should be a useful starting point. The XNA and MDX versions of this GUI can be seen in the screen shots section of www.robotechmmo.com.

FWIW, My GUI system uses Framebuffers to store JIT-rendered versions of each child window. The framebuffer textures are only only redrawn in response to relevant events. The result is that most frames do nothing more the draw 1 textured quad per child window.