Hallo, ich habe ein Problem. Ich schaue mir zurzeit ein Java Tower Defense Tutorial an. In der Folge (
) wird eine Textur in das Spiel geladen die Textur soll Quadartisch sein aber bei mir ist sie Dreieckig. 
Der Code aus der Klasse Artist:
Aus Tile:
Und aus Boot:
Es würde mich freuen wenn ihr mir helfen könnt danke!

Der Code aus der Klasse Artist:
Java:
package helpers;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glOrtho;
import static org.lwjgl.opengl.GL11.glVertex2f;
import java.io.IOException;
import java.io.InputStream;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.*;
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 Artist {
public static final int WIDTH = 1280, HEIGHT = 960;
public static void BeginSession() {
Display.setTitle("Stone Defense");
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
}
public static void DrawQuad(float x, float y, float width, float height) {
glBegin(GL_QUADS);
glVertex2f(x, y); //Top left corner
glVertex2f(x + width, y); //Top right corner
glVertex2f(x + width, y + height); //Bottom right corner
glVertex2f(x, y + height); //Bottom left corner
glEnd();
}
public static void DrawQuadTex(Texture tex, float x, float y, float width, float height) {
tex.bind();
glTranslatef(x, y, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(width, 0);
glTexCoord2f(1, 1);
glVertex2f(1, 1);
glVertex2f(width, height);
glTexCoord2f(0, 1);
glVertex2f(0, height);
glEnd();
glLoadIdentity();
}
public static Texture LoadTexture(String path, String fileType) {
Texture tex = null;
InputStream in = ResourceLoader.getResourceAsStream(path);
try {
tex = TextureLoader.getTexture(fileType, in);
} catch (IOException e) {
e.printStackTrace();
}
return tex;
}
}
Aus Tile:
Java:
package data;
import org.newdawn.slick.opengl.Texture;
public class Tile {
private float x, y, width, height;
private Texture texture;
public Tile(float x, float y, float width, float height, Texture texture) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}
Java:
package data;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.newdawn.slick.opengl.Texture;
import static org.lwjgl.opengl.GL11.*;
import static helpers.Artist.*;
public class Boot {
public Boot() {
BeginSession();
Texture t = LoadTexture("res/dirt64.png", "PNG");
Texture t2 = LoadTexture("res/Grass_1.png", "PNG");
while(!Display.isCloseRequested()) {
DrawQuadTex(t, 0, 0, 64, 64);
DrawQuadTex(t2, 64, 0, 64, 64);
Display.update();
Display.sync(60);
}
Display.destroy();
}
public static void main(String[] args) {
new Boot();
}
}
Es würde mich freuen wenn ihr mir helfen könnt danke!
Zuletzt bearbeitet von einem Moderator: