1

I have made a simple LWJGL program where it makes a display and renders text to the screen. I render text with Slick-util btw.

So my question is why does it take a couple seconds of a black screen(or whatever the clear color is) before it loads up. Is there a way to fix this? Can I hide the Display until it all renders? Well those are my questions. Here is my code:

package com.survivalpixel.kopis;

import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;

import java.awt.Font; 

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.TrueTypeFont;
public class Menu {
private int WIDTH = 1080,HEIGHT = 720;
Font font;
TrueTypeFont gamefont;
public static void main(String args[]){
    new Menu();
}
public Menu(){
    try {
        Display.setDisplayMode(new DisplayMode(WIDTH,HEIGHT));
        Display.setResizable(false);
        Display.setTitle("Kopis V.01");
        Display.create();
    } catch (LWJGLException e) {

    }

    initGL();
    init();


    while(!Display.isCloseRequested()){
        glPopMatrix();

        glClear(GL11.GL_COLOR_BUFFER_BIT);

        drawString("This is a test",100,100);

        Display.update();
        Display.sync(100);
        glPushMatrix();
    }
    Display.destroy();
    System.exit(0);
}
private void initGL() {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 1080, 720, 0, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glClearColor(0, 0, 0, 0);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


}
private void init() {

    font = new Font("times new roman", Font.BOLD,12);
    gamefont = new TrueTypeFont(font, false);


}
public void drawString(String s,int x, int y){
    gamefont.drawString(x, y, s);
}
}
36redsoxfan
  • 250
  • 2
  • 5
  • 15
  • Don't swallow exceptions. I think you have `glPushMatrix`/`glPopMatrix` swapped. [TrueTypeFont](http://slick.cokeandcode.com/javadoc/org/newdawn/slick/TrueTypeFont.html) seems to be deprecated - maybe that's why. – Piotr Praszmo May 19 '12 at 00:11

1 Answers1

0

As Banthar mentioned, glPushMatrix/glPopMatrix are in the wrong order. They are not even needed in your example so you can safely delete them.

Regarding the font, it seems UnicodeFont is now correct:

textFont = new UnicodeFont(new Font("Times New Roman", Font.PLAIN, 18));
textFont.addAsciiGlyphs();
textFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE));
textFont.loadGlyphs();

I have also tried your code, without any optimization and it runs correct despite the matrix order problem. Yes there is a small init time. But here it is very short, around a second. Either your hardware is generally very old or you may have a bad graphic driver.

Robert Kühne
  • 898
  • 1
  • 12
  • 33