miércoles, 24 de octubre de 2012

Piramide Unidad 3

 
 
#include <GL/glut.h>
GLfloat anguloCuboX = 0.0f;
GLfloat anguloCuboY = 0.0f;
GLint ancho=500;
GLint alto=500;
int hazPerspectiva = 0;
 void reshape(int width, int height){   
  glViewport(0, 0, width, height);   
  glMatrixMode(GL_PROJECTION);   
  glLoadIdentity();       
  if(hazPerspectiva)    
   gluPerspective(60.0f, (GLfloat)width/(GLfloat)height, 1.0f, 20.0f);   
  else
      glOrtho(-4,4, -4, 4, -5, 10);   
  glMatrixMode(GL_MODELVIEW);    
  ancho = width;   
  alto = height;
 }


 void Piramide(void){    //------------------Funcion que dibuja la Piramide

//Cara Fontral-------------------------------------------------------------------------
  glShadeModel(GL_SMOOTH);
  glColor3f(1.0f, 0.0f, 0.0f);  
  glBegin(GL_POLYGON);       
  glVertex3f(-1.0f, 0.0f,  1.0f);   
  glVertex3f( 1.0f, 0.0f,  1.0f);   
  glVertex3f( 0.0f,  1.0f,  0.0f);
  glEnd();   



 
//cara trasera--------------------------------------------------------------------------
 glShadeModel(GL_SMOOTH);
 glColor3f(0.0f, 1.0f, 0.0f);
    glBegin(GL_POLYGON);      //cara trasera   
    glVertex3f(-1.0f, 0.0f,  -1.0f);   
    glVertex3f( 1.0f, 0.0f,  -1.0f);   
 glVertex3f( 0.0f,  1.0f,  0.0f);
    glEnd();   


//CARA LATERAL IZQUIERDA----------------------------------------------------------------
 glShadeModel(GL_SMOOTH);
 glColor3f(0.0f, 0.0f, 1.0f);   
    glBegin(GL_POLYGON);         
    glVertex3f(-1.0f, 0.0f,  1.0f);   
    glVertex3f( -1.0f, 0.0f, -1.0f);   
 glVertex3f( 0.0f,  1.0f,  0.0f);   
 glEnd();   

//CARA LATERAL DERECHA--------------------------------------------------------------------
 glShadeModel(GL_SMOOTH);
 glColor3f(1.0f, 1.0f, 0.0f);   
    glBegin(GL_POLYGON);      
 glVertex3f(1.0f, 0.0f,  1.0f);   
    glVertex3f( 1.0f, 0.0f,  -1.0f);   
 glVertex3f( 0.0f,  1.0f,  0.0f);
 glEnd();
 

//CARA ABAJO------------------------------------------------------------------------------------
  
 
 glShadeModel(GL_SMOOTH);
 glColor3f(1.0f, 0.0f, 1.0f);   
 glBegin(GL_QUADS);
 glVertex3f( 1.0f,0.0f, -1.0f);   
 glVertex3f( 1.0f, 0.0f,  1.0f);   
 glVertex3f(-1.0f,0.0f,  1.0f);  
 glVertex3f(-1.0f, 0.0f, -1.0f);   
 glEnd();

 }

 //-----------------------------------------------------------------------------------------------------------------
 void display(){
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    
  glLoadIdentity();    
 
  glRotatef(anguloCuboY, 0.0f, 1.0f, 0.0f); 
 
 
  Piramide();    
 
  glLoadIdentity();    
  glFlush();   
 
 
  glutSwapBuffers();  
 
  anguloCuboX+=0.1f;  
  anguloCuboY+=0.1f;  
 
 }

 void init(){
  glClearColor(0,0,0,0);   
  glEnable(GL_DEPTH_TEST);   
  ancho = 400;   
  alto = 400;
 }
void idle(){  display();  }

 int main(int argc, char **argv){   
 
  glutInit(&argc, argv);   
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);   
  glutInitWindowPosition(100, 100);   
  glutInitWindowSize(ancho, alto);  
  glutCreateWindow("Giro Piramide");   
  init();   
  glutDisplayFunc(display);   
  glutReshapeFunc(reshape);   
  glutIdleFunc(idle);   
  glutMainLoop();   
  return 0;

 }
 
 


No hay comentarios:

Publicar un comentario