代码如下:
#include <windows.h> //#include <GLUT/glut.h> #include <GL/glut.h> #include <math.h> #include <iostream> using namespace std; #define GL_PI 3.1415f void RenderScene() { //glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); static GLdouble dRadius = 10; static GLdouble dAngle = 0.0; //glClearColor(0.0f,0.0f,1.0f,0.0f); if(dAngle==0.0) glClear(GL_COLOR_BUFFER_BIT); glPointSize(10.0); glBegin(GL_POINTS); glVertex2d(dRadius*cos(dAngle),dRadius*sin(dAngle)); glEnd(); dRadius *= 1.01; dAngle += 0.1; if(dAngle > GL_PI) { dRadius = 10; dAngle = 0.0; } //glutSwapBuffers(); glFlush(); } void ChangeSize(GLsizei w,GLsizei h) { if(h==0) h = 1; //glutPostRedisplay(); GLfloat aspectRatio = (GLfloat)w/(GLfloat)h; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glOrtho(-100,100,-100/aspectRatio,100/aspectRatio,100.0,-100.0); else glOrtho(-100*aspectRatio,100*aspectRatio,-100,100,100.0,-100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void SetupRC() { glClearColor(0.0f,0.0f,1.0f,1.0f); glColor3f(1.0f,0.0f,0.0f); } void TimerFunction(int value) { glutPostRedisplay(); glutTimerFunc(33,TimerFunction,1); } int main(int argc, char *argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(800,600); glutCreateWindow("Simple"); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); glutTimerFunc(33,TimerFunction,1); SetupRC(); glutMainLoop(); return 0; }
时间: 2024-10-20 04:42:20