Solution TD N°2

Polygone rouge :

public void display( GLAutoDrawable drawable ) { 
   
      final GL2 gl = drawable.getGL().getGL2(); 
      gl.glColor3f( 1f,0f,0f ); //applying red  
  
      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(); 
   }

Triangle à 3 couleurs différentes aux sommets :

public void display( GLAutoDrawable drawable ) { 
   
      final GL2 gl = drawable.getGL().getGL2(); 
      gl.glBegin( GL2.GL_TRIANGLES );  
      
      // Drawing Using Triangles 
    
      gl.glColor3f( 1.0f, 0.0f, 0.0f );   // Red 
      gl.glVertex3f( 0.5f,0.7f,0.0f );    // Top 
              
      gl.glColor3f( 0.0f,1.0f,0.0f );     // green 
      gl.glVertex3f( -0.2f,-0.50f,0.0f ); // Bottom Left 
              
      gl.glColor3f( 0.0f,0.0f,1.0f );     // blue 
      gl.glVertex3f( 0.5f,-0.5f,0.0f );   // Bottom Right 
              
      gl.glEnd();         
   } 

Résultats visuels :

Last modified: Thursday, 16 April 2020, 2:36 PM