title: How do I use a perspective projection matrix?
body: <p>I wrote this program, but I want the square to change size as it moves further away.</p>
  
  <pre><code>package com.ncom.src;
  
  import org.lwjgl.LWJGLException;
  import org.lwjgl.opengl.Display;
  import org.lwjgl.opengl.DisplayMode;
  import org.lwjgl.opengl.GL11;
  import static org.lwjgl.util.glu.GLU.*;
  
  import static org.lwjgl.opengl.GL11.*;
  
  public class Main {
      public void start() {
          float y = 0;
          try {
              Display.setDisplayMode(new DisplayMode(800,600));
              Display.create();
          } catch (LWJGLException e) {
              e.printStackTrace();
              System.exit(0);
          }
          while (!Display.isCloseRequested()) {
              glMatrixMode(GL_PROJECTION);
              glLoadIdentity();
              glOrtho(0, 800, 600, 0, 500000000, -500000000);
              glMatrixMode(GL_MODELVIEW);
              glClear(GL_COLOR_BUFFER_BIT);
              glBegin(GL_QUADS);
                  glVertex3f(350, 250, y);
                  glVertex3f(350, 270, y);
                  glVertex3f(370, 270, y);
                  glVertex3f(370, 250, y);
              glEnd();
              Display.update();
              y -= 20;
          }
  
          Display.destroy();
          System.exit(0);
      }
      public static void main(String[] argv) {
          Main quadExample = new Main();
          quadExample.start();
      }
   }
  </code></pre>