Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 3185 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 »

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


tnx
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 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 Member


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:

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

HTH!

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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (78 views)
2014-09-10 06:39:09

Tekkerue (38 views)
2014-09-09 02:24:56

mitcheeb (58 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (35 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!