Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ig.cpp

Go to the documentation of this file.
00001 /* $Id: ig04.cpp,v 1.1 2001/05/27 15:25:28 formella Exp $ */
00002 
00003 /*
00004  *  Copyright (C) 2001, Dr. Arno Formella
00005  *                      Universidad de Vigo
00006  *                      Departamento de Inform'atica
00007  */
00008 
00009 #include <GL/glut.h>
00010 
00011 #include "IGPolygon.h"
00012 
00013 list<IGPolygon> polygonList;
00014 
00015 static void Display(
00016 ) {
00017   glClearColor(1.0,0.0,0.0,0.0);  // todo en rojo
00018   glClear(GL_COLOR_BUFFER_BIT);   // borramos el buffer
00019   IGPolygon p;
00020   forall(p,polygonList) p.Draw();
00021   glFlush();
00022   glutSwapBuffers();
00023 }
00024 
00025 static void KeyPress(
00026   unsigned char key_code,
00027   int xpos,
00028   int ypos
00029 ) {
00030   switch(key_code) {
00031     case 'X':
00032       glMatrixMode(GL_PROJECTION);
00033       glRotated(-5.0,1.0,0.0,0.0);
00034       glMatrixMode(GL_MODELVIEW);
00035       break;
00036     case 'x':
00037       glMatrixMode(GL_PROJECTION);
00038       glRotated( 5.0,1.0,0.0,0.0);
00039       glMatrixMode(GL_MODELVIEW);
00040       break;
00041     case 'Y':
00042       glMatrixMode(GL_PROJECTION);
00043       glRotated(-5.0,0.0,1.0,0.0);
00044       glMatrixMode(GL_MODELVIEW);
00045       break;
00046     case 'y':
00047       glMatrixMode(GL_PROJECTION);
00048       glRotated( 5.0,0.0,1.0,0.0);
00049       glMatrixMode(GL_MODELVIEW);
00050       break;
00051     case 'Z':
00052       glMatrixMode(GL_PROJECTION);
00053       glRotated(-5.0,0.0,0.0,1.0);
00054       glMatrixMode(GL_MODELVIEW);
00055       break;
00056     case 'z':
00057       glMatrixMode(GL_PROJECTION);
00058       glRotated( 5.0,0.0,0.0,1.0);
00059       glMatrixMode(GL_MODELVIEW);
00060       break;
00061     case 'c':
00062       // activamos/desactivamos la eliminaci'on
00063       if(glIsEnabled(GL_CULL_FACE)==GL_TRUE) glDisable(GL_CULL_FACE);
00064       else glEnable(GL_CULL_FACE);
00065       break;
00066     case 'w': {
00067       GLint w;
00068       glGetIntegerv(GL_FRONT_FACE,&w);
00069       if(w==GL_CCW) glFrontFace(GL_CW);
00070       else glFrontFace(GL_CCW);
00071       break;
00072     }
00073     case 'F': glCullFace(GL_FRONT); break;    // elimina caras amversas
00074     case 'B': glCullFace(GL_BACK); break;     // elimina caras reversas
00075     case 'A': glCullFace(GL_FRONT_AND_BACK); break;  // elimina ambos
00076     case 'q':
00077     case 'Q':
00078        glFinish();
00079        exit(0);
00080        break;
00081   }
00082   glutPostRedisplay();
00083 }
00084 
00085 static void ReadFile(
00086 ) {
00087   ifstream in;
00088   in.open("cube.dat");
00089   if(!in) return;
00090   int       N,t;
00091   IGPolygon p;
00092   in >> N;
00093   while(--N>=0) {
00094     in >> t;
00095     if(t==0) {
00096       in >> p;
00097       if(p.IsOkForOpenGL()) polygonList.append(p);
00098     }
00099     else break;
00100   }
00101   in.close();
00102   cout << polygonList.size() << " simple and convex polygons read." << endl;
00103 }
00104 
00105 int main(
00106   int   argc,                     // n'umero de par'ametros
00107   char *argv[]                    // los par'ametros
00108 ) {
00109   glutInit(&argc,argv);           // inicializamos OpenGL
00110   glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA); // inicializamos los buffers
00111   glutInitWindowPosition(20,20);  // donde se presenta la ventana
00112   glutInitWindowSize(400,400);    // el tama~no en pixeles de la ventana
00113   glutCreateWindow("la ventana"); // creamos la ventana
00114   glOrtho(-100.0,100.0,-100.0,100.0,-100.0,100.0);
00115   glutDisplayFunc(Display);       // registramos la funci'on para dibujar
00116   glutKeyboardFunc(KeyPress);     // registramos la funci'on para el teclado
00117   ReadFile();
00118   glutMainLoop();                 // pasamos el control a OpenGL
00119 }
00120 

Generated at Wed May 30 11:16:28 2001 for Computer Graphics Course by doxygen1.1.5 written by Dimitri van Heesch, © 1997-2000