#include <stdlib.h>#include <glut.h> static GLfloat spin=0.0;static GLfloat posY=0.0f;static GLfloat posX=0.0f;static GLint w = 800;static GLint h = 600;// Called to draw scenevoid RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_LINE_LOOP); glVertex3f(0.0f,-0.25f,0.0f); glVertex3f(-0.25f,-0.5f,0.0f); glVertex3f(-0.5f,-0.5f,0.0f); glVertex3f(-0.0f,0.5f,0.0f); glVertex3f(0.5f,-0.5f,0.0f); glVertex3f(0.25f,-0.5f,0.0f); glVertex3f(-0.0f,-0.25f,0.0f); glEnd(); // Flush drawing commands glutSwapBuffers(); }void reshape(int w,int h){ glViewport(0,0,(GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-10.0f,10.0f,-10.0f,10.0f,-1.0f,1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity();}void spinDisplay(void){ spin+=5; glutPostRedisplay();}// Setup the rendering statevoid SetupRC(void) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glShadeModel(GL_FLAT); }void mySpecialKeys(int key, int x, int y){switch (key){case GLUT_KEY_LEFT: { glRotatef(3.1415/1.0,0.0,0.0,1.0); glutIdleFunc(spinDisplay); break; }case GLUT_KEY_RIGHT: { glRotatef(-3.1415/1.0,0.0,0.0,1.0); glutIdleFunc(spinDisplay); break; }case GLUT_KEY_UP: { glTranslatef(0.0f,0.1f,0.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glBegin(GL_LINE_STRIP); glVertex3f(-0.25f,-0.5f,0.0f); glVertex3f(0.0f,-1.0f,0.0f); glVertex3f(0.25f,-0.5f,0.0f); glEnd(); glutSwapBuffers(); break; }case GLUT_KEY_DOWN: { glTranslatef(0.0f,-0.1f,0.0f); break; }default: break;}}void myKeyboard(unsigned char key, int x, int y) {switch (key){case 27: exit(0);break;}}// Main program entry pointvoid main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowPosition(100,100); glutInitWindowSize(800,600); glutCreateWindow("Asteroids"); glutDisplayFunc(RenderScene); glutReshapeFunc(reshape); glutKeyboardFunc(myKeyboard); glutSpecialFunc(mySpecialKeys); SetupRC(); glutMainLoop();}
thanks in advance.