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
|
while(!done)
{
ticks++;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
done = true;
break;
}
if(event.type == SDL_KEYDOWN)
{
if(event.key.keysym.sym == SDLK_ESCAPE)
{
done = true;
break;
}
if(event.key.keysym.sym == SDLK_DOWN)
skup = true;
if(event.key.keysym.sym == SDLK_UP)
skdown = true;
if(event.key.keysym.sym == SDLK_LEFT)
skleft = true;
if(event.key.keysym.sym == SDLK_RIGHT)
skright = true;
if(event.key.keysym.sym == SDLK_PAGEUP)
skpu = true;
if(event.key.keysym.sym == SDLK_PAGEDOWN)
skpd = true;
}
if(event.type == SDL_KEYUP)
{
if(event.key.keysym.sym == SDLK_DOWN)
skup = false;
if(event.key.keysym.sym == SDLK_UP)
skdown = false;
if(event.key.keysym.sym == SDLK_LEFT)
skleft = false;
if(event.key.keysym.sym == SDLK_RIGHT)
skright = false;
if(event.key.keysym.sym == SDLK_PAGEUP)
skpu = false;
if(event.key.keysym.sym == SDLK_PAGEDOWN)
skpd = false;
}
if(event.type == SDL_MOUSEMOTION)
{
}
}
if(skup)
camz -= 0.1f;
if(skdown)
camz += 0.1f;
if(skleft)
camx += 0.1f;
if(skright)
camx -= 0.1f;
if(skpu)
roty += 0.2f;
if(skpd)
roty -= 0.2f;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(camx,camy,camz); // move 5 units into the screen.
glRotatef(roty, 1.0f, 0, 0);
glRotatef(0, 0, 1.0f, 0);
drawcube(0,0,0,0);
drawcube(1,0,0,1);
drawcube(2,0,0,0);
drawcube(3,0,0,0);//draws a cube of a fixed size, first three arguments are the position of the
drawcube(3,1,0,1);//upper left corner, the last argument is the pointer to the texture to use
SDL_GL_SwapBuffers();
SDL_Delay(10);
if(firstround)
firstround = false;
}
|