OpenGL text and other things. - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenGL text and other things. (/thread-2513.html)
OpenGL text and other things. - Talyn - Jul 21, 2008 09:43 PM
I have not been able to find any intuitive, useful or understandable implementations to draw text in OGL. Anyone have a simple solution to draw text to the screen in OpenGL?
Also, I have found some information on mouse events in SDL, but I haven't been able to figure out how to make the scene pan with a moved mouse, so that the mouse stays at the point the user clicks is moved around. Any ideas?
OpenGL text and other things. - kodex - Jul 21, 2008 09:56 PM
Text in OpenGL is a widely debated topic, see http://www.idevgames.com/forum/showthread.php?t=11231
When the user clicks take the coordinates of the click and add them to the coordinates of the previous center of the screen. Move all of your objects that distance in the opposite direction. This will give the appearance of the screen centering on the click.
OpenGL text and other things. - Talyn - Jul 21, 2008 10:02 PM
kodex Wrote:Text in OpenGL is a widely debated topic, see http://www.idevgames.com/forum/showthread.php?t=11231
Thanks! Now which of those would YOU recommend?
No, no. I mean being able to drag a scene around using the mouse. I suppose I could translate everything as long as the SDL_MOUSEMOVE event was active. Is that a reasonable approach?
OpenGL text and other things. - arekkusu - Jul 21, 2008 11:03 PM
Define "text" first.
Or like this?
Or maybe like this?
OpenGL text and other things. - AnotherJake - Jul 21, 2008 11:41 PM
Text in OGL can be a real bugger. You basically have one of three reasonable choices on the Mac (that I'm aware of):
1 - Monospaced pre-rendered fonts, with one letter per textured quad (or triangle strip)-- most popular, and really darn easy using display lists
2 - Apple's text rendering -- best looking and fairly easy (OSC has a super easy implementation for 10.4 and greater)
3 - Freetype's text rendering -- most flexible and cross-platform and looks great, but not real easy to figure out at first
Apple and Freetype methods typically render all of the text (or large text blocks) into a single texture, whereas the monospaced pre-rendered font technique typically uses one texture for each character and you draw the characters with display lists. There are several things to consider with all the different text approaches, and they all have advantages/disadvantages.
The most intuitive and practical approach to try first is the monospaced, pre-rendered font technique, using display lists. It isn't great, but it isn't bad at all for things like scores/high-scores and basic instructions. You can find tutorials for it all over the place. I think it's even mentioned in the Red Book.  Oh yeah, and you *can* hack in some basic kerning and other typesetting stuff too, but I'd say if you want to do that then you might as well use Apple's stuff or Freetype...
OpenGL text and other things. - JustinFic - Jul 21, 2008 11:53 PM
AnotherJake Wrote:1 - Monospaced pre-rendered fonts, with one letter per textured quad (or triangle strip)-- most popular, and really darn easy using display lists
For what it's worth, I've used this approach, and it's worked pretty good for me. Plus when you need to break out of the world of monospaced text, it's not a *huge* jump to start handling sizes of different glyphs, and it's something you don't have to worry about at all until you want to.
OpenGL text and other things. - Talyn - Jul 22, 2008 12:44 AM
AnotherJake Wrote:Text in OGL can be a real bugger. You basically have one of three reasonable choices on the Mac (that I'm aware of):
To be honest, I'm blown away that OpenGL does not have a provided text display function. Or SDL for that matter. I can guess as to WHY they did this: several approaches that allow for a by-need-basis for rendering. But geez! I never would have guessed that it would be THIS obscure! Thanks guys, I think I may do pre-rendered text for now. Thanks for the advice.
OpenGL text and other things. - OneSadCookie - Jul 22, 2008 02:09 AM
OpenGL doesn't because it's a low-level rendering API. Same reason it doesn't have texture loading functions.
SDL_ttf + SDL + OpenGL works reasonably well (see eg. Neverball).