For some reason images keep looking… strange…
Here is what it looks like:
The actual image I am attempting to display is this:
I am new to OpenGL, so I have no idea why this isn’t working. I am using code similar to what is found on the LWJGL wiki.
My current code is this:
package com.szanto.game;
import static org.lwjgl.opengl.GL11.*;
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
public class Game {
public static void main(String args[]) {
new Game().run();
}
public final int WINDOW_WIDTH = 640, WINDOW_HEIGHT = 480;
private long lastFPSTime;
private int fpsCounter;
private Texture texture;
public void run() {
try {
Display.setDisplayMode(new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT));
Display.setTitle("Game");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
init();
this.lastFPSTime = System.currentTimeMillis();
while (!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT);
renderGame();
Display.update();
Display.sync(60);
calculateFPS();
}
Display.destroy();
}
private void init() {
// Init OpenGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Init Other
try {
this.texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/image.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
private void renderGame() {
this.texture.bind();
glBegin(GL_QUADS);
glTexCoord2f(1, 1);
glVertex2f(30, 30);
glTexCoord2f(1, 0);
glVertex2f(30, 10);
glTexCoord2f(0, 0);
glVertex2f(10, 10);
glTexCoord2f(0, 1);
glVertex2f(10, 30);
glEnd();
}
private void calculateFPS() {
long currentTime = System.currentTimeMillis();
if (currentTime - this.lastFPSTime > 1000) { this.lastFPSTime = currentTime; Display.setTitle("FPS: " + this.fpsCounter); this.fpsCounter = 0; }
this.fpsCounter++;
}
}
I’ll love anyone who can help me fix it