title: Advice needed for 3D objects using the Lightweight Java Game Library (LWJGL)
body: <p>I have spent about 2 Days trying to find out how to make 3d objects using lwjgl, and have found nothing. I can easily render 2d objects, and when I tried to render 3d objects, either the program crashed, or a black screen was opened, right now, I'm using Eclipse, and I'm running it in that environment (I don't know if that's the problem). If someone could point me towards a good tutorial, or just give me an explanation of what I'm doing wrong, that would be appreciated. Here's my code:</p>
  
  <pre><code>    import org.lwjgl.LWJGLException;
      import org.lwjgl.opengl.Display;
      import org.lwjgl.opengl.DisplayMode;
      import org.lwjgl.opengl.GL11;
  
      public class Objects {
          public static void main(String[] args) {
              Objects objects = new Objects();
              objects.start();
          }
  
          public void start() {
              try {
                  Display.setDisplayMode(new DisplayMode(800, 600));
                  Display.create();
              } catch (LWJGLException e) {
                  e.printStackTrace();
                  System.exit(0);
              }
  
              initGL();
  
              while(!Display.isCloseRequested) {
                  Cube();
  
                  Display.update();
              }
  
              Display.destroy();
          }
  
          public void initGL() {
              GL11.glMatrixMode(GL11.GL_PROJECTION);
              GL11.glLoadIdentity();
              GL11.glOrtho(0, 800, 600, 0, 1, -1);
              GL11.glMatrixMode(GL11.GL_MODELVIEW);
  
              return;
          }
  
          public void cube() {
              GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
  
              //front face
  
              GL11.glColor3d(0.0, 1.0, 1.0);
              GL11.glVertex3d(1.0, 1.0, -1.0);
              GL11.glVertex3d(-1.0, 1.0, -1.0);
              GL11.glVertex3d(-1.0, -1.0, -1.0);
              GL11.glVertex3d(1.0, -1.0, -1.0);
  
              //side face
  
              GL11.glColor3d(1.0, 0.0, 0.0);
              GL11.glVertex3d(1.0, 1.0, -1.0);
              GL11.glVertex3d(1.0, 1.0, -3.0);
              GL11.glVertex3d(1.0, -1.0, -3.0);
              GL11.glVertex3d(1.0, -1.0, -1.0);
  
              ...(I kept going like this for the rest of the faces)
  
               return;
           }
  </code></pre>
  
  <p>***************EDIT***************</p>
  
  <p>I have read both of your answers, and have made a java lwjgl code based on it, however when I tried to run it in the Eclipse environment, it gave me the error:</p>
  
  <pre><code>usage:
  XPMFile &lt;file&gt;
  java.lang.ArrayIndexOutOfBoundsException: 0
  at org.lwjgl.util.XPMFile.main(XPMFile.java:260)
  </code></pre>
  
  <p>So, once again here's my code:</p>
  
  <pre><code>    package testing;
  
      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 CubeRender {
          public static void main(String[] args) {
              CubeRender cube = new CubeRender();
              cube.start();
          }
  
          public void start() {
              try {
                  Display.setDisplayMode(new DisplayMode(800, 600));
                  Display.create();
              } catch(LWJGLException e) {
                  e.printStackTrace();
                  System.exit(0);
              }
  
              initGL();
  
              while(!Display.isCloseRequested()) {
                  renderCube();
  
                  Display.update();
              }
  
              Display.destroy();
          }
  
          public void initGL() {
              GL11.glMatrixMode(GL11.GL_PROJECTION);
  
              GL11.glLoadIdentity();
  
              GLU.gluPerspective(45, 100, 1, 100);
              GL11.glEnable(GL11.GL_DEPTH_TEST);
              GL11.glDepthFunc(GL11.GL_LEQUAL);
  
              GL11.glMatrixMode(GL11.GL_MODELVIEW);
          }
  
          public void renderCube() {
              double x = 1;
              double y = 1;
              double z = -1;
  
              //front face
  
              GL11.glBegin(GL11.GL_QUADS);
  
              GL11.glNormal3d(0, 0, 1);
  
              GL11.glColor3d(0.0, 1.0, 1.0);
              GL11.glVertex3d(x, y, z);
              GL11.glVertex3d(x-2, y, z);
              GL11.glVertex3d(x-2, y-2, z);
              GL11.glVertex3d(x, y-2, z);
  
              GL11.glEnd();
  
              //right face
  
              GL11.glBegin(GL11.GL_QUADS);
  
              GL11.glNormal3d(-1, 0, 0);
  
              GL11.glVertex3d(x, y, z);
              GL11.glVertex3d(x, y, z-2);
              GL11.glVertex3d(x, y-2, z-2);
              GL11.glVertex3d(x, y-2, z);
  
              GL11.glEnd();
  
              return;
          }
      }
  </code></pre>
  
  <p>******EDIT 2******
  if you have anything to contribute for the above answer please post answers here:
  <a href="https://stackoverflow.com/questions/7949266/xpmfile-information-needed-for-lwjgl">How to import lwjgl_util</a></p>