T
Turakar
Gast
Hallo,
ich hab mal angefangen in lwjgl zu arbeiten, bin aber (wie so oft) auf einen fehler gestoßen. Der Würfel wird nicht weit weg gerendert, sondern sehr nah dran. Hat wer ne Idee was ich falsch mache?
Wahrscheinlich hab ich irgendwo nene "++" vergessen oder so????:L???:L???:L
ich hab mal angefangen in lwjgl zu arbeiten, bin aber (wie so oft) auf einen fehler gestoßen. Der Würfel wird nicht weit weg gerendert, sondern sehr nah dran. Hat wer ne Idee was ich falsch mache?
Java:
package bin.main;
import static org.lwjgl.opengl.GL11.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.util.glu.GLU;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class Main
{
final static int WINDOW_WIDTH = 500;
final static int WINDOW_HEIGHT = 500;
public Main()
{
try
{
Display.setDisplayMode(new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT));
Display.create();
}
catch (LWJGLException e)
{
e.printStackTrace();
Main.exit(1);
}
Display.setTitle("LWJGL TEST");
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0f);
glEnable(GL_CULL_FACE);
//glDepthMask(true);
glEnable(GL_TEXTURE_2D);
glTranslatef(0.0f, 0.0f, -500.0f);
//glRotatef(45, 1, 0, 0);
//glRotatef(45, 0, 1, 0);
GLU.gluPerspective(45.0f,WINDOW_WIDTH/WINDOW_HEIGHT,1.0f,500.0f);
Texture texture;
try
{
texture = TextureLoader.getTexture("PNG", new FileInputStream(new File("Crate.png")));
}
catch (FileNotFoundException e)
{
e.printStackTrace();
Display.destroy();
Main.exit(1);
}
catch (IOException e)
{
e.printStackTrace();
Main.exit(1);
}
while (!Display.isCloseRequested())
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
// Back Face
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
// Top Face
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
// Bottom Face
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
// Right face
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
// Left Face
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glEnd();
glDepthMask(true);
glFlush();
pollInputs();
Display.update();
}
Main.exit(0);
}
public static void exit(int code)
{
Display.destroy();
System.exit(code);
}
private void pollInputs()
{
while(Keyboard.next())
{
if(Keyboard.getEventKeyState())
{
System.out.println("Key " + Keyboard.getEventCharacter() + " is pressed!");
}
else
{
System.out.println("Key " + Keyboard.getEventCharacter() + " is released!");
}
}
}
/**Where the story begins... :D **/
public static void main(String[] args)
{
new Main();
}
}
Wahrscheinlich hab ich irgendwo nene "++" vergessen oder so????:L???:L???:L