Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Writing a String with lwjgl  (Read 4815 times)
0 Members and 1 Guest are viewing this topic.
Offline Guardian_SkaraBrae

Junior Newbie

Java games rock!

« Posted 2003-03-22 17:37:56 »


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....  Tongue

Offline princec

« JGO Spiffy Duke »

Medals: 1033
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #1 - Posted 2003-03-22 20:02:31 »

Ah, well, that's not so easy Smiley
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 Smiley

Offline cfmdobbie

Senior Devvie

Medals: 1

Who, me?

« Reply #2 - Posted 2003-03-23 09:12:42 »

That's not the simplest way to do it at all! Roll Eyes

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: (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. Grin


Hellomynameis Charlie Dobbie.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Guardian_SkaraBrae

Junior Newbie

Java games rock!

« Reply #3 - Posted 2003-03-24 12:59:37 »

Uou! Shocked

Realy, that's not so easy!

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

tnx very much! Grin
Pages: [1]
  ignore  |  Print  

EgonOlsen (74 views)
2018-06-10 19:43:48

EgonOlsen (55 views)
2018-06-10 19:43:44

EgonOlsen (74 views)
2018-06-10 19:43:20

DesertCoockie (254 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!