代码如下:
#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); GLfloat x,y,z,angle; glPushMatrix(); glRotatef(45.0f,1.0f,0.0f,0.0f); glRotatef(45.0f,0.0f,1.0f,0.0f); glBegin(GL_LINE_STRIP); z = -50.0f; for(angle = 0.0f;angle <= (GL_PI*2)*3;angle += 0.1f) { x = 25.0f*sin(angle); y = 25.0f*cos(angle); z += 0.5f; glVertex3f(x,y,z); } glEnd(); glPopMatrix(); glutSwapBuffers(); } void ChangeSize(GLsizei w,GLsizei h) { if(h==0) h = 1; 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,0.0f,1.0f); glColor3f(1.0f,0.0f,0.0f); } int main(int argc, char *argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); glutInitWindowSize(800,600); glutCreateWindow("Simple"); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); SetupRC(); glutMainLoop(); return 0; }
时间: 2024-10-10 06:08:57