Пример #1
0
void display()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glLoadIdentity();
  //gluLookAt(0, 0, 20 + zoomValue, 0, 0, 0, 0, 1, 0);
  gluLookAt(0, 0, 0, lx, ly, lz, 0, 1, 0);

  // multiply current matrix with arcball matrix
  glMultMatrixf( arcball.get() );

  GLUquadric *sphere = gluNewQuadric(); 
  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

  draw_sun();
  //draw_coordinate_system(5.0f);
  RenderScene();  

  glutPostRedisplay();
   
  glutSwapBuffers();
}
Пример #2
0
void drawscene(void){					//draw the whole scene
	GLint viewport[4];
	glGetIntegerv( GL_VIEWPORT, viewport );
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	gluPerspective( 45, double(viewport[2])/viewport[3], 0.1, 1000 );
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt( 100,25,200,0,0,lookz, 0,1,0 );					//the PRP is at (100,25,200), looking at (0,0,lookz), VUP is (0,1,0)
	glMultMatrixf( gsrc_getmo() ); 
	
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB |  GLUT_DEPTH);	//initialize the display mode, double buffer
	glClear(GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);								//enable depth test
	glClear(GL_COLOR_BUFFER_BIT);

	//Add a ambient light
	GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f};	 //the ambient Color is (0.2, 0.2, 0.2)
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);

	//Add directed light
	GLfloat lightColor1[] = {0.3f, 0.3f, 0.3f, 1.0f};	//Color (0.5, 0.2, 0.2)
	GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f};	//the light comes from the direction (-1, 0.5, 0.5)
	glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);
	
	//Add a point light source 
	GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5)
	GLfloat lightPos0[] = {-20.0f, 50.0f, 70.0f, 1.0f}; //Positioned at (-20,50,70)
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);

	////////draw the cube used for the background/////////////////////////////////////////
	glPushMatrix ( );
	glTranslatef(100,150,100);
	CreateBox();
	glPopMatrix ( );
	//////////////////////////////////////////////////////////////////

	glPushMatrix();	
	glTranslatef(-20.0f,50.0f,70.0f);
	draw_sun();										//draw a sun positioned at the point light source
	glPopMatrix ();

	GLfloat M[16]= {	1, 0, 0, 0,
						0, 1, 0, -1/(50-0.1),
						0, 0, 1, 0,
						0, 0, 0, 0 };				//perspective projection

	draw_object();									//draw the whole object

	/////////////////draw the shadow///////////////////////////
	//glPushMatrix();
	glMatrixMode(GL_MODELVIEW);
	glTranslatef(-20,50,70);						//M wc<-s
	glMultMatrixf(M);								//perspective project
	glTranslatef(20,-50,-70);						//M s<-wc
	glColor4f(0.3f,0.3f,0.3f,0.2f);					//the color of the shadow

	draw_shadow();									//draw the shadows

	glutSwapBuffers();								//swap buffers to display
	
	glFlush();
	
}