Slick's TrueTypeFont.drawString("") behaves strange

Started by Greenleon, May 27, 2009, 16:24:07

Previous topic - Next topic

Greenleon

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:
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!

Fool Running

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:
QuoteIf 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)

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Greenleon

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!

Fool Running

Sorry, I was referring to the:
   	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:
   	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. :-\
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Greenleon

This did not change anything...

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

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

princec

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

Cas :)