Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 12:59 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Mar 05, 2012 8:12 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
Hello,

I seem to have a little problem, so the idea is to show a rotated text with a custom font
all goes well but i see that my font doesn't look nice anymore (anti aliased / smooth) when i've rotated it
any ideas?

g.setAntiAlias(true);
g.rotate(0, 0, -4);
txt1.render(gc, g);
g.rotate(0, 0, 4);
g.setAntiAlias(false);
g.resetTransform();

txt1 is an instance of Label
label = new Label(txt);
label.setFont(fnt);
label.setForeground(clr);
label.setSize(width, height);
label.setLocation(x, y);
label.setHorizontalAlignment(hAlign);
label.setVerticalAlignment(vAlign);
label.setOpaque(false);

The creation of the font:

UnicodeFont ttf = new UnicodeFont(path, size, bold, italic);
ttf.addAsciiGlyphs();
ttf.getEffects().add(new ShadowEffect(Color.black, 2, 2, 1));
ttf.getEffects().add(new GradientEffect(Color.yellow, Color.red, .5f));
ttf.loadGlyphs();


Top
 Profile  
 
PostPosted: Tue Mar 06, 2012 1:11 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
Try setting the filter on the font image to FILTER_LINEAR. Keep in mind that this may cause problems if you plan to scale the font, depending on the sprite sheet (which is why SpriteSheets and Fonts tend to default to FILTER_NEAREST filtering).


EDIT: For UnicodeFont, it would look something like this (untested...)
Code:
... init font glyphs ...
List l = font.getGlyphPages();
for (int i=0; i<l.size(); i++) {
    ((GlyphPage)l).getImage().setFilter(Image.FILTER_LINEAR);
}


Top
 Profile  
 
PostPosted: Tue Mar 06, 2012 8:41 am 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
thanks for the reply so i've added this: but i don't see any difference, maybe my font ttf is of poor quality or so?

List l = ttf.getGlyphPages();
for (Object aL : l)
((GlyphPage) aL).getImage().setFilter(Image.FILTER_LINEAR, path);

ttf.loadGlyphs();


Top
 Profile  
 
PostPosted: Tue Mar 06, 2012 3:56 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
Try adding it after you've loaded your glyphs.


Top
 Profile  
 
PostPosted: Tue Mar 06, 2012 9:42 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
hmm.. doesn't do the trick..
i even converted everything to the hiero settings files

UnicodeFont ttf = new UnicodeFont("hh\\config\\fonts\\font" + fnt + ".ttf", "hh\\config\\fonts\\" + hiero + ".hiero");
ttf.addAsciiGlyphs();
ttf.addNeheGlyphs();
ttf.loadGlyphs();
List l = ttf.getGlyphPages();
for (Object aL : l)
((GlyphPage) aL).getImage().setFilter(Image.FILTER_LINEAR, "hh\\config\\fonts\\font" + fnt + ".ttf");


Top
 Profile  
 
PostPosted: Tue Mar 06, 2012 9:55 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
The following works fine on my end, and produces a much more aliased result than with default filtering:
Code:
      f = new UnicodeFont(new java.awt.Font("serif", java.awt.Font.PLAIN, 32));
      f.getEffects().add(new ColorEffect(java.awt.Color.white));
      f.addAsciiGlyphs();
      f.loadGlyphs();
      List<GlyphPage> list = (List<GlyphPage>)f.getGlyphPages();
      for (GlyphPage page : list)
         page.getImage().setFilter(Image.FILTER_LINEAR);


If you're having trouble, try uploading a small test case and provide the font file that isn't working.

Also, have you considered AngelCodeFont? It's much faster and more efficient if you're just trying to render plain fixed-size text.


Top
 Profile  
 
PostPosted: Thu Mar 08, 2012 8:49 am 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
probably i won't rotate it or put it on an image or so :)

another off topick question because i see you are the autor of the slick sui api
in my game a user needs to create his profile by typing his nickname in a textfield
but is there any possibility to center the text in the textfield when he/she is typing?
(mdes.slick.sui.TextField)

tx


Top
 Profile  
 
PostPosted: Thu Mar 08, 2012 8:00 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
mortias wrote:
probably i won't rotate it or put it on an image or so :)

another off topick question because i see you are the autor of the slick sui api
in my game a user needs to create his profile by typing his nickname in a textfield
but is there any possibility to center the text in the textfield when he/she is typing?
(mdes.slick.sui.TextField)

tx

SlickSui is dead and no longer maintained... And it's pretty awful compared to solutions like TWL or Nifty-GUI. :)

I don't remember most of the code to be honest, so I can't help answer questions on it.


Top
 Profile  
 
PostPosted: Fri Mar 23, 2012 12:20 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
for the record, AngelcodeFonts is indeed the font type you should use in slick
for performance and rendering reasons, if you rotate strings with this type it is properly rendered


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group