美文网首页
绘制立方体

绘制立方体

作者: zz张哲 | 来源:发表于2016-06-17 15:36 被阅读0次
    glClear(GL_COLOR_BUFFER_BIT);  //清除背景颜色
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);   //线框显示
        //glEnable(GL_DEPTH_TEST);
        glPushMatrix();
        glTranslatef(-4.0f, 3.0f, -10.0f);
    
        //绘制立方体
        glBegin(GL_QUADS);
    
        //x
        glColor4ub(200, 0, 0, 255);
        glVertex3f(0.5f, -0.5f, 0.5f);
        glVertex3f(0.5f, -0.5f, -0.5f);
        glVertex3f(0.5f, 0.5f, -0.5f);
        glVertex3f(0.5f, 0.5f, 0.5f);
    
        //-x
        glVertex3f(-0.5f, -0.5f, -0.5f);
        glVertex3f(-0.5f, -0.5f, 0.5f);
        glVertex3f(-0.5f, 0.5f, 0.5f);
        glVertex3f(-0.5f, 0.5f, -0.5f);
    
        //y
        glVertex3f(-0.5f, 0.5f, 0.5f);
        glVertex3f(0.5f, 0.5f, 0.5f);
        glVertex3f(0.5f, 0.5f, -0.5f);
        glVertex3f(-0.5f, 0.5f, -0.5f);
    
        //-y
        glVertex3f(-0.5f, -0.5f, -0.5f);
        glVertex3f(0.5f, -0.5f, -0.5f);
        glVertex3f(0.5f, -0.5f, 0.5f);
        glVertex3f(-0.5f, -0.5f, 0.5f);
    
        //z
        glVertex3f(-0.5f, -0.5f, 0.5f);
        glVertex3f(0.5f, -0.5f, 0.5f);
        glVertex3f(0.5f, 0.5f, 0.5f);
        glVertex3f(-0.5f, 0.5f, 0.5f);
    
        //-z
        glVertex3f(0.5f, -0.5f, -0.5f);
        glVertex3f(-0.5f, -0.5f, -0.5f);
        glVertex3f(-0.5f, 0.5f, -0.5f);
        glVertex3f(0.5f, 0.5f, -0.5f);
    
        glEnd();
        glPopMatrix();

    相关文章

      网友评论

          本文标题:绘制立方体

          本文链接:https://www.haomeiwen.com/subject/svsvdttx.html