PDA

View Full Version : Making Text


Nick
2004.09.29, 01:21 PM
I've pretty much found that the only way to do text on my screen for scoring and such is through textures. I could go through and make about 19 or 20 textures for the numbers and letters I need but I'd rather make one big texture.

1) If I were to do this, where can I get premade font textures (when I draw in Photoshop, the letters don't line up and I'm quite lazy about doing it)?
2) How do I code in OpenGL to take a part of the texture? Currently I'm using glTexCoord2f() with 1 and 0 being the only numbers I've ever used. How do I figure out the float values I'd need in this situation?
3) Is there an easier way out there?

Josh
2004.09.29, 01:33 PM
That method is used by NeHe is many of his tutorials. Check them out for examples of how to implement it.

Another method would be to use FTGL and FreeType. So far, this method has worked well for me.

Nick
2004.09.29, 01:33 PM
Thanks I'll check that out.

OneSadCookie
2004.09.29, 06:39 PM
why on earth can't people search the forum before they ask questions?

Searching simply for "text opengl" turns up a number of helpful-looking threads!

PowerMacX
2004.10.09, 02:35 PM
My CFont class (wich is based on NeHe's tutorial) loads the characters from two files:

One big texture with all the normal characters
One text file containing the positions and options for each char


Now, how do I generate the texture & the text file? I made a little app wich

takes a 24 or 32 bit (with an alpha channel) TGA image that has all the characters in one long strip
automatically detects each character
figures out the best size for the texture (power of 2, square)
generates a texture file & a txt with all the positions.


This can then be loaded in my CFont class:
CFont myFont;
myFont.Load("prettyfont"); // This will load prettyfont.tga & prettyfont.txt
and printed:
myFont.Print(x,y,"Current FPS:%0.1f",fps); // By default, it prints to a virtual screen of 800x600, but has a method to change it

I can upload it to my site if anybody is interested.

arekkusu
2004.10.09, 04:08 PM
If you're just using system fonts, you can of course render all the characters into a texture at run time. The Untima source shows how to do this.

codemattic
2004.10.13, 04:14 PM
I can upload it to my site if anybody is interested.

I would be very interested in that PMX!

PowerMacX
2004.10.14, 11:42 AM
I would be very interested in that PMX!

I have an exam in about an hour, after that, I'll make a small example project and upload it to my site (tomorrow or the day after).

codemattic
2004.10.14, 12:13 PM
great - thanks. there is no rush - exams come first and all that!

PowerMacX
2004.10.14, 02:53 PM
Finished my exam, relatively easy (IA - Expert Systems). I should probably make some simple Cocoa interface for my font-maker app, but at least for now I'll leave it as it is (100 lines of C, expects to find a file called font.tga on it's path, 24 or 32 bits, and generates TextureFont.tga & TextureFont.dat)

In the meantime, in my old site (http://www28.brinkster.com/ignacio3d/), you can download the code for vSpeed, a simple game I made for Vectorized (althrough I didn't finish it on time) wich uses the font loading class, CFont, and has an ugly font file included (ugly because it had to look "vectorized").

Warning: the CFont class in that game is not the latest version I have, I'll upload it along with the FontMaker app later.

Ignacio

PowerMacX
2004.10.16, 10:12 AM
OK, the FontMaker app is ready, I just made a short Cocoa wrapper for it (2 lines of code!) so you can drop a tga file on it and it will create the texture font files. I just need to make a sample OpenGL app to demo the CFont class and then I'll upload it to my site. (Tonight or tomorrow, depending on when I get home)

PowerMacX
2004.10.18, 08:50 PM
Well, I went way to far with this, as you can see in this screenshot:
http://www.reversecode.com/powermacx/images/screenshots/cfontdemo01.jpg

So basically, now you have two apps: FontMakerBasic, for making fonts, and CFontDemo to preview them.

I'm making this available 100% free, even for commercial apps, as long as you credit me in the readme/about box.

VERY IMPORTANT: If you are a contestant in uDG 2004, remember that I am too, so check the rules before using any of this code. Since I'm making this available to everyone, and not just to one contestant, I think that it's allowed by the rules but:

Carlos, if you are reading this, what do you think?

Download (http://www.reversecode.com/powermacx/developer.html)

codemattic
2004.10.19, 11:29 AM
very cool PMX!