Text error with LWJGL and Slick2D
NickName:Pastadin Ask DateTime:2013-09-26T01:11:37

Text error with LWJGL and Slick2D

I've been attempting to build a small program with the LWJGL just to go teach myself a bit of graphics, when I try to overlay text onto a 2D scene i'm drawing (this being a box that continuously bounces off all the sides of the window) the text becomes blurred and the box flickers repeatedly - https://i.stack.imgur.com/OATmd.jpg Stranger still, if I copy the font.drawString line but have it display a single word instead of the co-ords it doesn't flicker at all but is still blurry - https://i.stack.imgur.com/vnIK6.jpg.

Would anyone be able to help me with why this is happening and how I would fix it? I'm quite proficient in Java but this is the first time i've attempted anything graphics orientated.

import java.nio.FloatBuffer;
import java.text.DecimalFormat;

import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.ColorEffect;

import org.lwjgl.BufferUtils;

import static org.lwjgl.opengl.GL11.*;


public class TimerDemo
{
//time in ms since the last frame was rendered
private static long lastFrame;

//current time in ms
private static long getTime()
{
    return (Sys.getTime() * 1000) / Sys.getTimerResolution();
}

//gets the difference between the current time and lastFrame, then updates lastFrame
private static double getDelta()
{
    long currentTime = getTime();
    double delta = (double) (currentTime - lastFrame);
    lastFrame = getTime();
    return delta;
}


private static UnicodeFont font;
private static void setUpFonts()
{
    java.awt.Font awtFont = new java.awt.Font("Arial", java.awt.Font.PLAIN, 12);
    font = new UnicodeFont(awtFont);
    font.getEffects().add(new ColorEffect(java.awt.Color.white));
    font.addAsciiGlyphs();

    try
    {
      font.loadGlyphs();
    } 
    catch (SlickException e)
    {
        e.printStackTrace();
    }
}

public static void main(String[] args)
{
    try
    {
        Display.setDisplayMode(new DisplayMode(680, 480));
        Display.setTitle("Timer Demo");
        Display.create();
    }
    catch (LWJGLException e)
    {
        e.printStackTrace();
        Display.destroy();
        System.exit(1);
    }

    setUpFonts();

    //position
    int x = 100;
    int y = 100;

    //velocity
    int dx = 1;
    int dy = 1;

    //ensure lastframe is updated
    lastFrame = getTime();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 680, 480, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);


    while (!Display.isCloseRequested())
    {
        // Render

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();

        //change in position
        double delta = getDelta();

        if(x + 30 >= 680)
            dx = -1;
        else if (x <= 0)
            dx = 1;

        if(y + 30 >= 480)
            dy = -1;
        else if (y <= 0)
            dy = 1;

        x += delta * dx * 0.1;
        y += delta * dy * 0.1;

        glRecti(x, y, x + 30, y + 30);

        font.drawString(100, 10, "x is " + x + " y is " + y);


        Display.update();
        Display.sync(60);
        }

    Display.destroy();
    System.exit(0);
}
}

Copyright Notice:Content Author:「Pastadin」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19011174/text-error-with-lwjgl-and-slick2d

More about “Text error with LWJGL and Slick2D” related questions

Slick2D vs Straight LWJGL

I've been delving into game programming with Slick2D, and I've began to wonder if in the long run, knowing LWJGL would be more helpful. On one hand, Slick2D is fast and simple, but it seems LWJGL is

Show Detail

Rendering text with Slick2D inside a LWJGL window?

How would I render a basic string using Slick2D inside a window created with Display.Create() from LWJGL?

Show Detail

Slick2d - LWJGL Applet not finding /LZMA/LzmaInputStream

I can't run a Slick2d/lwjgl applet on my website and the only error I can see is this: WARNING: No file found for: /LZMA/LzmaInputStream.class Here is my applet code: &lt;applet code="org.lwjgl...

Show Detail

Java Slick2D Library

I decided to play around with Slick2D and LWJGL library. LWJGL is running pretty much smoothly, except with Slick2D which is working too but I'm getting a bit confused of two things. First some err...

Show Detail

lwjgl + slick2d + jinput error on 64-bit linux

I am using Linux (Ubuntu 12.04) with 64-bit java 7 and Eclipse (Indigo). On the game project we are using slick2d and along with it lwjgl. I was halted by the following errors. (fixes explained in ...

Show Detail

Rotation of rectangular Slick2d image with LWJGL causing distortion

I'm trying to rotate a rectangular Slick2d image with pixel size 666 x 333 using LWJGL. I was able to rotate a square image with pixel size 666 x 666 around its center, but the rectangular image does

Show Detail

Text error with LWJGL and Slick2D

I've been attempting to build a small program with the LWJGL just to go teach myself a bit of graphics, when I try to overlay text onto a 2D scene i'm drawing (this being a box that continuously bo...

Show Detail

LWJGL & Slick2D 64 bit

I'm trying to compile a program in LWJGL and Slick2D using 64 bit JDK 8u60. However, when I don't put the natives in it says it's missing lwjgl64. Once I import the lwjgl64.dll natives, there is a

Show Detail

Trouble adding lwjgl natives

I'm trying to set up Slick2D but I can't run my program because of the natives is not being added correctly. I have the location of them added the the lwjgl.jar in my Slick2D library and have them ...

Show Detail

LWJGL Package is sealed

I'm following along with a youtube tutorial on programming in Java using Slick2D and lwjgl. When I run this code: package game; import org.newdawn.slick.*; import org.newdawn.slick.state.*; public

Show Detail