My texture is flickering, it keeps showing up normal and after 5 seconds it starts to flicker again and then it shows up normal again. Is it my game loop or what is it?
Source code:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class Main {
public boolean finished = false;
Texture texture;
float x = 50.0f;
float y = 50.0f;
public Main() {
}
private void init(boolean fullscreen) {
try {
Display.setTitle("Test LWJGL");
Display.setFullscreen(fullscreen);
Display.setDisplayMode(new DisplayMode(480, 600));
Display.setVSyncEnabled(true);
Display.create();
texture = getTexture("texture");
GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_TEXTURE_2D);
} catch (LWJGLException e) {
e.printStackTrace();
}
}
private Texture getTexture(String key) {
try {
return TextureLoader.getTexture("PNG", new FileInputStream(
new File("res/img/" + key + ".png")));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public void start() {
init(false);
run();
}
public void run() {
while (!finished) {
Display.update();
if (Display.isCloseRequested()) {
finished = true;
} else {
tick();
render();
}
}
}
private void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
draw();
Display.update();
Display.sync(60);
}
private void draw() {
texture.bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(x, y);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(x + texture.getTextureWidth(), y);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(x + texture.getTextureWidth(),
y + texture.getTextureHeight());
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(x, y + texture.getTextureHeight());
GL11.glEnd();
}
private void tick() {
}
public static void main(String args[]) {
Main main = new Main();
main.start();
}
}