Hey!
Ich wolle (einfach aus langeweile...
) mich mal mit LWJgL bzw. OpenGL auseinander setzen. Ich habe es auch soweit geschafft, ein Würfel auf den Bildschirm zu zaubern. Das Problem: bestimmte Seiten wirken sehr merkwürdig (sind transparent, aber auch nicht - ist sehr schwer zu erklären...), und es wirkt so, als wenn ab einem bestimmten Abstand die Sachen einfach verschwinden,, also Stücke fehlen. Ich habe im Internet nach allen möglichen Methoden gesucht,das zu beheben (vor allem das mit dem transparenten Seiten), und bin dann auf "Depth ..." gestoßen (Keine Ahnung wie es vollständig heißt, jedenfalls die Flächen so sortieren, das alles richtig aussieht)- ich habe gefühlte 10000 Methoden ausprobiert, aber gebracht hat es nichts... Hat jemand eine Idee, woran es liegen könnte??? Da wo "Uninteressante Imports" steht, habe ich einfach alle "org.lwjgl.opengl.GLxx.*" static importiert, damit ich mich nicht um die versionsnummer kümmern muss
Also anstelle von GL11.glVertex3d (oder so) nur glVertex3d - find ich übersichtlicher
Bildchen sind im Moment ein bisschen schwierig, ich bin hier eigentlich im Urlaub 
MFG, me
Ich wolle (einfach aus langeweile...
Java:
Uninteressante Imports
public class MainDisplay {
public static final int width = 1280;
public static final int height = 720;
public static final String title = "Game";
public static void main(String... args) {
MainDisplay md = new MainDisplay();
md.start();
}
public MainDisplay() {
try {
Display.setDisplayMode(new DisplayMode(width, height));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 1280, 0, 720, 100, -100);
glMatrixMode(GL_MODELVIEW);
}
float mouseSens = 1.0f;
float rotatedX;
float rotatedY;
public void start() {
while (!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
for (int i = 0; i < Mouse.getButtonCount(); i++) {
if (Mouse.isButtonDown(i)) {
rotatedY += Mouse.getDX() * mouseSens;
rotatedX += -Mouse.getDY() * mouseSens;
}
}
glTranslated(640, 300, -100);
glRotatef(rotatedX, 1, 0, 0);
glRotatef(rotatedY, 0, 1, 0);
drawCube(0, 0, 0, 50);
drawCube(-60, 0, 0, 30);
Display.update();
Display.sync(30);
}
Display.destroy();
}
float[][][] cube = new float[][][] { //Array for cube
{ { 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) { //Draws the Cube
glColor3d(1.0d, 1.0d, 1.0d);
glBegin(GL_QUADS);
for (float[][] f : cube) {
for (float[] g : f) {
glColor3d(g[0], g[1], g[2]);
glVertex3f(x + g[0] * size, y + g[1] * size, z + g[2] * size);
}
}
glEnd();
}
}
Zuletzt bearbeitet: