예제 #1
0
파일: main.c 프로젝트: kmels/opengl-basics
void display(void)
{
  glClear (GL_COLOR_BUFFER_BIT);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  //glColor3f (1.0, 1.0, 1.0);  
  glLoadIdentity ();             /* clear the matrix */
  gluLookAt (eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  /* viewing transformation  */ 
  
  
  //glTranslatef(0,0,0);

  //rotate? 
  //printf("%f, %f, %f\n",translate_x,translate_y,translate_z);
  glTranslatef(translate_x,translate_y,translate_z);
  glScalef (scale_x, scale_y, scale_z);      /* modeling transformation */ 
  
  glRotatef(rotate_angle_y, 0.0f, 1.0f, 0.0f);
  glRotatef(rotate_angle_x, 1.0f, 0.0f, 0.0f);
  glRotatef(rotate_angle_z, 0.0f, 0.0f, 1.0f);

  //glutWireSphere(1.0f, 25, 25);
  //houseAngle += 0.05f;
  
  if (!figure)
    drawHouse();
  else
    drawTree();
       
  glFlush ();
  glutSwapBuffers();
}
예제 #2
0
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	gluLookAt(x, 1.0f, z,
		x + lx, 1.0f, z + lz,
		0.0f, 1.0f, 0.0f);

	glColor3f(0.35f, 0.54f, 0.2f);
	glBegin(GL_QUADS);
		glVertex3f(-100.0f, 0.0f, -100.0f);
		glVertex3f(-100.0f, 0.0f, 100.0f);
		glVertex3f(100.0f, 0.0f, 100.0f);
		glVertex3f(100.0f, 0.0f, -100.0f);
	glEnd();
	
	glColor3f(0.1f, 0.1f, 0.1f);
	glBegin(GL_QUADS);
		glVertex3f(6.0f, 0.01f, -100.0f);
		glVertex3f(6.0f, 0.01f, 100.0f);
		glVertex3f(8.0f, 0.01f, 100.0f);
		glVertex3f(8.0f, 0.01f, -100.0f);
	glEnd();


	for (int i = -5; i < 5; i++)
	for (int j = -5; j < 5; j++) {
		glPushMatrix();
		glTranslatef(i*20.0, 0, j * 20.0);
		drawHouse();
		glPopMatrix();
	}
	glutSwapBuffers();
}
예제 #3
0
/* OpenGL calls this routine to display the scene
*/ 
void display(){

	//Eye position
	double Ex = -2*dim*Sin(th)*Cos(ph);
	double Ey = +2*dim        *Sin(ph);
	double Ez = +2*dim*Cos(th)*Cos(ph);
	
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	
	//Set perspective
	glLoadIdentity();
	gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
	
	//Let there be light
	if(light)
		sun();
	 else{
		glDisable(GL_LIGHTING);
	}
	//Texture stuff
	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

	shininess = 10;
	float green[]   = {0.0, 0.01*diffuse, 0.0,1.0};
	glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white2);
    glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black2);
	glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,green);
	tree(16.5, 0, 0,    5, 4, 1, texture[3]);
	tree(19, 0, 2,    6, 5, 25, texture[3]);
	tree(19, 0, 0.5,    3, 3, 35, texture[3]);
	tree(-20, 0, -10,   8, 3, 50, texture[3]);
	tree(-3, 0, 5,   6, 5, 1, texture[3]);
	tree(-6, 0, 6,  8 , 3.5, 30, texture[3]);
	
	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
	glBindTexture(GL_TEXTURE_2D,texture[2]);
    //Draw flat plane
    drawflat(0,0,0, 100, 100, 0, .95, 0);   
	
	drawToolBar();
    //  Display parameters
    glWindowPos2i(5,5);
   // Print("Angle=%d,%d  Dim=%.1f Light=%.1f",th,ph,dim);
    //Print("Angle=%d,%d  Dim=%.1f Light=%s",th,ph,dim,light?"On":"Off");
	
	drawHouse(GL_RENDER, -7,0, 0,    0,     3, 5, 3.4,   2,   .85,.8,0,  .9,.9,0, .7,.7,0,   0.9,.8,0, texture[1], texture[5]);
	
	//Render the scene and make it visible
    //ErrCheck("display");
    glFlush();
    glutSwapBuffers();
}
예제 #4
0
void drawPolys(void) {
	myMatrixMode(GL_MODELVIEW);
	myScalef(50.0,50.0);

	drawHouse();

	myPopMatrix();
	myTranslatef(-50.0,0.0);
	myScalef(30.0,30.0);
	
	drawHouse();

	myPopMatrix();
	
	myTranslatef(0.0,-100.0);	
	myScalef(40.0,40.0);

	drawHouse();

	glFlush();
}
예제 #5
0
void rotateHouse() {

    glPushMatrix();
    glTranslatef(380.0, 380.0, 0.0);
    glRotatef(angle, 0.0, 0.0, 1.0);

    drawHouse(angle);

    glTranslatef(-380.0,-380.0, 0.0);
    glLoadIdentity();
    glPopMatrix();

}
void drawOffAxesView( void )
{
    glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   if (projection == PERPECTIVE_PROJECTION)
     glFrustum (-10.0, 10.0, -10.0, 10.0, nearClip, farClip);
   else
     glOrtho (-20.0, 20.0, -20.0, 20.0, nearClip, farClip);

   glViewport ((GLsizei) width/2, (GLsizei) height/2, (GLsizei) width/2, (GLsizei) height/2); 

   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity ();             /* clear the matrix */
           /* viewing transformation  */
   gluLookAt (20.0 + camerax, 20.0 + cameray, 60 + cameraz, 8.0, 8.0, 42.0, 0.0, 1.0, 0.0);
   drawHouse();
   glFlush ();
}
예제 #7
0
void picker(int button, int state, int x, int y){
	x = mousex;
	y = mousey;
	GLuint selectBuf[BUFSIZE];
	GLint hits;
	GLint viewport[4];
	bool newobj = false;
	
	if(button == GLUT_LEFT_BUTTON){
		if(state == GLUT_DOWN){	
		glGetIntegerv(GL_VIEWPORT, viewport);
		
		glSelectBuffer(BUFSIZE, selectBuf); //Array to be used for recording object hits
		(void) glRenderMode(GL_SELECT); 	//Enter Selection Mode
		
		//Initialize the name stack
		glInitNames();  
		glPushName(0);
		//Save current transformation state.
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		
		// Create a 5x5 picking region near cursor location
		gluPickMatrix((GLdouble) mousex, (GLdouble) (viewport[3] - mousey), 5.0,
		5.0, viewport);
		drawHouse(GL_SELECT, -7,0, 0,    0,     3, 5, 3.4,   2,   .85,.8,0,  .9,.9,0, .7,.7,0,   0.9,.8,0, texture[1], texture[5]);
		
		glMatrixMode (GL_PROJECTION);
		glPopMatrix ();
		glFlush ();
		
		hits = glRenderMode (GL_RENDER);
		processHits (hits, selectBuf);
		glutPostRedisplay();
	}
	
	if((state == GLUT_UP)&&(newobj == true)){
		glutWarpPointer(winwidth/2, winheight/2);
	}	
	}
	glutPostRedisplay();
}
예제 #8
0
// Generate the Graphics
void displayFcn(void)
{
	// Clear display window.
	glClear(GL_COLOR_BUFFER_BIT);

	// Draw 3 different rectangles
	drawRectangles();

	// Draw triangles
	drawTriangles();

	// Draw house
	drawHouse();
	
	// Draw square
	drawSquare();

	// Execute
	glFlush();
}
예제 #9
0
파일: xldemo.c 프로젝트: Aye1/RVProject
static void display(void)
{
	placeCamera();
	drawHouse();
	glutSwapBuffers();
}
예제 #10
0
void drawWorld(void)
{
	mvstack.push(model_view);
	drawDesert();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Translate (0, 6 , -30);
	model_view *= RotateY(180);
	drawBench();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Translate (25, 4, -30);
	drawTree();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Scale(.9, .9, .9);
	model_view *= Translate (-25, 4, -30);
	drawTree();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Scale(1, 2, 1);
	model_view *= Translate (25, 4, 30);
	drawTree();
	model_view = mvstack.pop();
	

	//house
	mvstack.push(model_view);
	model_view *= Translate(-40, 10, 0);
	model_view *= RotateY(90);
	drawHouse();
	model_view = mvstack.pop();
	

	//moon
	mvstack.push(model_view);
	set_colour(.9, .9, .8);
	model_view *= Translate (-70, 75, 200);
	model_view *= Scale(30, 30, 30);
	drawSphere();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Translate(160,100, 0);
	model_view *= Scale (150, 200, 250);
	drawStone();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Translate(-160,100, 0);
	model_view *= Scale (150, 200, 250);
	drawStone();
	model_view = mvstack.pop();

	if (TIME >= 7 && TIME < 8)
	{
		mvstack.push(model_view);
		model_view *= Translate (0, 10, -20);
		model_view *= Scale(1.2, 1.6, 1.2);
		model_view *= Translate (0, 66.5- TIME*9.5, -35 + TIME*5);
		model_view *= RotateX((180*7)-TIME*180);
		drawBanana1();
		model_view = mvstack.pop();
	}
	else if (TIME >= 8)
	{
		mvstack.push(model_view);
		model_view *= Translate (0, 0.5, -16.8);
		model_view *= Scale (1.2, 1.6, 1.2);
		model_view *= RotateX(180);
		drawBanana1();
		model_view = mvstack.pop();
	}
}
예제 #11
0
void drawBlock(const BlockInfo& block)
{
  ErrCheck("Before drawBlock"); 
  if(!block.initalized)
  {
    //printf("Not Initialized\n");
    return;
  }
  if(!determineBlockVisability(block))
  {
    double red[3] = {1,0,0}; 
    drawCube(block.location[0], block.location[1], block.location[2],
             block.size[0], block.size[1], block.size[2],
             red , red);
             // double xSize, double ySize, double zSize,
             // double topColor[3], double bottomColor[3]
    //Not visable don't draw
    return;
  }
  glPushMatrix();
  
  srand(block.randomSeed);
  glTranslated(block.location[0] + block.size[0]/2.0 ,
               block.location[1] + block.size[1]/2.0,
               block.location[2] );
  ErrCheck("before drawGround in DrawBlock");
  drawGround(block.size[0], block.size[1], block.size[2]);
  
  for(uint32_t ii = 0; ii < block.trees.size(); ii++)
  {
    
    // For Readibility
    const TreeInfo & thisTree = block.trees[ii];
    const double * location = thisTree.location;
    const double * size = thisTree.size;
    /*double size3d[3] = {size[1]*1.5, size[0]*1.5, size[0]};
    if(!determineVisability(location, size3d, block.location))
    {
      continue;
    }*/ // This Messes With the Shadows
    srand(thisTree.randomSeed);
    drawTree(size[0], size[1], location[0], location[1], location[2]);
  }

  for(uint32_t ii = 0; ii < block.rocks.size(); ii++)
  {
    
    // For Readibility
    const RockInfo & thisRock = block.rocks[ii];
    const double * location = thisRock.location;
    const double * size = thisRock.size;
    srand(thisRock.randomSeed);
    drawRock(location[0],
             location[1],
             location[2],
             size[0],
             size[1],
             size[2],
             thisRock.roughness);
    
  }
  //printf("\\h"); fflush(stdout);
  
  for(uint32_t ii = 0; ii < block.houses.size(); ii++)
  {
    // For Readibility
    const HouseInfo & thisHouse = block.houses[ii];
    const double * location = thisHouse.location;
    const double * size = thisHouse.size;
    srand(thisHouse.randomSeed);
    glPushMatrix();
    glRotated(thisHouse.rotation, 0, 0, 1);
    drawHouse(location[0],
             location[1],
             location[2],
             size[0],
             size[1],
             size[2]);
    glPopMatrix(); 
  }
  //printf("\\"); fflush(stdout);
  
  
  glPopMatrix();
}