Hey!
Ich versuche grad den Depth-Test in ein paar kleinen Test zum funktionieren zu bringen, aber der mag micht nicht
Was habe ich falsch gemacht ;( Wahrscheinlich einfach irgendwo ein Minus zu viel oder so... Zum starten erstelle ich einfach ein neues Objekt dieser Klasse
Ich versuche grad den Depth-Test in ein paar kleinen Test zum funktionieren zu bringen, aber der mag micht nicht
Java:
//Imports sind uninteressant!
public class Window {
public static final int WIDTH = 1280;
public static final int HEIGHT = 720;
public static final String TITEL = "Minaria";
public Window() {
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.setTitle(TITEL);
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
mainLoop();
}
int dy;
int dx;
int step = 50;
private void mainLoop() {
initGL();
Mouse.setGrabbed(true);
Camera c = new Camera(0, 0, 0);
while (!Display.isCloseRequested()) {
GL11.glClearColor(0, 0, 0, 1);
GL11.glClearDepth(1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();
GLU.gluPerspective(0.1f, 1280.0f / 720.0f, 1, 1000000000f);
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glPushMatrix();
c.lookThrough();
int size = 512;
Random r = new Random(1000);
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
for (int z = 0; z < 10; z++) {
if (r.nextBoolean())
drawCube(x * size, y * size, z * size, size);
}
}
}
c.yaw(Mouse.getDX());
c.pitch(-Mouse.getDY());
if (isKeyDown(KEY_W))
c.walkForward(step);
if (isKeyDown(KEY_S))
c.walkBackwards(step);
if (isKeyDown(KEY_A))
c.strafeLeft(step);
if (isKeyDown(KEY_D))
c.strafeRight(step);
if (isKeyDown(KEY_SPACE))
c.goUp(step);
if (isKeyDown(KEY_LSHIFT))
c.goDown(step);
GL11.glPopMatrix();
Display.update();
Display.sync(30);
}
Display.destroy();
}
float[][][] cube = new float[][][] {
{ { 0, 0, 1 }, { 1, 0, 1 }, { 1, 1, 1 }, { 0, 1, 1 } },
{ { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 }, { 0, 0, 0 } },
{ { 1, 1, 0 }, { 1, 1, 1 }, { 0, 1, 1 }, { 0, 1, 0 } },
{ { 1, 0, 0 }, { 1, 1, 0 }, { 1, 1, 1 }, { 1, 0, 1 } },
{ { 0, 0, 0 }, { 1, 0, 0 }, { 1, 0, 1 }, { 0, 0, 1 } },
{ { 0, 0, 0 }, { 1, 0, 0 }, { 1, 1, 0 }, { 0, 1, 0 } }
};
private void drawCube(int x, int y, int z, int size) {
texture.release();
GL11.glBegin(GL11.GL_QUADS);
GL11.glColor3f(1, 1, 1);
int whereAmI = 0;
for (float[][] f : cube) {
for (float[] g : f) {
if (whereAmI == 0)
GL11.glTexCoord2f(0, 0);
if (whereAmI == 1)
GL11.glTexCoord2f(1, 0);
if (whereAmI == 2)
GL11.glTexCoord2f(1, 1);
if (whereAmI == 3)
GL11.glTexCoord2f(0, 1);
whereAmI++;
GL11.glColor3d(g[0], g[1], g[2]);
GL11.glVertex3f(x + g[0] * size, y + g[1] * size, z + g[2] * size);
}
whereAmI = 0;
}
GL11.glEnd();
}
Texture texture;
private void loadTexture() {
try {
texture = TextureLoader.getTexture("JPEG", new FileInputStream(new File(System.getProperty("user.home").toString() + "/...minaria/ressources/test.jpeg")));
} catch (FileNotFoundException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
}
private void initGL() {
GL11.glViewport(0, 0, WIDTH, HEIGHT);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 1280, 0, 720, 1, 1000000000);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(true);
GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glDepthRange(0.0f, 1.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_TEXTURE_2D);
loadTexture();
}
}
Zuletzt bearbeitet: