Polygon disappears when I increase the z value

I am working on a problem where I am trying to “zoom out.” I have a polygon drawn on the screen, but if I increase the z value to anything more than 1 the polygon disappears. I have included some code which is basically just a slight modification of the first Red Book example.


import javax.swing.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;
import javax.media.opengl.glu.*;

public class Simple implements GLEventListener
{
	private GLU glu = new GLU();

	public static void main(String[] args)
	{
    	       JFrame frame = new JFrame("Simple");
    	       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    	       GLCanvas canvas = new GLCanvas();
    	       canvas.addGLEventListener(new Simple());
    	       frame.add(canvas);

    	       frame.setSize(500, 500);
    	       frame.setVisible(true);
  	}

  	public void init(GLAutoDrawable drawable)
  	{
	       GL gl = drawable.getGL();

		// initialize viewing values
		gl.glMatrixMode(gl.GL_PROJECTION);
		gl.glLoadIdentity();

   		glu.gluLookAt(250, 250, 1,     250, 250, 0,     0, 1, 0);
	}

  	public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}

  	public void display(GLAutoDrawable drawable)
  	{
		GL gl = drawable.getGL();

		// draw white polygon
		gl.glColor3f (1.0f, 1.0f, 1.0f);
		gl.glBegin(gl.GL_POLYGON);
			gl.glVertex3f (0f, 0f, 0f);
			gl.glVertex3f (500f, 0f, 0f);
			gl.glVertex3f (500f, 500f, 0f);
			gl.glVertex3f (0f, 500f, 0f);
		gl.glEnd();

		gl.glFlush ();
  	}

  	public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
}

My guess is that your polygon disappears because it it crosses one of the near or far clipping planes of the projection. You probably need to call glFrustrum() or gluPerspective() somewhere to define these.
Simon

You should not move the polygon when zooming. Just modify the projection matrix properties.