SDL/OpenGL and fonts

I need portable way to draw fonts in SDL/OpenGL. Last time I used method
described in NeHe tutorial, but it needs X, so it doesn’t work it Windows. It’s
even doesn’t work with one Debian version (probably something broken in XFree86
there).
I don’t need 3D fonts. I need only flat text on OpenGL surface. Maybe I should
draw text in bitmap, then use it as texture? But how can I draw that text? Must
I use SDL_ttf, or is it a way to do it only with SDL?–
decopter - free SDL/OpenGL simulator under heavy development
download it from http://decopter.sourceforge.net

I need portable way to draw fonts in SDL/OpenGL.
I don’t need 3D fonts. I need only flat text on OpenGL surface. Maybe I
should draw text in bitmap, then use it as texture? But how can I draw
that text? Must I use SDL_ttf, or is it a way to do it only with SDL?

Of course you can do it with just SDL. However, if you specifically want to
be able to use truetype fonts, then SDL_ttf would be your best bet. If you
just want to get something displayed, you might like to check out Karl
Bartel’s SFont library (GPL):

http://www.linux-games.com/sfont/

It consists of just two files (a .c and a .h) that you can compile into your
program - no extra libraries, and it’ll run anywhere SDL runs. The fonts
themselves are stored in a single image file - there’s a few on the website
you can use, and it’s not too hard to make your own.

It can render a line of text onto an SDL_Surface for you, which you can then
convert into an OpenGL texture, or do whatever it is you do (I’m not an OGL
programmer)On Mon, 31 Dec 2001, Jacek [iso-8859-2] Pop?awski wrote:

Mike.

If you’re looking for a debugging/console font for OpenGL, you can do it
even easier. If you can load a PNG or Targa, you can get any font of the
Q3A console variety to work with a simple Draw_Character function which
takes an X, Y, and character. Nothing written to use SDL surfaces will
ever be that simple or lightweight. A Q3A console font ix 16x16, both
characters and size of the characters. Q2 has a simple example of doing
this if you need it, but you probably won’t.

After you’re in 2D mode, just do this:

sl = (num & 15) * 0.0625;
sh = sl + 0.0625;

tl = (num >> 4) * 0.0625;
th = tl + 0.0625;

glBindTexture2D (charfont);

glBegin (GL_QUADS);
glTexCoord2f (sl, tl);
glVertex2f (x, y);
glTexCoord2f (sh, tl);
glVertex2f (x+16, y);
glTexCoord2f (sh, th);
glVertex2f (x+16, y+16);
glTexCoord2f (sl, th);
glVertex2f (x, y+16);
glEnd ();

Obviously, if you are going to do a whole string, it’s best to do so since
you can just change texcoords and vertices without changing anything else.
Also, while converting the above to vertex arrays gains you virtually
nothing, a whole string (or screen!) of them would serve as a good use of
them. The math at the top is nothing magic once I remind you that the
characters are stored in a 16x16 grid and that 1/16.0 == 0.0625.

Getting in and out of a mode where glVertex2f will work like that I’ll
leave to you to write or copy from testgl.On Mon, Dec 31, 2001 at 09:33:35PM +0800, Mike wrote:

I need portable way to draw fonts in SDL/OpenGL.
I don’t need 3D fonts. I need only flat text on OpenGL surface. Maybe I
should draw text in bitmap, then use it as texture? But how can I draw
that text? Must I use SDL_ttf, or is it a way to do it only with SDL?

Of course you can do it with just SDL. However, if you specifically want to
be able to use truetype fonts, then SDL_ttf would be your best bet. If you
just want to get something displayed, you might like to check out Karl
Bartel’s SFont library (GPL):

http://www.linux-games.com/sfont/

It consists of just two files (a .c and a .h) that you can compile into your
program - no extra libraries, and it’ll run anywhere SDL runs. The fonts
themselves are stored in a single image file - there’s a few on the website
you can use, and it’s not too hard to make your own.

It can render a line of text onto an SDL_Surface for you, which you can then
convert into an OpenGL texture, or do whatever it is you do (I’m not an OGL
programmer)


Joseph Carter Not many fishes

For every vision there is an equal and opposite revision.

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011231/d6b09417/attachment.pgp

I need portable way to draw fonts in SDL/OpenGL. Last time I used method
described in NeHe tutorial, but it needs X, so it doesn’t work it Windows. It’s
even doesn’t work with one Debian version (probably something broken in XFree86
there).
I don’t need 3D fonts. I need only flat text on OpenGL surface. Maybe I should
draw text in bitmap, then use it as texture? But how can I draw that text? Must
I use SDL_ttf, or is it a way to do it only with SDL?

make a custom ‘font’ texture and use a formula to extract the right part
of it. Take a look at mark kilgards “texfont” package, I believe steve baker
uses it or at least the format in his plib project

    -Erik <@Erik_Greenwald> [http://math.smsu.edu/~erik]

The opinions expressed by me are not necessarily opinions. In all probability,
they are random rambling, and to be ignored. Failure to ignore may result in
severe boredom or confusion. Shake well before opening. Keep Refrigerated.