Hallo liebe User,
befasse mich gerade mit LWJGL und wollte einen drehenden 3D Würfel zeichnen doch alles was ich zu sehen bekomme sind komische Linien die größer und kleiner werden. Wenn ich den Würfel ohne Rotation anzeige dann sehe ich halt einen 2D Würfel :shock:! Bitte um Hilfe der Code:
befasse mich gerade mit LWJGL und wollte einen drehenden 3D Würfel zeichnen doch alles was ich zu sehen bekomme sind komische Linien die größer und kleiner werden. Wenn ich den Würfel ohne Rotation anzeige dann sehe ich halt einen 2D Würfel :shock:! Bitte um Hilfe der Code:
Java:
package org.cookiesoft.display;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.openal.AL;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
public class Game {
public static int fps = 60;
public static int DisplayWidth = 800;
public static int DisplayHeight = 500;
public static String DisplayTitle = "Game";
private static float CubeRot = 0;
public static void main(String[] args) {
Game.createDisplay();
Game.init();
}
public static void init(){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, Display.getDisplayMode().getWidth(), 0.0, Display.getDisplayMode().getHeight(), -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
while(!(Display.isCloseRequested())){
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){
glViewport(10, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
}
paint();
Display.update();
Display.sync(60);
}
Display.destroy();
}
public static void createDisplay(){
try {
Display.setDisplayMode(new DisplayMode(DisplayWidth, DisplayHeight));
Display.setTitle(DisplayTitle);
Display.create();
} catch (LWJGLException e) {
System.err.println("Display can't create!");
}
}
public static void paint(){
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();
glTranslatef(0.0f, 0.0f,0.0f);
GL11.glRotatef(CubeRot,0.0f,1.0f,0.0f); // Rotate The cube around the Y axis
GL11.glRotatef(CubeRot,1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
//Front
glColor3f(1.0f,0.5f,0.0f);
glVertex3i(100, 100, 0);
glVertex3i(200, 100, 0);
glVertex3i(200, 200, 0);
glVertex3i(100, 200, 0);
//Back
glColor3f(0.0f,0.5f,0.0f);
glVertex3i(100, 100, 100);
glVertex3i(200, 100, 100);
glVertex3i(200, 200, 100);
glVertex3i(100, 200, 100);
//Left
glColor3f(0.0f,0.5f,0.0f);
glVertex3i(100, 100, 100);
glVertex3i(100, 100, 200);
glVertex3i(100, 200, 200);
glVertex3i(100, 200, 100);
//Right
glColor3f(0.0f,0.5f,0.0f);
glVertex3i(200, 100, 100);
glVertex3i(200, 100, 200);
glVertex3i(200, 200, 200);
glVertex3i(200, 200, 100);
//Down
glColor3f(0.0f,0.5f,0.0f);
glVertex3i(100, 100, 100);
glVertex3i(100, 100, 200);
glVertex3i(200, 100, 200);
glVertex3i(200, 100, 100);
//Up
glColor3f(0.0f,0.5f,0.0f);
glVertex3i(100, 200, 100);
glVertex3i(100, 200, 200);
glVertex3i(200, 200, 200);
glVertex3i(200, 200, 100);
glEnd();
CubeRot += 0.1f;
}
}