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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| #include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "constantes.h"
int main ( int argc, char** argv )
{
SDL_Surface *ecran = NULL;
SDL_Event event;
bool continuer = true;
long angleX = 0, angleZ = 0, last_time = 0, current_time = 0;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_OPENGL);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, (double)LARGEUR_FENETRE/HAUTEUR_FENETRE, 1, 1000);
glEnable(GL_DEPTH_TEST);
last_time = SDL_GetTicks();
SDL_EnableKeyRepeat(10, 10);
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = false;
break;
default:
break;
}
current_time = SDL_GetTicks();
if(current_time - last_time >= 20)
{
angleX++;
angleZ++;
last_time = current_time;
}
else
{
SDL_Delay(20 - (current_time - last_time));
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(3, 3, 3, 0, 0, 0, 0, 0, 1);
glRotated(angleX, 1, 0, 0);
glRotated(angleZ, 0, 0, 1);
glBegin(GL_QUADS);
glColor3ub(255, 0, 0);
glVertex3d(1, 1, -1);
glVertex3d(-1, 1, -1);
glVertex3d(-1, 1, 1);
glVertex3d(1, 1, 1);
glColor3ub(0, 255, 0);
glVertex3d(1, -1, -1);
glVertex3d(1, 1, -1);
glVertex3d(1, 1, 1);
glVertex3d(1, -1, 1);
glColor3ub(0, 0, 255);
glVertex3d(-1, -1, -1);
glVertex3d(-1, 1, -1);
glVertex3d(-1, 1, 1);
glVertex3d(-1, -1, 1);
glColor3ub(255, 0, 0);
glVertex3d(1, 1, -1);
glVertex3d(-1, 1, -1);
glVertex3d(-1, 1, 1);
glVertex3d(1, 1, 1);
glColor3ub(255, 255, 0);
glVertex3d(-1, -1, -1);
glVertex3d(1, -1, -1);
glVertex3d(1, -1, 1);
glVertex3d(-1, -1, 1);
glColor3ub(255, 0, 255);
glVertex3d(1, 1, 1);
glVertex3d(-1, 1, 1);
glVertex3d(-1, -1, 1);
glVertex3d(1, -1, 1);
glColor3ub(0, 255, 255);
glVertex3d(1, 1, -1);
glVertex3d(-1, 1, -1);
glVertex3d(-1, -1, -1);
glVertex3d(1, -1, -1);
glEnd();
glFlush();
SDL_GL_SwapBuffers();
}
return 0;
} |
Partager