LWJGL
May 22, 2013, 19:39:00 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.9.0 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Slick's TrueTypeFont.drawString("") behaves strange  (Read 5305 times)
Greenleon
Newbie
*
Posts: 10


« on: May 27, 2009, 09:24:07 »

Hello,

I shortly started to use slick-util. Now I am trying to draw a string into the opengl window. I tried it both of the ways that are explained here
http://slick.cokeandcode.com/wiki/doku.php?id=truetype_font_support

Unfortunately both are bringing the same results. A rectangle in the specified color where the text should have been.

The code:
Code:
package spiel;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.TrueTypeFont;
 
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
 
public class TTFTest {
 
private static final String GAME_TITLE = "test";
private static final boolean fullscreen = false;
    public static void main(String[] args)
        throws LWJGLException, FontFormatException, IOException {
 
        TrueTypeFont trueTypeFont;
 
        // not included for brevity
        initGL();
 
        Font startFont = Font.createFont(Font.TRUETYPE_FONT,
    new BufferedInputStream(new FileInputStream("verdana.ttf")));
        Font baseFont = startFont.deriveFont(Font.PLAIN, 50);
        trueTypeFont = new TrueTypeFont(baseFont, true);
       
        System.out.println(trueTypeFont.toString());
 
        while (true) {
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
            trueTypeFont.drawString(120.0f, 120.0f, "this is a test", Color.green);
 
            Display.update();
            if (Display.isCloseRequested()) {
                System.exit(0);
            }
        }
       
       
    }
   
    private static void initGL()
    {
    try{
        // Create a fullscreen window with 1:1 orthographic 2D projection (default)
        Display.setTitle(GAME_TITLE);
        Display.setFullscreen(fullscreen);
     
        // Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work)
        Display.setVSyncEnabled(true);
     
        // Create default display of 640x480
        Display.create();
        } catch (Exception e)
        {
       
        }
       
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glViewport(0,0,640,480);
    GL11.glOrtho(0, 640, 0, 480, 0, 25);
    //GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_BLEND);

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_ALWAYS);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glAlphaFunc(GL11.GL_GREATER, 0);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
   
    }

}

I have the file verdana.ttf (copied from /usr/share/fonts/truetype/msttcorefonts/) in the project folder which is on the classpath.

Any ideas?? It is frustrating!
Thanks!
Logged
Fool Running
Nerdus Imperius
*****
Posts: 742


« Reply #1 on: May 28, 2009, 10:45:54 »

I've never used Slick, but your problem sounds like one of 2 things:
*Either texturing is somehow being turned off (seems unlikely based on your code). You might try doing this:
Quote
If you use your own gl methods to bind textures, TrueTypeFont may not display correctly. To ensure TrueTypeFont works, insert a call to TextureImpl.bindNone() before your drawstring calls.
*Or your blending mode is weird (seems most likely based on your code). You might try removing the setup for the blending mode (still enable blending)

Logged

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option Grin
Greenleon
Newbie
*
Posts: 10


« Reply #2 on: May 28, 2009, 11:14:06 »

Thanks for the answer!
I tried bindNone()... did not change anything. And I do not really understand what you mean by "remove the setup for the blending mode". I do not have any setup for any blending mode. I just enabled GL_BLEND.

The full code of the testproject I am refering to is by the way with my first post.

Any other ideas??

Thanks!
Logged
Fool Running
Nerdus Imperius
*****
Posts: 742


« Reply #3 on: May 30, 2009, 19:55:48 »

Sorry, I was referring to the:
Code:
    GL11.glEnable(GL11.GL_ALPHA_TEST);
     GL11.glAlphaFunc(GL11.GL_GREATER, 0);
Its actually the alpha testing, not blending. They might mess with the texture blending of the font, though, which is what I was referring to.
Have you tried removing this from the code:
Code:
    GL11.glEnable(GL11.GL_DEPTH_TEST);
     GL11.glDepthFunc(GL11.GL_ALWAYS);
     GL11.glEnable(GL11.GL_ALPHA_TEST);
     GL11.glAlphaFunc(GL11.GL_GREATER, 0);
Just for testing.

Again, I'm just guessing since I don't use Slick at all. Undecided
Logged

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option Grin
Greenleon
Newbie
*
Posts: 10


« Reply #4 on: May 31, 2009, 09:56:53 »

This did not change anything...

Ah I found it. I just looked at the testutils glinit.
Somehow, you need to have this:

Code:
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Logged
princec
Nerdus Imperius
*****
Posts: 1870



WWW
« Reply #5 on: June 06, 2009, 01:11:50 »

Heh, not exactly "somehow" Wink That's pretty much the essential pair of lines to get any useful sprite work done.

Cas Smiley
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!