起点0615的个人主页

http://www.qtcn.org/bbs/u/145133  [收藏] [复制]

起点0615

与时具进,掌握最新技术!!

  • 8

    关注

  • 7

    粉丝

  • 10

    访客

  • 等级:新手上路
  • 总积分:48
  • 男,1992-07-15

最后登录:2021-11-20

更多资料

日志

opengl 中常用画正方体的方法

2013-08-17 20:28

void GLWidget::drawCube()
{
    GLfloat vertex_list[8][3] = {
        {-1.0, -1.0, 1.0},
        {1.0, -1.0, 1.0},
        {1.0, 1.0, 1.0},
        {-1.0, 1.0, 1.0},
        {-1.0, -1.0, -1.0},
        {1.0, -1.0, -1.0},
        {1.0, 1.0, -1.0},
        {-1.0, 1.0, -1.0}
    };

    GLint vertex_index_list[6][4] = {
        {0, 1, 2, 3}, // front
        {4, 7, 6, 5}, // back
        {7, 3, 2, 6}, // top
        {4, 5, 1, 0}, // bottom
        {5, 6, 2, 1}, // right
        {4, 0, 3, 7} // left
    };

    static const GLfloat texCoord_list[4][2] = {
        {0.0, 0.0},
        {1.0, 0.0},
        {1.0, 1.0},
        {0.0, 1.0}
    };

    static const GLint texCoord_index_list[6][4] = {
        {0, 1, 2, 3},
        {1, 2, 3, 0},
        {3, 0, 1, 2},
        {2, 3, 0, 1},
        {1, 2, 3, 0},
        {0, 1, 2, 3}
    };

    static const GLfloat normal_list[6][3] = {
        {0.0, 0.0, 1.0},
        {0.0, 0.0, -1.0},
        {0.0, 1.0, 0.0},
        {0.0, -1.0, 0.0},
        {1.0, 0.0, 0.0},
        {-1.0, 0.0, 0.0}
    };

    glBindTexture(GL_TEXTURE_2D, texture[filter]);

    glBegin(GL_QUADS);
    for (int i = 0; i < 6; i++) {
        glNormal3fv(normal_list);
        for (int j = 0; j < 4; j++) {
            glTexCoord2fv(texCoord_list[texCoord_index_list[j]]);
            glVertex3fv(vertex_list[vertex_index_list[j]]);
        }
    }
    glEnd();
}




只需要在paintGL()方法中调用drawCube()方法即可……















分类:opengl|回复:1|浏览:2029|全站可见|转载
 

下一篇: qt5.0.2连接mysql

上一篇: OpenGL的引入

 
删除

彩阳:Good,继续学习中……

2013-08-18 01:21 -

Powered by phpwind v8.7 Certificate Copyright Time now is:04-19 21:21
©2005-2016 QTCN开发网 版权所有 Gzip disabled