#include #include #include #include "main.h" //////////////////////////////// /////// Variables ///////// //////////////////////////////// // Différentes fenètres int f1; int f2; //fenetre ouvert bool fen1; bool fen2; // Quel fenêtre, 1 par défault int fenetre = 1; // Pour réenvoyer a main int rargc; char **rargv; // Peline écran bool ChoixEcran = false; // Configuration pas fait bool fullscreen = false; // Par default pas en pleine écran // Configuration const char *resolution; //variable de la resolution int option[3]; // Option de configuration int current = 0; // Choix présentement selectionner int couleur; int refresh; // Grandeur de la fenêtre par default int LARGEUR_FENETRE = 640; int HAUTEUR_FENETRE = 480; int g_w, g_h; //////////////////////////////// ///// Fonction Texte ///// //////////////////////////////// void Texte(double x,double y, void *font, char *string) { glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); char *s; //Drawing text glRasterPos2f(x,y); for (s=string; *s != '\0'; s++) { glutBitmapCharacter(font, *s); } glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); } //////////////////////////////// ///// Fonction ///// ///// de configuration ///// //////////////////////////////// void sendConfig() { std::ostringstream scouleur; std::ostringstream srefresh; std::string oss; if (option[0] == 1) { fullscreen = true; // couleur if (option[2]==0) { scouleur << 16; } else if (option[2]==1) { scouleur << 32; } // refresh if (option[3]==0) { srefresh << 60; } else if (option[3]==1) { srefresh << 70; } else if (option[3]==2) { srefresh << 72; } else if (option[3]==3) { srefresh << 75; } // resolution if (option[1]==0) { oss = "\""; oss += "640x480"; oss += ":"; oss += scouleur.str(); oss += "@"; oss += srefresh.str(); oss += "\""; } else if (option[1]==1) { oss = "\""; oss += "800x600"; oss += ":"; oss += scouleur.str(); oss += "@"; oss += srefresh.str(); oss += "\""; } else if (option[1]==2) { oss = "\""; oss += "1024x480"; oss += ":"; oss += scouleur.str(); oss += "@"; oss += srefresh.str(); oss += "\""; } // créer le buffer pour copier la chaîne size_t size = oss.size() + 1; char * buffer = new char[ size ]; // copier la chaîne strncpy( buffer, oss.c_str(), size ); // mettre la chaine dans resolution resolution = buffer; // libérer la mémoire delete [] buffer; } else if (option[0] == 0) { if (option[1] == 0) { int LARGEUR_FENETRE = 640; int HAUTEUR_FENETRE = 480; } else if (option[1] == 1) { int LARGEUR_FENETRE = 800; int HAUTEUR_FENETRE = 600; } else if (option[1] == 2) { int LARGEUR_FENETRE = 1024; int HAUTEUR_FENETRE = 768; } } } //////////////////////////////// ///// Gestion du clavier ///// /////pour la configuration ///// //////////////////////////////// void KeyboardConfig(unsigned char key, int x, int y) { if ( key == 13) { sendConfig(); ChoixEcran = true; reset(); } if ( key == 27) { exit(0); } } void KeySpecialConfig(int key, int x, int y) { switch(key) { case GLUT_KEY_RIGHT : option[current] = option[current]+1; if (option[0] > 1) { option[0] = 0; } if (option[1] > 2) { option[1] = 0; } if (option[2] > 1) { option[2] = 0; } if (option[3] > 3) { option[3] = 0; } break; case GLUT_KEY_LEFT : option[current] = option[current]-1; if (option[0] < 0) { option[0] = 1; } if (option[1] < 0) { option[1] = 2; } if (option[2] < 0) { option[2] = 1; } if (option[3] < 0) { option[3] = 3; } break; case GLUT_KEY_UP : current = current-1; if (current < 0) { current = 3; } break; case GLUT_KEY_DOWN : current = current+1; if (current > 3) { current = 0; } break; } glutPostRedisplay(); } //////////////////////////////// ///// Gestion du clavier ///// ///// principale ///// //////////////////////////////// void KeyboardMain(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; } } void KeySpecialMain(int key, int x, int y) { } //////////////////////////////// ///// Fonction de rendu ///// ///// de configuration ///// //////////////////////////////// void DessineCarre() { glLoadIdentity(); float squarey; if (current == 0) { squarey = 0.6f; } else if (current == 1) { squarey = 0.3f; } else if (current == 2) { squarey = 0.0f; } else if (current == 3) { squarey = -0.3f; } glTranslatef(-0.9f,squarey,-1.0f); glBegin(GL_QUADS); glVertex3d(0.0f, 0.0f, 0.0f); glVertex3d(0.05f, 0.0f, 0.0f); glVertex3d(0.05f, 0.05f, 0.0f); glVertex3d(0.0f, 0.05f, 0.0f); glEnd(); } void DessinePoint1() { glLoadIdentity(); float point1x; if (option[0] == 0) { point1x = -0.55; } else if (option[0] == 1) { point1x = -0.05; } glTranslatef(point1x,0.5f,-1.0f); glPointSize(5.0); glBegin(GL_POINTS); glVertex3f(0.0f,0.0f,0.0f); glEnd(); } void DessinePoint2() { glLoadIdentity(); float point2x; if (option[1] == 0) { point2x = -0.55; } else if (option[1] == 1) { point2x = -0.05; } else if (option[1] == 2) { point2x = 0.45; } glTranslatef(point2x,0.2f,-1.0f); glPointSize(5.0); glBegin(GL_POINTS); glVertex3f(0.0f,0.0f,0.0f); glEnd(); } void DessinePoint3() { glLoadIdentity(); float point3x; if (option[2] == 0) { point3x = -0.55; } else if (option[2] == 1) { point3x = -0.05; } glTranslatef(point3x,-0.1f,-1.0f); glPointSize(5.0); glBegin(GL_POINTS); glVertex3f(0.0f,0.0f,0.0f); glEnd(); } void DessinePoint4() { glLoadIdentity(); float point4x; if (option[3] == 0) { point4x = -0.55; } else if (option[3] == 1) { point4x = -0.2; } else if (option[3] == 2) { point4x = -0.05; } else if (option[3] == 3) { point4x = 0.2; } glTranslatef(point4x,-0.4f,-1.0f); glPointSize(5.0); glBegin(GL_POINTS); glVertex3f(0.0f,0.0f,0.0f); glEnd(); } void displayConfig() { glClear(GL_COLOR_BUFFER_BIT); DessineCarre(); DessinePoint1(); DessinePoint2(); DessinePoint3(); DessinePoint4(); glLoadIdentity(); glColor3f(1.0f,1.0f,1.0f); // Titre : Configuration Texte(-0.2,0.9,GLUT_BITMAP_HELVETICA_18,"Configuration"); glColor3f(1.0f,1.0f,0.0f); // Sous-Titre : Affichage Texte(-0.8,0.6,GLUT_BITMAP_HELVETICA_12,"Affichage"); // Sous-Titre : Resolution Texte(-0.8,0.3,GLUT_BITMAP_HELVETICA_12,"Resolution"); // Sous-Titre : Couleur Texte(-0.8,0,GLUT_BITMAP_HELVETICA_12,"Couleur"); // Sous-Titre : Rafraichissement Texte(-0.8,-0.3,GLUT_BITMAP_HELVETICA_12,"Vitesse de rafraichissement"); glColor3f(0.0f,1.0f,1.0f); // Option : Fenetre Texte(-0.5,0.5,GLUT_BITMAP_HELVETICA_10,"Fenetre"); // Option : Pleine ecran Texte(0,0.5,GLUT_BITMAP_HELVETICA_10,"Pleine Ecran"); // Option : 640x480 Texte(-0.5,0.2,GLUT_BITMAP_HELVETICA_10,"600x480"); // Option : 800x600 Texte(0,0.2,GLUT_BITMAP_HELVETICA_10,"800x600"); // Option : 1024x768 Texte(0.5,0.2,GLUT_BITMAP_HELVETICA_10,"1024x768"); // Option : 16 Texte(-0.5,-0.1,GLUT_BITMAP_HELVETICA_10,"16"); // Option : 32 Texte(0,-0.1,GLUT_BITMAP_HELVETICA_10,"32"); // Option : 60 Texte(-0.5,-0.4,GLUT_BITMAP_HELVETICA_10,"60"); // Option : 70 Texte(-0.25,-0.4,GLUT_BITMAP_HELVETICA_10,"70"); // Option : 72 Texte(0,-0.4,GLUT_BITMAP_HELVETICA_10,"72"); // Option : 75 Texte(0.25,-0.4,GLUT_BITMAP_HELVETICA_10,"75"); glFlush(); glutSwapBuffers(); } //////////////////////////////// ///// Fonction de rendu ///// ///// Principale ///// //////////////////////////////// void display() { // Enleve la couleur glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glColor3f(0.0f, 0.5f, 0.0f); Texte(1,1,GLUT_BITMAP_TIMES_ROMAN_10,"Configuration"); // Ici on met se que l'on veut afficher à l'écran glutSwapBuffers(); } //////////////////////////////// ///// Gestion principale ///// //////////////////////////////// // Redimenssion de l'écran void reshape(GLint w, GLint h) { g_w = w; g_h = h; glViewport(0, 0, g_w, g_h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(65.0, (float)g_w / g_h, 1, 1000); glMatrixMode(GL_MODELVIEW); } void main(int argc, char **argv) { rargc = argc; rargv = argv; bool ConfigOpen = true; if (ChoixEcran == false) { glutInit(&argc,argv); glutInitDisplayMode ( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize (LARGEUR_FENETRE, HAUTEUR_FENETRE); f1 = glutCreateWindow ("Configuration"); ConfigOpen = true; glutDisplayFunc(displayConfig); glutKeyboardFunc(KeyboardConfig); glutSpecialFunc(KeySpecialConfig); glutMainLoop(); } else { if(ConfigOpen) { glutDestroyWindow(f1); ConfigOpen = false; } glutInit(&argc,argv); glutInitDisplayMode ( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); if (fullscreen) { glutSetIconTitle("Request - Respond"); glutGameModeString(resolution); glutEnterGameMode(); } else { glutInitWindowSize (LARGEUR_FENETRE,HAUTEUR_FENETRE); f2 = glutCreateWindow ("Request - Respond"); } glutSetCursor(GLUT_CURSOR_NONE); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(KeyboardMain); glutSpecialFunc(KeySpecialMain); glutMainLoop(); } } void reset() { main(rargc, rargv); }