
How to render text on the screen
Posted Tuesday, 9 February, 2010 - 23:32 by chandragon inHi
I feel a bit of shame asking such a basic thing, but how do I render text on the screen ?
I searched for classes that could do that and found on internet that many people use a "TextPrinter" instance, but I don't find that class in OpenTK.Graphics.
I read in a post of this forum that it would be in "OpenTK.Compatibility", but I don't have it, has it been removed from the newer versions of OpenTK ? is there any substitute for the TextPrinter ?
Thanks for the answers !


Comments
Re: How to render text on the screen
Hello,
Here is a modified version of Chandragon's code, with the projection working. Hope this can help ppl landing on that thread.
Just create and instance of MyTextWriter and call Update/AddText whenever the text change. Call Draw in the drawing loop.
Re: How to render text on the screen
Thanks for the book page, this is a question that gets asked a lot. I will add the code to the sample browser.
Re: How to render text on the screen
Hi fictiveLaark,
I managed to use your code, but the text background is always black. Can you show me where I can change that? THanks
Re: How to render text on the screen
Hope you already did the obvious and searched the code for Color.Black.
Re: How to render text on the screen
Thanks for posting the code - this works pretty well, except I found I had to fall back to
TextRenderingHint.SingleBitPerPixelGridFit(no AA) or the text looked really awful when overlaid on background images.Has anyone tried support for BitmapFonts in OpenTK, e.g. http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13
Re: How to render text on the screen
@Fiddler:
Why this excellent font library and routines isnt any more in core of otk? I liked these a lot, my bitmap font rendering system sucks
when comparing to them, and when I tried some dynamic texts on that one example, it does not work the way I needed (was calculating
wrong bboxes or so, dont remember but havent tested it so much, maybe I write wrong my code already).
Re: How to render text on the screen
Hi David,
Thanx for the code.
This works perfectly fine on 32 bit machine but when I compile on 64 bit machine, only white screen is displayed. Am I missing something??