Writing a String with lwjgl

Hi,

I’m just wanna know if there some way to write a string in the screen using OpenGL?

Why? Because i wanna show the FPS on the screen… :stuck_out_tongue:

tnx

Ah, well, that’s not so easy :slight_smile:
I’ll go through the steps, and you’ll have to work out the details:

  1. Pick a non-proportional font for simplicity. One that fits nicely in 16x16 squares for example.

  2. Render this font ahead of time into a 256x256 luminance alpha texture (ie. monochrome with alpha channel), so that each character in the font occupies a 16x16 tile. Each character could be positioned according to its ascii value; eg. ‘A’ is 65, so it would be 1 across and 4 down at (16,64).

  3. When the time comes to render strings in OpenGL, bind to that texture, and render quads according to the characters in the string you want to render. Texture coordinates are in fractions of course, so instead of 0…256 coordinates you’re dealing with 0.0f to 1.0f, so scale them accordingly.

That’s the simplest way to do it.

Cas :slight_smile:

That’s not the simplest way to do it at all! ::slight_smile:

It’ll probably give you the best performance, but drawing bitmaps is a lot easier. You’ll get it working a lot faster as well. Check out the font.c example code from Redbook 1.0. Here a link I prepared earlier:

http://www.cs.rit.edu/usr/local/pub/ncs/graphics/OpenGL.old/src/font.c (cut and paste this link, the forum software doesn’t recognise it properly)

That should get you up and running displaying text - I think it took me about 20 mins to rip the raster definition and write the glBitmap code to go around it.

You should probably write a “proper” textured quad system eventually, as it allows you to scale fonts, rotate them etc, and will probably be faster, but a glBitmap solution will get you up and running faster.

For extra brownie points, abstract it away behind a text-rendering interface, so you can swap it out to a textured quad system later with no core code changes. ;D

HTH!

Uou! :o

Realy, that’s not so easy!

I’ll try do it and when i get some results, i show to you.

tnx very much! ;D