计算机图形学——OpenGL学习系列之绘制3D下的小桌子

来源:互联网 发布:廖雪峰python教程微盘 编辑:程序博客网 时间:2024/04/30 08:50

计算机图形学——OpenGL学习系列之绘制3D下的小桌子

做的一个小练习,主要用到了几何变换还有gl自带的一个绘制立方体的函数,顺便体会一下glPush和glPop的用法。另外,从2D到3D,开心到飞起偷笑明天让他动起来,睡觉睡觉

#include <gl\glut.h>void drawTop(){glPushMatrix();glColor3f(0.25,0.25,0.25);glTranslatef(0, 0, 0.6);glScalef(8, 8, 1);glutSolidCube(0.2);glPopMatrix();}void drawLeg(float x, float y){glPushMatrix();glColor3f(0.75,0.75,0.75);glTranslatef(x, y, 0);glScalef(1, 1, 5);glutSolidCube(0.2);glPopMatrix();}void drawDesk(){glPushMatrix();glRotatef(90, -1.0, 0.0, 0.0);glRotatef(10, -1.0, 0.0, 0.0);glRotatef(30,0,1,0);drawTop();drawLeg(0.5, 0.5);drawLeg(-0.5, 0.5);drawLeg(-0.5, -0.5);drawLeg(0.5, -0.5);glPopMatrix();}void display(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glDisable(GL_DEPTH_TEST);glDisable(GL_LIGHTING);    glMatrixMode(GL_MODELVIEW);drawDesk();glFlush();}int main(int argc, char *argv[]){    glutInit(&argc, argv);    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);    glutInitWindowPosition(100, 100);    glutInitWindowSize(400, 400);    glutCreateWindow("MyDesk");    glutDisplayFunc(&display);    glutMainLoop();    return 0;}


0 0