Exemple #1
0
void
display(void)
{
  glClear(GL_COLOR_BUFFER_BIT);
  drawShip(angle);
  drawRocks();
  drawBullets();
  glutSwapBuffers();
}
Exemple #2
0
void kbd(unsigned char key, int x, int y)
{
    if(key == 'q' || key == 'Q')
	{
		exit(0);                                                //quite the program
	}
	//if the "q" key is pressed, quit the program
    
    if(key == 'z')
	{
        // pos -= 1;
        eye[1] -= 2.0;
        //point[1]-=cameraspeed;
        
	}
    if(key == 'x')
	{
        // pos += 1;
        eye[1] +=2.0;
        //point[1]+=cameraspeed;
	}
    
   
    if(key =='l' || key =='L'){
        if (lightOn == true) {
            
            glEnable(GL_LIGHTING); 
            lightOn = false;
        }
        else if(lightOn == false) {
            glDisable(GL_LIGHTING);
            lightOn = true;
        }
    }
    if(key =='1' || key =='1'){
        glPushMatrix();
        glTranslatef(0, 0, 0);
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'G');
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'A');
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'M');
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'E');
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,' ');
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'O');
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'V');
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'E');
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'R');
        glPopMatrix();

    }
    if(key =='2' || key =='2'){
        drawstar();
        drawRocks();
        
    }
    
    
    if (key == 'w' || key == 'W') {
        planepos[1] = planepos[1]+25;
    }
    if (key == 's' || key == 'S') {
        planepos[1] = planepos[1]-25;
    }
    if (key == 'a' || key == 'A') {
        planepos[0] = planepos[0]-25;
       
        
    }
    if (key == 'd' || key == 'D') {
        planepos[0] = planepos[0]+25;
     
        }
    }
Exemple #3
0
void display()
{
    
    /*---------------------------------------Lighting ------------------------------------------------*/       
    typedef struct materialStruct { 
        float ambient[4]; 
        float diffuse[4]; 
        float specular[4]; 
        float emission[4];
        float m_amb[4];
        float m_diff[4]; 
        float m_spec[4] ;
        float shininess; 
    } materialStruct; 
    
    materialStruct redPlastic = { 
        {0.0, 0.0, 0.3, 1.0}, 
        {0.0, 0.4, 0.1, 1.0}, 
        {0.6, 0.6, 0.8, 1.0}, 
        {0.0, 0.0, 0.0, 0.0}, 
        {0.03, 0.22, 0.03, 1.0},
        {0.18, 0.77, 0.1, 1.0},
        {0.10, 0.41, 0.29, 1.0},
        50.0 
    }; 
    
    //  glEnable(GL_LIGHTING); 
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);                   //First light point
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glLightfv(GL_LIGHT0, GL_AMBIENT, redPlastic.ambient);  
    glLightfv(GL_LIGHT0, GL_DIFFUSE, redPlastic.diffuse); 
    glLightfv(GL_LIGHT0, GL_SPECULAR, redPlastic.specular); 
    
    
    
    glEnable(GL_LIGHT1);
    glLightfv(GL_LIGHT1, GL_POSITION, light_pos1);                  //Second Light point
    
    glLightfv(GL_LIGHT1, GL_AMBIENT, redPlastic.ambient);  
    glLightfv(GL_LIGHT1, GL_DIFFUSE, redPlastic.diffuse); 
    glLightfv(GL_LIGHT1, GL_SPECULAR, redPlastic.specular); 
    
    
    typedef struct materialStruct2 { 
        float ambient[4]; 
        float diffuse[4]; 
        float specular[4]; 
        float emission[4];
        float m_amb[4];
        float m_diff[4]; 
        float m_spec[4] ;
        float shininess; 
    } materialStruct2; 
    
    materialStruct2 redPlastic2 = { 
        {0.0, 0.0, 0.3, 1.0}, 
        {0.6, 0.1, 0.1, 1.0}, 
        {0.6, 0.6, 0.8, 1.0}, 
        {0.0, 0.0, 0.0, 0.0}, 
        {0.03, 0.02, 0.33, 1.0},
        {0.78, 0.17, 0.21, 1.0},
        {0.30, 0.11, 0.19, 1.0},
        50.0 
    }; 
    
    
    glEnable(GL_LIGHT2);
    glLightfv(GL_LIGHT2, GL_POSITION, light_pos2);                      //Third Light point
    
    glLightfv(GL_LIGHT2, GL_AMBIENT, redPlastic2.ambient);  
    glLightfv(GL_LIGHT2, GL_DIFFUSE, redPlastic2.diffuse); 
    glLightfv(GL_LIGHT2, GL_SPECULAR, redPlastic2.specular); 

    
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,  redPlastic2.ambient);  
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  redPlastic2.diffuse);  
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  redPlastic2.specular);  
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS,  redPlastic2.shininess);  
    
	//clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity();
    
    
    if (deltaMove)
		computePos(deltaMove);
	if (deltaAngle)
		computeDir(deltaAngle);
    
    //gluLookAt(0, 30, 70, 0, 0, 0, 0, 1, 0);
	gluLookAt(eye[0],eye[1],eye[2],eye[0]+point[0],eye[1],eye[2]+point[2],0,1,0);
    camerapos [0] = eye[0];
    camerapos[2] = eye[2];
	//optionally draw the axis
    //glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, "SPACE Helicopter PRO");
	//drawAxis();
    drawstar();
    	

	drawRocks();
    
    glPushMatrix();
    
    /*---------------------------------------Solar system-----------------------------------------*/

    
    //Venus
    
    glRotatef(ang/200, 0, 1, 1);
    
    glTranslatef(100, 0, 0);
    
    glColor3f(1, 0, 0);
    
    glScalef(2, 2, 2);
    
    drawsphere();
    
    
    
    glPopMatrix();
    
    glPushMatrix();
    
    //Earth
    
    glRotatef(ang/250, 0, 1, 1);
    
    glTranslatef(150, 0, 0);
    
    glColor3f(0, 0, 1);
    
    glScalef(3, 3, 3);
    
    drawsphere();
    
    //moon
    
    glRotatef(ang/80, 0, 1, 1);
    
    glTranslatef(75, 0, 0);
    
    glColor3f(1, .5, .5);
    
    glScalef(1, 1, 1);
    
    drawsphere();
    
    
    
    glPopMatrix();
    
    glPushMatrix();
    
    
    
    //Mars
    
    glRotatef(ang/500, 0, 1, 0);
    
    glTranslatef(200, 0, 0);
    
    glColor3f(1, 0, 0);
    
    glScalef(5, 5, 5);
    
    drawsphere();
    
    
    
    glRotatef(ang/800, 0, 1, 1);
    
    glTranslatef(-500, 0, 0);
    
    glColor3f(.5, .5, .5);
    
    glScalef(3, 3, 3);
    
    drawsphere();
    
    
  
    
    glPopMatrix();
    
    glRotatef(ang/800, 0, 1, 1);
    
    glTranslatef(500, 0, 0);
    
    glColor3f(.5, .5, .5);
    
    glScalef(3, 3, 3);
    
    drawsphere();
    

    
    glRotatef(ang/550, 0, 1, 1);
    
    glTranslatef(-200, 0, 0);
    
    //glRotatef(ang, 0, 1, 0);
    
    glScalef(5, 5, 5);
    
    
    glPopMatrix();
    
    
  
    
    glPopMatrix();
    
    glPopMatrix();
    

    
    /*---------------------------------------Draw Light Source-----------------------------------------*/
    glPushMatrix();
    glTranslated(light_pos2[0], light_pos2[1], light_pos2[2]);
    glColor3f(1, 1, 0);
    
    glPopMatrix();
	
	glutSwapBuffers();
    
    
	glutPostRedisplay();
    
    
    
    
}