I am having more trouble with rendering 3d objects in java, heres my new problem I have managed to import the needed libraries (gluPerspective, etc.) however when I run my java application in the eclipse environment, it opens a window, then the window stays black. Here is my code:
package test;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
public class Obj3d {
public static void main(String[] args) {
Obj3d obj = new Obj3d();
obj.start();
}
public void start() {
try {
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
init3dGL();
while(!Display.isCloseRequested()) {
clear();
renderCube();
Display.update();
}
Display.destroy();
System.exit(0);
}
public void init3dGL() {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45, 2, -1, 100);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
return;
}
public void renderCube() {
GL11.glBegin(GL11.GL_QUADS);
//front faces
GL11.glNormal3d(0, 0, 1);
GL11.glColor3d(0.0, 1.0, 1.0);
GL11.glVertex3d(5, 5, -5);
GL11.glVertex3d(-5, 5, -5);
GL11.glVertex3d(-5, -5, -5);
GL11.glVertex3d(5, -5, -5);
GL11.glEnd();
return;
}
public void clear() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
}
}
I can’t see my error in the above coding, however I am new to lwjgl 3d programming, so this may be due to my lack of experience. Please be patient, although I am a fast learner. Thanks in advance.
Using a negative near distance is not such a good idea, I think. Try
And this
2in there should actually be your window’s aspect ratio (width / height), in your case1.333 = 800 / 600.