Files Classes Functions Hierarchy
00001 #include <iostream> 00002 #include <fstream> 00003 using namespace std; 00004 00005 #include <commandline.h> 00006 #include <graphmisc.h> 00007 #include <simplexD1tessapp01.h> 00008 #include <zpr.h> 00009 00010 string simplexD1tessapp01::doc[] = 00011 { 00012 "", 00013 "Application to displays a line tessellation from indexed lines." 00014 }; 00015 00016 bool * simplexD1tessapp01::help = 0; 00017 menusystem * simplexD1tessapp01::messages = 0; 00018 simplexD1tessapp01::tesstype* simplexD1tessapp01::tess = 0; 00019 simplexD1tessapp01::tessdisptype* simplexD1tessapp01::tessdisp = 0; 00020 uint simplexD1tessapp01::displaypoints = 0; 00021 uint simplexD1tessapp01::displaylines = 0; 00022 uint simplexD1tessapp01::displaylinesmulticolor = 0; 00023 uint simplexD1tessapp01::displaysimplexindexes = 0; 00024 00025 00026 void simplexD1tessapp01::keyboard(unsigned char key, int x, int y) 00027 { 00028 switch (key) 00029 { 00030 case 27: exit(0); break; 00031 00032 case 'h': if (help) *help = !*help; break; 00033 case '1': if (tessdisp) tessdisp->gswitches[displaypoints]->toggle(); break; 00034 case '2': if (tessdisp) 00035 { 00036 tessdisp->gswitches[displaylinesmulticolor]->isdrawn = false; 00037 tessdisp->gswitches[displaylines]->isdrawn = false; 00038 } 00039 break; 00040 case '3': if (tessdisp) 00041 { 00042 tessdisp->gswitches[displaylinesmulticolor]->isdrawn = false; 00043 tessdisp->gswitches[displaylines]->isdrawn = true; 00044 } 00045 break; 00046 case '4': if (tessdisp) 00047 { 00048 tessdisp->gswitches[displaylinesmulticolor]->isdrawn = true; 00049 tessdisp->gswitches[displaylines]->isdrawn = false; 00050 } 00051 case '5': if (tessdisp) tessdisp->gswitches[displaysimplexindexes]->toggle(); break; 00052 break; 00053 00054 case 'u': if (messages) messages->scrollup(); break; 00055 case ' ': if (messages) messages->scrolldown(); break; 00056 case 's': 00057 { 00058 stringstream ss; 00059 for (uint i=1; i<tess->vi.size(); ++i) 00060 ss << i << ": " << tess->vi[i] << endl; 00061 00062 if (messages) 00063 messages->addfont10blockstart(ss.str(),1); 00064 } 00065 break; 00066 case 'p': 00067 { 00068 stringstream ss; 00069 for (uint i=1; i<tess->pts.size(); ++i) 00070 ss << i << ": " << tess->pts[i] << endl; 00071 00072 messages->addfont10blockstart(ss.str(),1); 00073 } 00074 break; 00075 case 'c': messages->clear(); break; 00076 00077 00078 } 00079 00081 // tessdisp->update(); 00082 00083 glutPostRedisplay(); 00084 } 00085 00086 00087 void simplexD1tessapp01::display() 00088 { 00089 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00090 00091 gobj::global->draw(); 00092 00093 00094 glerrordisplay(); 00095 00096 glutSwapBuffers(); 00097 } 00098 00099 void simplexD1tessapp01::mainmenu() 00100 { 00101 gobjpush(new gobjglDisable(GL_LIGHTING)); 00102 menusystem * menu = 00103 new menusystem(0,0,true,point2<GLint>(60,30),10); 00104 menu->fontcolor = point4<float>(218.0/255.0,165.0/255.0,32.0/255.0,0.75); 00105 00106 gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true); 00107 help = & menuswitch->isdrawn; 00108 gobjpush(menuswitch); 00109 00110 menu->addfont12("Indexed Lines Display",2); 00111 00112 menu->addfont10("1 Toggle the points",1); 00113 menu->addfont10("2 Mesh - none",1); 00114 menu->addfont10("3 Mesh - uniform color",1); 00115 menu->addfont10("4 Mesh - multi color",1); 00116 menu->addfont10("5 Toggle the simples indexes",1); 00117 menu->addfont10(" ",1); 00118 00119 menu->addfont10("s Print simplexes",1); 00120 menu->addfont10("p Print points",1); 00121 menu->addfont10("space Scroll down",1); 00122 menu->addfont10("u Scroll up",1); 00123 menu->addfont10("c Clear the display",1); 00124 00125 00126 00127 menu->addfont10(" ",1); 00128 menu->addfont10("h Toggle help menu",1); 00129 menu->addfont10("ESC Quit"); 00130 00131 } 00132 00133 void simplexD1tessapp01::createdisplay() 00134 { 00135 tessdisp = new tessD1disp01<tesstype,pt2,uint>(*tess); 00136 00137 typeop< tessD1draw01points<tesstype,pt2> > pointstype; 00138 tessdisp->displayDeferred(displaypoints,pointstype); 00139 00140 typeop< tessD1draw01lines<tesstype,pt2> > linestype; 00141 tessdisp->displayDeferred(displaylines,linestype); 00142 00143 typeop< tessD1draw01linesmulticolor<tesstype,pt2> > linesmulticolortype; 00144 tessdisp->displayDeferred(displaylinesmulticolor,linesmulticolortype); 00145 00146 typeop< tessD1draw01simplexindexes<tesstype,pt2> > simplexindexestype; 00147 tessdisp->displayDeferred(displaysimplexindexes,simplexindexestype); 00148 00149 //gobjpush(tessdisp); 00150 00151 tessdisp->update(); 00152 xGraphics.push(tessdisp); 00153 } 00154 00155 void simplexD1tessapp01::messagemenu() 00156 { 00157 messages = 00158 new menusystem(0,0,true,point2<GLint>(60,250),10); 00159 gobjpush(messages); 00160 messages->fontcolor = point4<float>(1.0,0.0,0.0,0.8); 00161 messages->lightingdisable(); 00162 00163 glDisable(GL_DEPTH_TEST); 00164 glEnable(GL_BLEND); 00165 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00166 } 00167 00168 simplexD1tessapp01::simplexD1tessapp01(int argc, char** argv) 00169 { 00170 glutInit(&argc,argv); 00171 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00172 glutInitWindowSize(800,600); 00173 glutCreateWindow(""); 00174 glutDisplayFunc(display); 00175 glutKeyboardFunc(keyboard); 00176 00177 OpenGLinitialisation(); 00178 00179 glEnable(GL_DEPTH_TEST); 00180 glEnable(GL_CULL_FACE); 00181 glEnable(GL_NORMALIZE); 00182 00183 xGraphics.set(); 00184 00185 commandline cmd(argc,argv); 00186 00187 // Read in the tessellation file 00188 string file; 00189 cmd.mapvar(file,"file"); 00190 if (file.empty()) 00191 { 00192 cout << "error: filename of an indexed 2D tessellation expected." << endl; 00193 cout << " eg ./main prog=15 file=tessD1001.txt" << endl; 00194 return; 00195 } 00196 00197 string s; 00198 bool res = tokenizermisc::readfile(s,file); 00199 if (res==false) 00200 { 00201 cout << "error: could not read file " << file << endl; 00202 return; 00203 } 00204 00205 // Create the tessellation 00206 tesstype tessD1; 00207 tess = & tessD1; 00208 00209 tess->serializeInverse(s); 00210 00211 createdisplay(); 00212 00213 mainmenu(); 00214 00215 messagemenu(); 00216 00217 zpr zz; 00218 glutMainLoop(); 00219 } 00220 00221 00222 00223 00224
1.5.8