茶壶旋转

来源:互联网 发布:双色球算法必中6红246 编辑:程序博客网 时间:2024/06/02 14:08

简介

主要通过调用函数实现茶壶旋转的效果。

代码

#include <GL\glut.h>float angle = 0;void init(){    glClearColor(0, 0, 0, 0);    glColor3f(1, 1, 1);     glShadeModel(GL_SMOOTH);}void display(){    glClear(GL_COLOR_BUFFER_BIT);//有深度depth、累积accum、模板stencil缓冲区    glLoadIdentity();    gluLookAt(0, 0, 200, 0, 0, 0, 0, 1, 0);    glRotatef(angle, 0, 1, 0);    glColor3f(0, 1, 0);    glPushMatrix();    //glPointSize(10);    //glBegin(GL_TRIANGLES);    //glColor3f(1, 0, 0);    //glVertex3f(-50, 0, 0);    //glColor3f(0, 1, 0);    //glVertex3f(50, 0, 0);    //glColor3f(0, 0, 1);    //glVertex3f(0, 50, 0);    //glEnd();    glutWireTeapot(70);    glPopMatrix();    glutSwapBuffers();}void rotate(){    if (angle > 360) angle -= 360;    angle += 0.5;     glutPostRedisplay();}void reshape(int w, int h){    glViewport(0, 0, w, h);    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    //gluOrtho2D(-w/2.0 , w/2.0 , -h/2.0 , h / 2.0);//正交投影    gluPerspective(100, 1, 0.1, 1000);//透视投影    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();}int main(int argc, char **argv){    glutInit(&argc, argv);    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);    glutCreateWindow("1_opengl");    glutInitWindowSize(800, 800);    init();    glutDisplayFunc(display);    glutReshapeFunc(reshape);    glutIdleFunc(rotate);    glutMainLoop();    return 0;}

结果

这里写图片描述

0 0