OpenGL text and other things.

Member
Posts: 215
Joined: 2008.06
Post: #1
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?

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #2
Text in OpenGL is a widely debated topic, see http://www.idevgames.com/forum/showthread.php?t=11231
http://www.idevgames.com/forum/showthread.php?t=10370
http://www.idevgames.com/forum/showthread.php?t=3798

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.
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #3
kodex Wrote:Text in OpenGL is a widely debated topic, see http://www.idevgames.com/forum/showthread.php?t=11231
http://www.idevgames.com/forum/showthread.php?t=10370
http://www.idevgames.com/forum/showthread.php?t=3798

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.

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?

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #4
Define "text" first.

Like this?
Or like this?
Or maybe like this?
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #5
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. [edit] 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...
Quote this message in a reply
Member
Posts: 338
Joined: 2004.07
Post: #6
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.

Justin Ficarrotta
http://www.justinfic.com
"It is better to be The Man than to work for The Man." - Alexander Seropian
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #7
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):

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. [edit] 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...

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.

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
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).
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Opengl/Cocoa text rendering tesil 15 17,916 Mar 20, 2012 11:16 AM
Last Post: OneSadCookie
  SDL/OpenGL fullscreen text rendering StealthyCoin 2 6,633 Mar 26, 2009 09:47 AM
Last Post: StealthyCoin
  OpenGL Text Rendering (in Cocoa) daveh84 5 8,021 Feb 19, 2009 12:44 PM
Last Post: TomorrowPlusX
  Seriously strange things Talyn 5 3,176 Feb 8, 2009 11:28 AM
Last Post: arekkusu
  opengl text/font drawing from CGContext fretmunky 11 13,278 Dec 7, 2008 11:29 AM
Last Post: fretmunky