|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
//GLAPI void GLAPIENTRY gluOrtho2D (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);
//#include <GL/glut.h>
#define LARGEUR 640
#define LONGUEUR 480
void dessiner();
double angleX, angleZ;
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("The 3D Cube of the dead !!!",NULL);
SDL_SetVideoMode(LARGEUR, LONGUEUR, 32, SDL_OPENGL);
SDL_EnableKeyRepeat(10,10);
//SDL_ShowCursor(false);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70,(double)LARGEUR/LONGUEUR,1,1000);
glEnable(GL_DEPTH_TEST);
dessiner();
bool continuer = true;
SDL_Event event;
Uint32 last_time = SDL_GetTicks();
Uint32 current_time,ellapsed_time, start_time;
while (continuer)
{
start_time = SDL_GetTicks();
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
continuer = false;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
/*case SDLK_RIGHT:
angle = 1;
break;
case SDLK_LEFT:
angle = -1;
break;*/
/*case SDLK_UP:
posY += 5;
break;
case SDLK_DOWN:
posY -= 5;
break;*/
}
break;
/*case SDL_MOUSEMOTION:
posX = event.motion.x-LARGEUR/2;
posY = LONGUEUR/2-event.motion.y;
break;*/
}
}
current_time = SDL_GetTicks();
ellapsed_time = current_time - last_time;
last_time = current_time;
angleZ += 0.05 * ellapsed_time;
angleX += 0.05 * ellapsed_time;
dessiner();
ellapsed_time = SDL_GetTicks() - start_time;
if (ellapsed_time < 10)
{
SDL_Delay(10 - ellapsed_time);
}
}
SDL_Quit();
return 0;
}
void dessiner()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
gluLookAt(3,4,2,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,255,0);
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);
glColor3ub(255,0,255);
glVertex3d(1,-1,1);
glVertex3d(1,1,1);
glVertex3d(-1,1,1);
glVertex3d(-1,-1,1);
glEnd();
glFlush();
SDL_GL_SwapBuffers();
} |
|