/* Auteur: Nicolas JANEY                        */
/* nicolas.janey@univ-fcomte.fr                 */
/* Fevrier 2017                                */
/* Une scene OpenGL                             */

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>

/* Scene dessinee                               */

void scene(int l) {
  int i;
  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 };
  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);
    float ty = 0.1F+((rand()%100)/50.0F);
    glPushMatrix();
    glTranslatef(x,ty/2.0F,z);
    glRotatef(rand()%360,0.0F,1.0F,0.0F);
    glScalef(0.1F,ty,0.1F);
    glutSolidCube(1.0);
    glPopMatrix(); }
  glPopMatrix();
}
