openGL编码实现一个立方体

代码清单:

#include "GL/glut.h"
void init(void)
{
    glClearColor(0.0,0.0,0.0,0.0);
    glShadeModel(GL_FLAT);
}

void Reshape(int w, int h)//移动窗口或改变窗口尺寸
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-1.0,1.0,-1.0,1.0,1.5,20.0);
    glMatrixMode(GL_MODELVIEW);

}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);  
glLoadIdentity();//设置当前矩阵为单位矩阵
gluLookAt(5.0,5.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);
glScalef(2.0,1.0,1.0);//x方向放大2倍
glutWireCube(1);
glFlush();
}

void main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(100,100);
    glutCreateWindow("3D Cube");
    init();
    glutReshapeFunc(Reshape);
    glutDisplayFunc(display);
    glutMainLoop();
}

结果截图:
(https://img-blog.csdn.net/20171107233409641?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVG9yaWFfemhhbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

你可能感兴趣的:(计算机图形学)