Solution TD N°5

Polygone avec éclairage :

   public void display( GLAutoDrawable drawable ) {
   
      final GL2 gl = drawable.getGL().getGL2(); 
      gl.glColor3f(1f,0f,0f); //applying red
      
      // Clear The Screen And The Depth Buffer 
      gl.glClear( GL2.GL_COLOR_BUFFER_BIT |  
      GL2.GL_DEPTH_BUFFER_BIT );   
      gl.glLoadIdentity();       // Reset The View    
      gl.glRotatef( rpoly, 0.0f, 1.0f, 0.0f ); 
              
      gl.glBegin( GL2.GL_POLYGON ); 
      
      gl.glVertex3f( 0f,0.5f,0f ); 
      gl.glVertex3f( -0.5f,0.2f,0f ); 
      gl.glVertex3f( -0.5f,-0.2f,0f ); 
      gl.glVertex3f( 0f,-0.5f,0f ); 
      gl.glVertex3f( 0f,0.5f,0f ); 
      gl.glVertex3f( 0.5f,0.2f,0f ); 
      gl.glVertex3f( 0.5f,-0.2f,0f ); 
      gl.glVertex3f( 0f,-0.5f,0f ); 
      
      gl.glEnd(); 
              
      gl.glFlush(); 
      
      rpoly += 0.2f;  //assigning the angle 
      
      gl.glEnable( GL2.GL_LIGHTING );  
      gl.glEnable( GL2.GL_LIGHT0 );  
      gl.glEnable( GL2.GL_NORMALIZE );  
 
      // weak RED ambient 
      float[] ambientLight = { 0.1f, 0.f, 0.f,0f };  
      gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambient-Light, 0);  
 
      // multicolor diffuse 
      float[] diffuseLight = { 1f,2f,1f,0f };  
      gl.glLightfv( GL2.GL_LIGHT0, GL2.GL_DIFFUSE, diffuse-Light, 0 ); 
   }  

 

Résultat visuel :

Modifié le: Thursday 16 April 2020, 14:59