日志
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()方法即可…… |
下一篇: qt5.0.2连接mysql
上一篇: OpenGL的引入