Hello All!
I am currently trying to learn opengl 3d rendering. I am using LWJGL as my engine. But I have got this problem. I follow tutorials from all over the internet, but when I run it in Eclipse, I just get a black screen:
This is the source code:
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import static org.lwjgl.util.glu.GLU.*;
public class Main {
public static void main(String args[]) {
Main game = new Main();
game.run();
}
private void run() {
try {
Display.setDisplayMode(new DisplayMode(500, 400));
Display.setTitle("Hello World!");
Display.create();
} catch (LWJGLException ex) {
ex.printStackTrace();
System.exit(0);
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,((float)500)/((float)400),0.1f,100.0f);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
while (!Display.isCloseRequested()) {
render();
Display.update();
Display.sync(60);
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
System.exit(0);
}
}
}
public static void render() {
glPushMatrix();
glColor3f(0.0f, 0.5f, 0.0f);
glBegin(GL_QUADS);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glEnd();
glPopMatrix();
}
}
Please Help! If you have any more questions, then ask!