problem with gluLookAt()

Hello everybody

I’m a beginner at jogl and i have a really weird problem with the gluLookAt() fonction.
Here is my code:

  

 public void init(GLDrawable gld) {
   	GL gl = gld.getGL();
		GLU glu = gld.getGLU();
		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		gl.glViewport(0,0,500,300);
		gl.glMatrixMode(GL.GL_PROJECTION);
		gl.glLoadIdentity();
   	glu.gluLookAt(0.0, 0.0, 0.0,   0.0, 0.0, -100.0,    0.0, 1.0, 0.0);
		glu.gluPerspective(45.0f, 800.0f / 600.0f, 1.0f, 500.0f);
		gl.glMatrixMode(GL.GL_MODELVIEW);

   }


   public void display(GLDrawable gld) {
                                           GL gl = gld.getGL();
	
		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
		gl.glLoadIdentity();   

		gl.glTranslatef(0.0f,0.0f,-5.0f);

		gl.glBegin(GL.GL_TRIANGLES);
			gl.glVertex3f( 0.0f, 1.5f, 0.0f);
			gl.glVertex3f(-1.0f, -1.0f, 0.0f);
			gl.glVertex3f( 1.0f, -1.0f, 0.0f);
		gl.glEnd();



    }

That works fine and i see a beautifull white triangle.
But now if I change the value of glu.gluLookAt from (0.0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0) to (0.0, 0.0, 2.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0), my triangle disappear and I don’t understand why!!

So if someone could help me, that would be great!!

BTW sorry for my poor english

Thanks guys

Apply the gluLookAt to the modelview-matrix, not the projection-matrix.

Thanks Riven

That’s work
It seems I always have to call gluLookAt and gluPerspective in the display loop.

If someone need it, here is the good code:


   public void init(GLDrawable glDrawable){
      GL gl = glDrawable.getGL();
      GLU glu = glDrawable.getGLU();
   }

   public void display(GLDrawable glDrawable){
      GL gl=glDrawable.getGL();
      GLU glu=glDrawable.getGLU(); 
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);   
      gl.glLoadIdentity();       
      gl.glMatrixMode(GL.GL_MODELVIEW);
      glu.gluLookAt(0.0,0.0,0.0,  0.0,0.0, -100.0,   0.0, 1.0, 0.0);    
      glu.gluPerspective(45.0,4/(double)3,0.01,300);
      
      gl.glColor3f(1.0f, 0.0f, 0.0f);
		gl.glTranslatef(0.0f,0.0f,-5.0f);

		gl.glBegin(GL.GL_TRIANGLES);
			gl.glVertex3f( 0.0f, 1.5f, 0.0f);
			gl.glVertex3f(-1.0f, -1.0f, 0.0f);
			gl.glVertex3f( 1.0f, -1.0f, 0.0f);
		gl.glEnd();
      gl.glFlush();
   }

gluPerspective should be called when the projection matrix is the active matrix. The following code should do the trick.

 public void init(GLDrawable gld) {
  GL gl = gld.getGL();
  GLU glu = gld.getGLU();
  gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  
  gl.glViewport(0,0,500,300);
  
  // Load the projection matrix
  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glLoadIdentity();
  glu.gluPerspective(45.0f, 800.0f / 600.0f, 1.0f, 500.0f);
  
  // Switch to the modelview matrix from here on
  gl.glMatrixMode(GL.GL_MODELVIEW);
}

public void display(GLDrawable gld) {
  GL gl = gld.getGL();
  
  gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
  gl.glLoadIdentity();   
  glu.gluLookAt(0.0, 0.0, 0.0,   0.0, 0.0, -100.0,    0.0, 1.0, 0.0);

  gl.glTranslatef(0.0f,0.0f,-5.0f);

  gl.glBegin(GL.GL_TRIANGLES);
  gl.glVertex3f( 0.0f, 1.5f, 0.0f);
  gl.glVertex3f(-1.0f, -1.0f, 0.0f);
  gl.glVertex3f( 1.0f, -1.0f, 0.0f);
  gl.glEnd();
}

Yes, that’s better ;D

thank you pepijnve