Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
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  
  Basic true-type font renderer  (Read 3419 times)
0 Members and 1 Guest are viewing this topic.
Offline Spacebeans
« Posted 2014-05-31 00:47:34 »

Are there any good ways to render a true-type font without slick2D, and mainly any other library (With LWJGL...)? I also need it to work well with blending, anti-aliasing, and the coordinates have to be at the top-left-hand corner (or if you have a way to change it in realtime, without any effect on performance, let me know!)
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #1 - Posted 2014-05-31 00:52:43 »

There's gdx-freetype: https://github.com/libgdx/libgdx/wiki/Gdx-freetype

If you want a "pure java" solution, then why not just use Font?

1  
2  
font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("font.ttf"));
font.deriveFont(24f);


Then render to BufferedImage with Graphics2D or something and go from there.
Offline wessles
« Reply #2 - Posted 2014-05-31 00:53:28 »

Why won't you use slick? You wouldn't even need to import a whole new jar, you would just need to copy and modify this code. Just be sure to include a license in it!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spacebeans
« Reply #3 - Posted 2014-05-31 01:15:51 »

Why won't you use slick? You wouldn't even need to import a whole new jar, you would just need to copy and modify this code. Just be sure to include a license in it!

Because X:0, and Y:0 in slick is in the bottom left and I already tried to fix it... I found a plain LWJGL port here: http://lwjgl.org/forum/topics/help-with-picking-for-a-n00b/2951/view.html

But the main thing I'm worried about is how 0, 0 is at the bottom left in the vertex locations. Any way to fix this?
1  
2  
3  
4  
5  
6  
7  
8  
       GL11.glTexCoord2f(TextureSrcX, TextureSrcY);
      GL11.glVertex2f(drawX, drawY);
      GL11.glTexCoord2f(TextureSrcX, TextureSrcY + RenderHeight);
      GL11.glVertex2f(drawX, drawY + DrawHeight);
      GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY + RenderHeight);
      GL11.glVertex2f(drawX + DrawWidth, drawY + DrawHeight);
      GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY);
      GL11.glVertex2f(drawX + DrawWidth, drawY);
Offline wessles
« Reply #4 - Posted 2014-05-31 01:21:32 »

This is not that complex math, but I feel your pain; I myself have debugged this for hours before, but solved it after a bit. Here is how I fixed a similar coordinate issue in MERCury:

From here

1  
2  
3  
4  
5  
// sy1 is the first texture coordinate's y value
// sy2 is the second texture coordinate's y value
// h is the height of the texture being drawn
sy1 = h - sy1;
sy2 = h - sy2;


Please forgive me if this code is completely irrelevant; I did not get too much sleep Tongue. But I am confidant this will help.

Although, couldn't you just rewrite the OGL for your own texture-drawing purposes?

-wes
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #5 - Posted 2014-05-31 01:38:45 »

If the coordinate system is all that is holding you back, then yeah, you just rotate all y-coordinates about the line y = <height> like wes said.

1  
2  
3  
int yCoordToDrawTextAt = 10; // from top-left

drawText(x, h - yCoordToDrawTextAt); // draw it with OGL, using flipped coords


Alternatively, you can use J2D just for it's rasterizer, as shown here by mattdesl: https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-&-Java2D
It's a good method if you are familiar with J2D and don't want to fuss with stuff to get your fonts rendered in OGL.
Should be pretty easy to port if you're not using libGDX.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2014-05-31 12:35:51 »

To everybody suggesting
y = h-y;
please know it's
y = (h-1)-y;
Pointing

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline wessles
« Reply #7 - Posted 2014-05-31 17:24:55 »

I really am starting to seriously question how many other things I have miscalculated by this logic. Always off by 1 pixel!
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #8 - Posted 2014-05-31 18:11:08 »

To everybody suggesting
y = h-y;
please know it's
y = (h-1)-y;
Pointing

Ah hell, quite right.

Quote
There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (847 views)
2019-09-04 15:33:17

hadezbladez (5791 views)
2018-11-16 13:46:03

hadezbladez (2603 views)
2018-11-16 13:41:33

hadezbladez (6207 views)
2018-11-16 13:35:35

hadezbladez (1499 views)
2018-11-16 13:32:03

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

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

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

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

nelsongames (5501 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04: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!