PDA

View Full Version : Rendering text in OpenGL



lanjoe9
05-27-2007, 08:18 AM
I'm using SDL and OpenGL to do a 3d game.
I saw SDL_TTF and tried to use it, which involves rendering text to a surface and blitting that surface to the "screen" surface.

Unfortunately this does not seem to work if the screen is an OpenGL surface, because I never see the font being rendered unless I deactivate the OpenGL
setting in the video mode (SDL_OPENGL) and comment all OpenGL instructions (i.e. deactivate OpenGL completely) on my app.

Is there any way I can do blitting (without using the SDL_OPENGL_Blitting or so hack (which I have found to be called the ultimate evil)), or any simple way to do font rendering ?

Or am I going to have to render font to a texture and use that texture in a polygon.. ?

In case I have to use the texture-polygon approach, can I do it in a way I only see the rendered text but not the entire polygon?

Thanks in advance!

lanjoe9
05-27-2007, 08:25 AM
Although in the end the texture-polygon approach does seem tempting to use for later in-game effects [what? no evil devil graemlin?? boo!]

Overmind
05-27-2007, 11:33 AM
In case I have to use the texture-polygon approach, can I do it in a way I only see the rendered text but not the entire polygon?Usually, you put the text in an alpha texture. So you can uses the alpha test to discard the rest of the polygon, and you can use blending to smooth the edges of the font.

V-man
05-27-2007, 11:59 PM
There are 2 options to the polygon and texture approach. Have one big poly that contains what you want displayed like "please type your name" or if your text will be dynamic, render each character, polygon after polygon.

It's also possible to do a render to texture approach for the dynamic text situation.
You need to decide if it is worth your time.

I would not trust SDL or FTGL. Perhaps they use those damn wgl functions.

Overmind
05-28-2007, 02:37 AM
FTGL uses Freetype 2 for font rendering, so it's propably safe to use on all platforms.

SDL_TTF does not use OpenGL at all. It's only for the 2D graphics part of SDL, it won't work directly with OpenGL.

zeoverlord
05-29-2007, 05:53 AM
NeHe lesson 17 (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=17)
I think this is all you need for now, there are better ways of doing this, but this works better then most methods just because you have complete control over the fonts and you can make them look any way you like (including evil devil graemlins).

Jorufo
05-31-2007, 05:14 PM
If you want a quality product, I would recommend defining the fonts as a list of lines and Bezier Curves. Then just render the outline and Tessellate the interior. This will give you a scalable font vs. one that is a set size.

Korval
05-31-2007, 07:12 PM
If you want a quality product, I would recommend defining the fonts as a list of lines and Bezier Curves.If you're going to do that, you may as well just download Font Creator and the FreeType library, and use their conversion program to generate glyph textures that you can use to render with.

No point in writing all of that code yourself. And FreeType has a very good license on it.