用opengl画旋转六边形
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 04:33:56
用opengl画旋转六边形
用opengl画旋转六边形
用opengl画旋转六边形
#include
#include
#include
#define PI 3.14
float spin=0;
int step=2;
void init()
{glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
}
void display()
{glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin,0,0,1);
glScalef(50,50,50);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
int i;
for(i=0;i=360)spin-=360;
glutPostRedisplay();
}
void reshape(int w, int h)
{glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100*w/h,100*w/h,-100,100,-10,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char** argv)
{glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}