Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
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 2952 times)
0 Members and 1 Guest are viewing this topic.
Offline sgthale

Senior Newbie

« Posted 2012-05-04 01: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 05: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.

Offline lhkbob

JGO Knight

Medals: 32

« Reply #2 - Posted 2012-05-04 05: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 06: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).

Offline divxdede
« Reply #4 - Posted 2012-05-04 06: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: 120
Projects: 15


« Reply #5 - Posted 2012-05-04 09: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 09: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
Offline sgthale

Senior Newbie

« Reply #7 - Posted 2012-05-06 20: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  

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

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

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

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

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

Solater (65 views)
2018-03-17 05:04:08

nelsongames (110 views)
2018-03-05 17:56:34

Gornova (175 views)
2018-03-02 22:15:33

buddyBro (730 views)
2018-02-28 16:59:18

buddyBro (93 views)
2018-02-28 16:45:17
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!