/* Programme qui ouvre une fenêtre SDL Program that opens a SDL window Copyright (C) 2006 BEYLER Jean Christophe This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include //Afficher du texte utilisant GLUT void render_string(float x, float y, void* font, const char* s) { glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glRasterPos2f(x, y); while(*s) { glutBitmapCharacter(font, *s); s++; } } const int WIDTH=640; const int HEIGHT=480; int main(int argc, char **argv) { //Déclaration des variables SDL_Event event; SDL_Surface *screen; int done = 0; //Initialisation de SDL if(SDL_Init(SDL_INIT_VIDEO)!=0) { std::cerr << "Problème pour initialiser SDL: %s\n" << SDL_GetError() << std::endl; return 1; } //Mettre un titre à la fenêtre SDL_WM_SetCaption("Programme SDL de base", NULL); //Ouvrerture d'une surface pour l'affichage de la fenêtre screen = SDL_SetVideoMode(WIDTH,HEIGHT, 32,SDL_OPENGL); if(screen==NULL) done = 1; /* Mettre en place le double buffer */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /* Initialisation de OpenGL */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Mettre en place une perspective orthogonale gluOrtho2D(0,HEIGHT, 0, WIDTH); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Boucle generale while(!done) { //Traiter les évènements while(SDL_PollEvent(&event)) { switch(event.type) { //Si on veut quitter, done=1 suffira case SDL_QUIT: done=1; break; //Si on vient de relacher une touche de clavier case SDL_KEYUP: //Et si c'est la lettre q /* Attention, ceci ne fonctionne pas avec tous les Systèmes d'exploitation et tous les claviers Pour le rendre portable, il faudrait passer par les Unicodes, mais cela sort du cadre de ce tutoriel d'introduction. Si vous voulez utiliser la lettre 'q' pour quitter et ceci ne fonctionne pas, alors c'est la lettre 'a' qu'il faudra utiliser (c'est la place de la lettre 'q' sur le clavier QWERTY). Si vous voulez vraiment la lettre 'q', remplacer SDLK_q par SDLK_a, cela devrait faire l'affaire */ if(event.key.keysym.sym==SDLK_q) //On met done a 1 pour quitter done=1; break; //Sinon on ne fait rien default: break; } } render_string(10,10,GLUT_BITMAP_HELVETICA_18,"Bonjour"); SDL_GL_SwapBuffers(); } SDL_FreeSurface(screen); SDL_Quit(); return 0; }