noztol
noztol

Reputation: 524

lwjgl and slick-util rendering text

Let me start with I can't find a Slick2d.jar file anywhere on the internet furthermore my project is not necessarily always going to be in 2d so I would prefer to use slick-util since that is recommended on the lwjgl website. Furthermore I know TrueTypeFont is depreciated in slick2d but this is the only way to draw text in slick-util

SO my code has the following lines:

import java.awt.Font;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.Color;

...

Font awtFont = new Font("Times New Roman", Font.ITALIC, 24);
font = new TrueTypeFont(awtFont, antiAlias);

...

font.drawString(dim.width/4+10,0, Income, Color.yellow)

...

As is I get one big yellow block I have no idea how to fix it. GL_TEXTURE_2D is already enable and I also do all the blend calls that other people have mentioned as solutions.

GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

Upvotes: 0

Views: 4433

Answers (3)

DaCoder
DaCoder

Reputation: 83

Well, I am 2 away from commenting, so @Twister1002 "Slick-Util uses Java's built in AWT Font support to load the fonts, so be sure to be familar with the AWT's Font class. You can use either the default built in java fonts or load external ttf files. The Slick-Util library will convert the AWT Font so that it can be used with OpenGL. The fonts are stored and drawn through slick's TrueTypeFont class."

And to answer your question: http://ninjacave.com/slickutil3 This example works fine for me. As to what caused your original issue, I cannot see anything you have posted (in the little amount of code you did post) that would cause such an error.

Upvotes: 1

DreamSea
DreamSea

Reputation: 11

Late answer, but I was unable to find anything when I searched for TrueTypeFont solutions earlier.

What was messing it up for me (and making the block instead of text) was calling/drawing both front and back buffers for various other reasons in my program.

GL11.glDrawBuffer(GL11.GL_FRONT_AND_BACK);
drawOtherStuff();

For whatever reason, the drawString() displays fine if I call/draw only the back buffer (and then returning to front and back before drawing other stuff again).

GL11.glDrawBuffer(GL11.GL_BACK);
font.drawString(100, 50, "THE LIGHTWEIGHT JAVA GAMES LIBRARY", Color.yellow);

No idea why it works. Also not sure if it is specific to my problem, but hope it might work as a temporary fix for others.

Upvotes: 1

Twister1002
Twister1002

Reputation: 557

You must use the Slick.jar file that was downloaded. All exceptions throw a "SlickExcpetion". If you also look into the graphics method it says Font type, however that MUST be a org.newdawn.slick.Font. It can NOT be used with AWT.

I've learned using Slick you have to use all it's Slick components; not any of the java ones.

Upvotes: 0

Related Questions