Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  
  Slick2D + Fonts = CRAZY THING  (Read 1870 times)
0 Members and 1 Guest are viewing this topic.
Offline ShuKen

Junior Member


Medals: 4



« Posted 2012-10-18 02:57:36 »

Hi guys! This is my first thread on this awesome forum. I have been reading a lot of threads, learning a lot of things thanks to all of you. Now I have another problem and I guess that nobody before posted it (i searched but find anything) (sorry for my bad english)

Im trying to use fonts on slick2D to simple draw "info strings" like player position, currentState and that kind of things.

The code:
import java.awt.Font;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.Graphics;

Font font = new Font("Serif", Font.BOLD, 15);
UnicodeFont ufont= new UnicodeFont(font, font.getSize(), font.isBold(), font.isItalic());
g.setFont(ufont);

g.drawString(cad, 15, 45);     <----------doesn't work (compile ok)
ufont.drawString(15, 45, cad);        <----------doesn't work either (compile ok)

Really dunno why.
Game runs fine. No warnings. No errors. No crashes. Just dont want to draw the Strings.

Any idea?

Thanks!!

P.D.: cad is already innitiated.
Offline Vladiedoo
« Reply #1 - Posted 2012-10-18 03:07:31 »

Welcome to JGO  Grin.

You need to add glyphs to your font. This explains how to do so http://slick.cokeandcode.com/wiki/doku.php?id=unicode_font_support.

Also for future reference, when you post code, look for the little #Button that reads "Insert Code" which will add [.code][./code] (but without the periods in there) and then you simply add your code between the two brackets to make something that looks like this.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
// I am not an expert but here is your code modified to work.
UnicodeFont ufont = null;
String cad = "test";
try {
   Font font = new Font("Serif", Font.BOLD, 15);
   ufont = new UnicodeFont(font, font.getSize(), font.isBold(), font.isItalic());
   ufont.addAsciiGlyphs();
   ufont.addGlyphs(400, 600);
   ufont.getEffects().add(new ColorEffect(java.awt.Color.WHITE));
   ufont.loadGlyphs();
} catch (SlickException e) {
   e.printStackTrace();
}
g.setFont(ufont);
g.drawString(cad, 150, 450);
ufont.drawString(200, 450, cad);
Offline StumpyStrust
« Reply #2 - Posted 2012-10-18 03:37:05 »

If this is with slick engine I do not know much about that but with the slick you use to render text in lwjgl I do not have to add glyphs.

Thing you may have to do is unbind any textures and then if you use colored text, set the color back to (1,1,1,1) as slick does not do this. Kinda retarded imho that it will not fix that but what ever.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-10-18 04:43:15 »

Some fonts above code point 127 take a really long time to load on certain Macs, so only add what you need.

If you aren't using the latest dev branch, then I'd recommend the following:
1  
   ufont.addGlyphs(32, 127);


If you are using the latest dev branch, the above should be equivalent to:
1  
   ufont.addAsciiGlyphs();




Quote
Thing you may have to do is unbind any textures and then if you use colored text, set the color back to (1,1,1,1) as slick does not do this. Kinda retarded imho that it will not fix that but what ever.
Slick binds textures and colors for you -- if no color is specified, white (1,1,1,1) will be used. If you are running into a texture bind bug, then you're either using an outdated version of Slick, or you're not using Slick's Texture.bind() utility.

Offline Cero
« Reply #4 - Posted 2012-10-18 13:28:29 »

In general its a "bad" practice to use unicode fonts, just use bitmap fonts / angelcode fonts

Offline ShuKen

Junior Member


Medals: 4



« Reply #5 - Posted 2012-10-18 16:18:14 »

Thank you guys for the quick answers!

Vladiedoo, your code works!. The link also helped a lot (I understand a bit more now Tongue)

davedes, how can I know if Im using the latest dev branch? I speak spanish, really dont know what a dev branch is but...It's the Slick version? Becouse i don't know that either (could be: #Sat Jun 26 18:22:25 UTC 2010 build=274   ?) im kinda lost on that too. I dont know what version of Slick Im using (but that is for other topic, I guess).

This whole world of fonts, Unicode, Angel, TrueType...I feel that I just dont know enough. AngelCode is the best choice? If it is, then I'll start watching it.
Offline davedes
« Reply #6 - Posted 2012-10-18 16:45:21 »

AngelCodeFont is the fastest and best choice for simple text rendering, but it's also more limited. It expects you to supply the font definition and image, which needs to be generated with a tool like BMFont (Windows) or TWL's Font Tool. It doesn't play well with unicode glyphs, so if you need multiple language support, I'd stick with UnicodeFont.

The main downside to UnicodeFont is that it's slightly slower to load; and on certain Macs including the codepoints 128-255 will increase loading to ~3.5 seconds for a single font (this seems to be a Mac and/or Java2D bug). Once it's loaded, it will perform nearly as efficiently as AngelCodeFont.

Also, if you want, you can load glyphs one at a time; in UnicodeFontTest it loads glyphs on the fly in the update loop. Presumably in a more complex game you would have a loading screen with a progress bar.

TrueTypeFont is deprecated and no longer maintained.

You can find more about the development branch here:
http://slick.javaunlimited.net/viewtopic.php?f=3&t=5171&start=0

Liam is working on a website which hosts a more recent build, although I'm not sure if the build includes the UnicodeFont changes I mentioned. To be safe, I'd just call addGlyphs(32, 127).

Offline ShuKen

Junior Member


Medals: 4



« Reply #7 - Posted 2012-10-18 17:28:08 »

AngelCodeFont is the fastest and best choice for simple text rendering, but it's also more limited. It expects you to supply the font definition and image, which needs to be generated with a tool like BMFont (Windows) or TWL's Font Tool. It doesn't play well with unicode glyphs, so if you need multiple language support, I'd stick with UnicodeFont.

The main downside to UnicodeFont is that it's slightly slower to load; and on certain Macs including the codepoints 128-255 will increase loading to ~3.5 seconds for a single font (this seems to be a Mac and/or Java2D bug). Once it's loaded, it will perform nearly as efficiently as AngelCodeFont.

Also, if you want, you can load glyphs one at a time; in UnicodeFontTest it loads glyphs on the fly in the update loop. Presumably in a more complex game you would have a loading screen with a progress bar.

TrueTypeFont is deprecated and no longer maintained.

You can find more about the development branch here:
http://slick.javaunlimited.net/viewtopic.php?f=3&t=5171&start=0

Liam is working on a website which hosts a more recent build, although I'm not sure if the build includes the UnicodeFont changes I mentioned. To be safe, I'd just call addGlyphs(32, 127).

Thanks dave! I guess I'll use Unicode at the moment. Been looking at the BMFont soft and topics about angel, and looks like that it's necesary one more step to make it work...I supose that I'll priorize other things first and maybe later look at angelcode seriusly.

Thanks for the answers guys!
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.

atombrot (25 views)
2014-08-19 00:29:53

Tekkerue (24 views)
2014-08-15 21:45:27

Tekkerue (23 views)
2014-08-15 21:22:17

Tekkerue (13 views)
2014-08-15 21:20:21

Tekkerue (20 views)
2014-08-15 21:12:11

Rayexar (58 views)
2014-08-10 17:49:23

BurntPizza (38 views)
2014-08-09 12:09:32

BurntPizza (30 views)
2014-08-07 17:01:56

Norakomi (37 views)
2014-08-06 10:49:38

BurntPizza (67 views)
2014-08-02 17:57:17
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!