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 112 113 114 115
| #include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
int up,right;
SDL_Event event;
void draw_screen(void)
{
while (1)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_UP)
{
up = (up + 1);
}
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_DOWN)
{
up = (up - 1);
}
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_LEFT)
{
right = (right + 1);
}
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RIGHT)
{
right = (right - 1);
}
gluLookAt(right,up,1,0,0,0,0,1,0);
glTranslatef(0.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glColor3d(1,0,0);
glVertex3i(1,1,1);
glColor3d(-1,-9,0);
glColor3d(1,-3,5);
glVertex3i(1,-1,1);
glColor3d(3,1,-1);
glVertex3i(-1,-1,1);
glColor3d(-1,-1,0);
glVertex3i(-1,1,1);
glColor3d(1,1,0);
glVertex3i(1,1,-1);
glColor3d(-1,-1,-1);
glVertex3i(1,-1,-1);
glColor3d(-1,-1,0);
glVertex3i(-1,-1,-1);
glColor3d(-1,-1,0);
glVertex3i(-1,1,-1);
glColor3d(1,0,-1);
glVertex3i(1,1,1);
glColor3d(2,-1,0);
glVertex3i(1,-1,1);
glVertex3i(1,-1,-1);
glColor3d(-1,-1,0);
glVertex3i(1,1,-1);
glColor3d(1,3,0);
glVertex3i(-1,1,1);
glColor3d(-1,4,-1);
glVertex3i(-1,-1,1);
glColor3d(3,-1,0);
glVertex3i(-1,-1,-1);
glColor3d(1,0,0);
glVertex3i(-1,1,-1);
glColor3d(-1,0,6);
glVertex3i(-1,1,-1);
glColor3d(-1,2,-2);
glVertex3i(-1,1,1);
glColor3d(1,-5,0);
glVertex3i(1,1,1);
glColor3d(-1,-1,0);
glVertex3i(1,1,-1);
glColor3d(-1,-1,0);
glVertex3i(-1,-1,-1);
glVertex3i(-1,-1,1);
glColor3d(-3,2,0);
glVertex3i(1,-1,1);
glColor3d(-1,-2,3);
glVertex3i(1,-1,-1);
glEnd();
SDL_GL_SwapBuffers();
SDL_PollEvent (&event);
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
{
SDL_Quit();
return;
}
}
}
void setup_opengl( int hauteur, int largeur )
{
float ratio = (float) hauteur / (float) largeur;
glClearColor(0, 0, 0, 0);
glViewport(0, 0, hauteur, largeur);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, ratio, 0.5, 50);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
}
int main(int argc, char **argv)
{
int hauteur = 800;
int largeur = 600;
int bits = 32;
int flags = 0;
SDL_Init(SDL_INIT_VIDEO);
flags = SDL_OPENGL;
SDL_SetVideoMode(hauteur,largeur,bits,flags);
setup_opengl(hauteur,largeur);
draw_screen();
return 0;
} |
Partager