// DIBUJO DE UN CUADRITO EN PERSPECTIVA #include <GL/glut.h> void display(void) { glClearColor (0.0, 0.0, 0.0, 0.0); // selecciona el color de borrado -negro- /* borra la pantalla */ glClear (GL_COLOR_BUFFER_BIT); // borra la pantalla glMatrixMode(GL_PROJECTION); glLoadIdentity(); //glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); // Se sustituye por gluPerspective glMatrixMode(GL_MODELVIEW); gluPerspective(60,1,1,100); // (angulo, ancho, alto, distancia) glTranslatef(0,0,-2); // Alejamos el cuadro del observador 2 unidades en Z glBegin(GL_QUADS); glColor3f(1,0,0); glVertex3f(-.5,.5,-.5); glColor3f(0,1,0); glVertex3f(-.5,-.5,.5); glColor3f(0,0,1); glVertex3f(.5,-.5,.5); glColor3f(0,1,1); glVertex3f(.5,.5,-.5); glEnd(); glFlush (); // Vacia el buffer de dibujo sleep(3); exit(0); } void inicializa (void) { /* inicializa los valores de la vista */ glLoadIdentity(); } int main(int argc, char** argv) { glutInit(&argc, argv); // Inicializa la libreria auxiliar GLUT glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Inicializa el modo de visualizacion glutInitWindowSize (500, 500); // Indica el tamano de la ventana (ancho,alto) glutInitWindowPosition (20, 20); // Indica la posiciOn inicial (xmin,ymin) glutCreateWindow ("Triangulo"); // Abre la ventana con el tItulo indicado //inicializa (); // Inicializar valores glutDisplayFunc(display); // Indica cual es la funciOn de dibujo glutMainLoop(); // Comienza el bucle de dibujo y proceso de eventos. return 0; }