Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 2:20 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed Jan 13, 2010 9:28 pm 
Offline
User avatar

Joined: Wed Jan 13, 2010 9:14 pm
Posts: 9
There is a problem with displaying really big fonts.

See the sample program below :

Code:
import org.newdawn.slick.*;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.font.effects.ColorEffect;

import java.awt.Color;
import java.awt.Font;


public class FontTest extends BasicGame {
    private UnicodeFont fUnicodeFont;

    public FontTest() {
        super("FontTest");
    }

    @Override
    public void init(GameContainer gameContainer) throws SlickException {
        Font font = new Font("Verdana", Font.PLAIN, 20);
        fUnicodeFont = new UnicodeFont(font, 300, false, false);

        fUnicodeFont.getEffects().add(new ColorEffect(Color.GREEN));
        fUnicodeFont.addAsciiGlyphs();
        fUnicodeFont.loadGlyphs();
    }

    @Override
    public void update(GameContainer gameContainer, int i) throws SlickException {
        // do nothing
    }

    public void render(GameContainer gameContainer, Graphics graphics) throws SlickException {
        graphics.drawRect(0, 0, 800, 600);
        fUnicodeFont.drawString(10, 10, "SOS");
    }

    public static void main(String[] args) throws SlickException {
        AppGameContainer app = new AppGameContainer(new FontTest());
        app.setDisplayMode(800, 600, false);
        app.start();
    }
}


With font size 300, the text is displayed correctly on the screen.
Change the font to 450 and you get a bizarre effect.

http://fng.narfum.org/!/slick/big_font_bug_300.png
http://fng.narfum.org/!/slick/big_font_bug_450.png

slick build 270
lwjgl 2.2.1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 02, 2010 10:32 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
It's because the texture size isn't big enough to fit all the characters on I expect. I though Unicode font handled this correctly. Did you have any luck with TrueType fonts in this case?

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 03, 2010 7:41 pm 
Offline
User avatar

Joined: Wed Jan 13, 2010 9:14 pm
Posts: 9
I tried with truetype fonts.

Code:
import org.newdawn.slick.*;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.font.effects.ColorEffect;

import java.awt.Color;
import java.awt.Font;


public class FontTest extends BasicGame {
    private UnicodeFont fUnicodeFont;

    public FontTest() {
        super("FontTest");
    }

    @Override
    public void init(GameContainer gameContainer) throws SlickException {
        Font font = new Font("Verdana", Font.PLAIN, 20);
        fUnicodeFont = new UnicodeFont(font, 300, false, false);

        fUnicodeFont.getEffects().add(new ColorEffect(Color.GREEN));
        fUnicodeFont.addAsciiGlyphs();
        fUnicodeFont.loadGlyphs();
    }

    @Override
    public void update(GameContainer gameContainer, int i) throws SlickException {
        // do nothing
    }

    public void render(GameContainer gameContainer, Graphics graphics) throws SlickException {
        graphics.drawRect(0, 0, 800, 600);
        fUnicodeFont.drawString(10, 10, "SOS");
    }

    public static void main(String[] args) throws SlickException {
        AppGameContainer app = new AppGameContainer(new FontTest());
        app.setDisplayMode(800, 600, false);
        app.start();
    }
}


With font-size 50, the text is displayed correctly.
If we change the font-size to 70, only the O is displayed.
With font-size 80, we don't see anything on screen.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 03, 2010 8:03 pm 
Offline
User avatar

Joined: Wed Jan 13, 2010 9:14 pm
Posts: 9
I found a workaround for the original problem by adding the following line right before the drawString statement:

Code:
graphics.scale( 1.5f, 1.5f );


This solves the problem, but produces ugly and not so sharp text :)

http://fng.narfum.org/!/slick/big_font_300_ugly.png


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2010 10:59 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
The original problem is due to running out of texture space on the card. I can only reproduce it on my limited machine, not on the one with the decent graphics card. Think we'll have to accept it as a limitation of the API. You can work round by only loading the characters you're expecting to display which presumably is going to be pretty limited at point size 450.... bit confused what the use case for 450 point size fonts is.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2010 5:13 pm 
Offline
User avatar

Joined: Wed Jan 13, 2010 9:14 pm
Posts: 9
I needed it for a fancy countdown timer.
And the last 10 seconds are filled with big numbers on screen.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2010 6:09 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
But doesn't 450 point font more than cover the screen, like way way way more? Even so, if it's just numbers you could use a charset that only contained numbers and it'll more likely work.

Kev


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 0 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