Hallo
ich möchte mit lwjgl Texturen laden und auch benutzen hierzu habe ich dieses Tutorial gemacht:
und verwende auch die Bibliothek, die dort erwähnt wird(slick-util). Doch es wird nur eine weiße Fläche angezeigt.
Es ist nur ein kleiner Test, hier der Quellcode:
package test.lwjgl;
import java.awt.Canvas;
import java.awt.Dimension;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JFrame;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import static org.lwjgl.opengl.GL11.*;
public class Main {
Texture texture;
JFrame f;
int w, h;
public static void main(String[] args){
new Main();
}
public Main(){
f = new JFrame("LWJGL Test");
f.setPreferredSize(new Dimension(700, 550));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocation(900, 50);
f.pack();
Canvas canvas = new Canvas();
f.add(canvas);
try{
f.setVisible(true);
Display.create();
Display.setParent(canvas);
}
catch (LWJGLException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
try {
texture = TextureLoader.getTexture("PNG",
Main.class.getResource("../../textur.png").openStream());
} catch (FileNotFoundException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
w = Display.getWidth();
h = Display.getHeight();
while(!Display.isCloseRequested()){
glClear(GL11.GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, h, 0, 0, 1000);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBindTexture(GL_TEXTURE_2D, texture.getTextureID());
glBegin(GL_TRIANGLES);
glTexCoord2f(1, 0);
glVertex2i(450, 10);
glTexCoord2f(0, 0);
glVertex2i(10, 10);
glTexCoord2f(0, 1);
glVertex2i(10, 450);
glTexCoord2f(0, 1);
glVertex2i(10, 450);
glTexCoord2f(1, 1);
glVertex2i(450, 450);
glTexCoord2f(1, 0);
glVertex2i(450, 10);
glEnd();
Display.update();
}
}
}