#include <iostream> #include <gl\glut.h> #include <gl\GL.h> #include <gl\GLU.h> #include "base.h" using namespace std; int x, y; void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); //glBegin(GL_TRIANGLES); glBegin(GL_QUADS); glVertex2d(x, y); glVertex2d(x + 35, y); glVertex2d(x + 35, y + 35); glVertex2d(x, y + 35); glEnd(); glPopMatrix(); //glFlush(); glutSwapBuffers(); } void init() { glClearColor (0.0, 0.0, 0.0, 0.0); glColor3f(1.0, 1.0, 1.0); x = y = 0; } void reshape(int w, int h) { double d = MapHeight / 600.0 / 2; double dw = w / 2.0 * d; double dh = h / 2.0 * d; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-dw, dw, -dh, dh); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glutPostRedisplay(); } void onTimer(int value) { printf("dfd\n"); x += 10; // 重绘 glutPostRedisplay(); glutTimerFunc(50, onTimer, 0); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); // glutInitWindowSize(MapWidth,MapHeight); double radio = MapWidth * 1.0 / MapHeight; glutInitWindowSize(600 * radio,600); glutInitWindowPosition(0,0); glutCreateWindow("simple"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutTimerFunc(50, onTimer, 0); init(); glutMainLoop(); //system("pause"); }