Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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  
  Font engine  (Read 1718 times)
0 Members and 1 Guest are viewing this topic.
Offline sgthale

Senior Newbie





« Posted 2012-05-04 03:07:34 »

I was wondering what would be a good way to make a Font engine with the LWJGL to write text. The one I wrote currently works like this:

1.) Create a new StaticText class object passing in the X Y positions and the string that will be displayed.

2.) In the StaticText constructor, create a blank texture, bind a FrameBufferObject for rendering, and render all the letters into that new texture

3.) Since the StaticText class is extended to Component which holds the x,y,textureId variables, the renderer can loop through the Component array and draw everything.

Basically, every text object is rendered in the beginning within its own textureID so it doesnt have to render each letter again after every frame. Is this a slow way of doing a font engine? Any feedback?




Thats a pic of my font engine. The red outline is the size of the texture. When you pass in different lines "/n" it calculates how big the width and height of the texture has to be to fit in all lines.
Offline theagentd
« Reply #1 - Posted 2012-05-04 07:12:37 »

Seems perfectly fine. Text changes pretty slowly (someone has to read it xD), so prerendering it might be the best solution depending on how it will be used. You might end up with LOTS of textures though. It might be better to simpy store a Display List instead of a texture.

Myomyomyo.
Offline lhkbob

JGO Knight


Medals: 32



« Reply #2 - Posted 2012-05-04 07:17:25 »

My approach was to use a rectangle packer to draw all of the characters I might need into a BufferedImage using Java2D, and their anti-aliased font support.  I'd push the BufferedImage's byte data into a single OpenGL texture.  Then I'd create geometries for each text string I'd need with a quad per character and the appropriate texture coordinates to look up in the image.

All strings of the same font could use the same texture atlas.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-05-04 08:09:42 »

Basically if you ensure that all of your glyphs are in the same texture, and you draw your texture regions efficiently (i.e. using vertex arrays or VBOs) then you should be fine. That way you don't depend on frame buffers, or Java2D/AWT, or what have you.

You might want to look into TWL's BitmapFont tool, which is really useful for packing glyphs into a texture (with kerning information and all).
http://twl.l33tlabs.org/themer/fonttool.jnlp

Offline divxdede

Junior Member





« Reply #4 - Posted 2012-05-04 08:26:52 »

why rasterizing truetype fonts and not simply draw vectorial bezier curve ? (it's a naive question, it may be a good raison)
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 70
Projects: 15


★★★★★


« Reply #5 - Posted 2012-05-04 11:15:31 »

why rasterizing truetype fonts and not simply draw vectorial bezier curve ? (it's a naive question, it may be a good raison)
Drawing the bezier curve will only give you the outline to the font, to fill it with a solid color you'd have to probably use some sort of triangulator. Besides that method will use a lot more polygons, drawing raster fonts is much faster once they have been generated.
Offline Danny02
« Reply #6 - Posted 2012-05-04 11:55:18 »

The Jogl guys create an very interessting font rendering system, which uses shaders for rendering of the splines.
I haven't tryed it yet but are planning to use it when i need fonts in the future
http://ramisantina.com/blog/?p=73
Offline sgthale

Senior Newbie





« Reply #7 - Posted 2012-05-06 22:25:57 »

Is it bad to have too many textures? Does it clog RAM? But either way, im going to gradually delete the textures afterwards
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.

xsi3rr4x (51 views)
2014-04-15 18:08:23

BurntPizza (47 views)
2014-04-15 03:46:01

UprightPath (63 views)
2014-04-14 17:39:50

UprightPath (45 views)
2014-04-14 17:35:47

Porlus (62 views)
2014-04-14 15:48:38

tom_mai78101 (86 views)
2014-04-10 04:04:31

BurntPizza (144 views)
2014-04-08 23:06:04

tom_mai78101 (243 views)
2014-04-05 13:34:39

trollwarrior1 (202 views)
2014-04-04 12:06:45

CJLetsGame (209 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!