/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Novembre 2010 */ /* Une scene OpenGL */ #include #include #include #include #include #include /* Scene dessinee */ void scene(int l) { int i; const GLfloat l_pos[] = { 1.0F,1.0F,-1.0F,1.0F }; const GLfloat c1[4] = { 1.0F,1.0F,1.0F,1.0F }; const GLfloat c2[4] = { 0.1F,0.7F,0.6F,1.0F }; const GLfloat c3[4] = { 1.0F,1.0F,0.0F,1.0F }; if ( l ) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glLightfv(GL_LIGHT0,GL_POSITION,l_pos); glPushMatrix(); glNormal3f(0.0F,1.0F,0.0F); glMaterialfv(GL_FRONT,GL_DIFFUSE,c1); glColor4fv(c1); glBegin(GL_QUADS); for ( i = 0 ; i < 20 ; i++ ) { for ( int j = 0 ; j < 20 ; j++ ) { if ( (i+j)%2 == 1 ) { glVertex3f(i-10.0F,0.0F,j-10.0F); glVertex3f(i-9.0F,0.0F,j-10.0F); glVertex3f(i-9.0F,0.0F,j-9.0F); glVertex3f(i-10.0F,0.0F,j-9.0F); } } } glEnd(); glMaterialfv(GL_FRONT,GL_DIFFUSE,c2); glColor4fv(c2); glBegin(GL_QUADS); for ( i = 0 ; i < 20 ; i++ ) { for ( int j = 0 ; j < 20 ; j++ ) { if ( (i+j)%2 == 0 ) { glVertex3f(i-10.0F,0.0F,j-10.0F); glVertex3f(i-9.0F,0.0F,j-10.0F); glVertex3f(i-9.0F,0.0F,j-9.0F); glVertex3f(i-10.0F,0.0F,j-9.0F); } } } glEnd(); glMaterialfv(GL_FRONT,GL_DIFFUSE,c3); glColor4fv(c3); srand(0); for ( i = 0 ; i < 100 ; i++ ) { float x = -10.0F+((float) (rand()%1000)/50.0F); float z = -10.0F+((float) (rand()%1000)/50.0F); glPushMatrix(); glTranslatef(x,1.0F,z); glRotatef(rand()%360,0.0F,1.0F,0.0F); glScalef(0.1F,2.0F,0.1F); glutSolidCube(1.0); glPopMatrix(); } glPopMatrix(); }