1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#define arrivee() fprintf(sortie, "arrivée à la ligne %i\n", __LINE__)
int main(int argc, char *argv[])
{
int continuer = 1;
SDL_Event event;
FILE *sortie = fopen ("Sortie.txt", "w+");
if (sortie == NULL)
{
printf ("Erreur : base de donnees introuvable...\n");
return EXIT_FAILURE;
}
arrivee();
if( SDL_Init(SDL_INIT_VIDEO) < 0)
{
fprintf(sortie, "Echec SDL_Init à la ligne %i: %i\n", __LINE__, *SDL_GetError());
return (EXIT_FAILURE);
}
arrivee();
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface *ecran = SDL_SetVideoMode(800, 600, 32, SDL_OPENGL);
if(ecran==NULL)
{
fprintf(sortie, "Echec lors de la création de fenêtre à la ligne %i: %i\n", __LINE__, *SDL_GetError());
return (EXIT_FAILURE);
}
arrivee();
int valeurBuffer;
if(SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &valeurBuffer)<0)
{
fprintf(sortie, "Echec de recuperation du parametre SDL_GL_DOUBLEBUFFER à la ligne %i: %i\n", __LINE__, *SDL_GetError());
return (EXIT_FAILURE);
}
arrivee();
if(valeurBuffer!=1)
{
fprintf(sortie, "Erreur : SDL_GL_DOUBLEBUFFER inactif à la ligne %i\n", __LINE__);
return (EXIT_FAILURE);
}
arrivee();
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
arrivee();
fclose(sortie);
SDL_Quit();
exit(EXIT_SUCCESS);
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
continuer = 0;
arrivee();
fclose(sortie);
SDL_Quit();
exit(EXIT_SUCCESS);
break;
default:
break;
}
break;
}
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3ub(255, 0, 0); glVertex2d(-0.75, -0.75);
glColor3ub(0, 255, 0); glVertex2d(0, 0.75);
glColor3ub(0, 0, 255); glVertex2d(0.75, -0.75);
glEnd();
glFlush();
SDL_GL_SwapBuffers();
}
arrivee();
fclose(sortie);
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager