00001
00002
00003 00004 00005 00006 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);
00018 glClear(GL_COLOR_BUFFER_BIT);
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
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;
00074 case 'B': glCullFace(GL_BACK); break;
00075 case 'A': glCullFace(GL_FRONT_AND_BACK); break;
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,
00107 char *argv[]
00108 ) {
00109 glutInit(&argc,argv);
00110 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
00111 glutInitWindowPosition(20,20);
00112 glutInitWindowSize(400,400);
00113 glutCreateWindow("la ventana");
00114 glOrtho(-100.0,100.0,-100.0,100.0,-100.0,100.0);
00115 glutDisplayFunc(Display);
00116 glutKeyboardFunc(KeyPress);
00117 ReadFile();
00118 glutMainLoop();
00119 }
00120