Sign in to follow this  
slavik

text rendering

Recommended Posts

slavik    116
I am writing a game and want to have a HUD. I have the code ready and everything. Only thing left for me is to render text in the HUD. Right now, I am aware of 4 different ways to draw text: 1. glutBitmapCharacter() 2. glutOutlineCharacter() 3. using the SDL_ttf library 4. creating a font texture and using textured GL_QUADS (also has the plus of being able to draw custom icons or other HUD elements) Which way of rendering text would be the fastest? Also, I am using SDL for windowing and input support, so I really don't want to use GLUT functions ...

Share this post


Link to post
Share on other sites
MARS_999    1627
As of right now I am going to guess the quad route would be the fastest, but I haven't tried it myself I use wglUseFontBitmaps()

Share this post


Link to post
Share on other sites
NickGravelyn    855
Honestly, I'd go with FTGL. It does standard 2D text (like the HUD as you mentioned) but also has the ability to handle 3D extruding. It requires that you have FreeType to build it, but it only took me about 10 minutes to get it compiled and be using FTGL in my program.

Basic usage of FTGL is like this:

#include "FTGLPixmapFont.h"

static FTFont* font;

font = new FTGLPixmapFont("../Assets/impact.ttf");
font->FaceSize(50);
font->CharMap(ft_encoding_unicode);

glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
char framerate[64];
sprintf(framerate, "FPS: %d", lastFramesPerSecond);
glColor4f(1, 0 , 0, .5);
glRasterPos2i(20,20);
font->Render(framerate);






I currently use FTGL with my SDL/OpenGL app and have had zero problems with it.

P.S. You can find a bit about FTGL and an example app at OpenGL's site here.

P.P.S. Don't use the windows function suggested. Nothing against the function itself, but I personally believe that if you're using SDL and OpenGL, you should keep everything as system independent as possible in case you ever want to port to other operation systems.

Share this post


Link to post
Share on other sites
slavik    116
Well, I am developing this game on my Linux laptop (Ubuntu) and for some reason glutBitmapCharacter gives linking errors on my Windows system :(

But yeah, I use SDL and OpenGL to be platform independent :D.


EDIT:
Here's another question.
If I were to use the texture method (by loading the font texture into an SDL surface) how would I be able to change the Hue? Assuming that I have a function that converts RGB and HSV between each other. Would this be done using masks?

EDIT2:
Does OpenGL support (use) the alpha channel (transparency) that is part of a texture (since PNG can do transparency).

[Edited by - slavik on April 23, 2006 11:44:22 PM]

Share this post


Link to post
Share on other sites
NickGravelyn    855
If you load a font in as a texture, simply have the texture be a PNG file with transparency. Make each character be white in the texture. Then you can simply do something like:

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glColor3f(1,0,0);
//rendertext


And you'll get red text.

Again, I'll still say using FTGL will save you so much time because it loads the .ttf files straight from the hard drive instead of making a texture, so it's much nicer to scale up or down without data loss. But take whichever route helps you out.

Share this post


Link to post
Share on other sites
slavik    116
I'll look into FTGL, but the reason why I am leaning towards textures is because the text I will use will be single sized anyway and I can also put in icons and weird images as part of text and the code will all be the same and easier to use (I think).

An example of this is Counter-Strike, because it has all of the HUD as textures and this allows users to alter the way the HUD looks (something that I would like the users to be able to do).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this