
What about FONTS??
Posted Saturday, 15 September, 2007 - 23:39 by Anonymous inI've search a lot for a little example including fonts and it does not exist in the whole Internet. Is that simply not possible? I really need put text in my window and now I dont know if OpentTK could offer any support for that. Can anybody give some help about this problem?


Comments
The frustration with using
The frustration with using fonts in OpenGL! I'm trying to find a way to add font rendering in OpenTK, but this is not a simple issue, and I don't believe I'll find a solution in time for the 1.0 release. Ideally OpenTK would support both truetype fonts and bitmap based fonts, but this is still a long way off.
The best advice I can give you is to cook up a texture-based font renderer: load a bitmap (png) with all needed glyphs aligned in a grid, then play with the texture coordinates to render glyphs on quads. I've used this successfully in the past, and it works well enough for simple games/applications.
I've come up with something
I've come up with something that currently works for me, mostly, but is definitely sub-optimal. It works on Windows (only), and uses WGL to build a display lists of polygons of fonts. I've attached the code for my font class below. There are several things tho: 1. generating this list is slow (~.6-1.0 seconds on a core2duo). to get around this, I preload the fonts I need at startup, and store them in a list. Then I have a method I call when I want to draw a particular font, it checks against the pre-rendered ones and uses one if it matches, otherwise it creates it, adds it to the list and then uses it. 2. they look great real big, or if you can enable a multisampling extension (or presumably any type of scene antialiasing, I have yet to look into this), but otherwise look kind of crappy at regular/small font sizes. I plan soon on checking whether multisamplings turned on, and if it isn't creating antialiased bitmaps instead. Hopefully at least. Hope this helps a little.
yours,
Bobby
Thanks for the code, it
Thanks for the code, it definitely helps! Strange thing, I was thinking about something like this just a few hours ago. I'll port this to GLX and add it to OpenTK - it's not Freetype, but it's better than nothing.
To my knowledge
To my knowledge glCallLists() itself will call glCallList() a couple of times, which is rather expensive if you are drawing alot of text. If your application is something like a chatroom (where you have a large amount of static text and only the input line changing), consider the possibility of compiling display lists at runtime for every _line_ once (glDrawArrays) instead of every character. This also has the benefit that addding coloring to characters/words/etc. is very cheap (e.g. you can check for certain unicode chars and interpret them as colors when building the vertex array). Not sure how much more expensive GL_COMPILE_AND_EXECUTE is compared to directly drawing it though, but after compilation the display list should execute much faster than passing every single character, or drawing the vertex array without VBOs. I don't have benchmarks to prove anything and results might vary depending on the driver. Just my 2 cents.