它可以用 2 个三角形条来完成,但是对于更复杂的几何图形,条通常会替换为索引三角形,因为当您需要多个条时它们会变得更有效。我认为如果您使用退化三角形将两者连接起来,也可以使用单个条带完成,但对于较大的几何图形,索引通常更好。四边形只是被转换成三角形。
仅当启用背面剔除时,缠绕方向才重要。此外,当您为照明添加纹理坐标和表面法线时,事情会变得更加复杂。法线可用于使立方体看起来多面或平滑阴影,这确实适用于较大的模型,如球体。这是我多年前为 OpenGL ES 2.0 编写的教程:
/******************************************************************************
Function DrawCubeSmooth
Return None
Description Draw a cube using Vertex and NormalsPerVertex Arrays and
glDrawArrays with two triangle strips. Because normals are
supplied per vertex, all the triangles will be smooth shaded.
Triangle strips are used instead of an index array. The first
strip is texture mapped but the second strip is not.
******************************************************************************/
void Cube2::DrawCubeSmooth(void)
{
static GLfloat Vertices[16][3] =
{ // x y z
{-1.0, -1.0, 1.0}, // 1 left First Strip
{-1.0, 1.0, 1.0}, // 3
{-1.0, -1.0, -1.0}, // 0
{-1.0, 1.0, -1.0}, // 2
{ 1.0, -1.0, -1.0}, // 4 back
{ 1.0, 1.0, -1.0}, // 6
{ 1.0, -1.0, 1.0}, // 5 right
{ 1.0, 1.0, 1.0}, // 7
{ 1.0, 1.0, -1.0}, // 6 top Second Strip
{-1.0, 1.0, -1.0}, // 2
{ 1.0, 1.0, 1.0}, // 7
{-1.0, 1.0, 1.0}, // 3
{ 1.0, -1.0, 1.0}, // 5 front
{-1.0, -1.0, 1.0}, // 1
{ 1.0, -1.0, -1.0}, // 4 bottom
{-1.0, -1.0, -1.0} // 0
};
static GLfloat NormalsPerVertex[16][3] = // One normal per vertex.
{ // x y z
{-0.5, -0.5, 0.5}, // 1 left First Strip
{-0.5, 0.5, 0.5}, // 3
{-0.5, -0.5, -0.5}, // 0
{-0.5, 0.5, -0.5}, // 2
{ 0.5, -0.5, -0.5}, // 4 back
{ 0.5, 0.5, -0.5}, // 6
{ 0.5, -0.5, 0.5}, // 5 right
{ 0.5, 0.5, 0.5}, // 7
{ 0.5, 0.5, -0.5}, // 6 top Second Strip
{-0.5, 0.5, -0.5}, // 2
{ 0.5, 0.5, 0.5}, // 7
{-0.5, 0.5, 0.5}, // 3
{ 0.5, -0.5, 0.5}, // 5 front
{-0.5, -0.5, 0.5}, // 1
{ 0.5, -0.5, -0.5}, // 4 bottom
{-0.5, -0.5, -0.5} // 0
};
static GLfloat TexCoords[8][2] =
{ // x y
{0.0, 1.0}, // 1 left First Strip
{1.0, 1.0}, // 3
{0.0, 0.0}, // 0
{1.0, 0.0}, // 2
{0.0, 1.0}, // 4 back
{1.0, 1.0}, // 6
{0.0, 0.0}, // 5 right
{1.0, 0.0} // 7
};
glEnableVertexAttribArray(VERTEX_ARRAY);
glEnableVertexAttribArray(NORMAL_ARRAY);
glEnableVertexAttribArray(TEXCOORD_ARRAY);
// Set pointers to the arrays
glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, Vertices);
glVertexAttribPointer(NORMAL_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, NormalsPerVertex);
glVertexAttribPointer(TEXCOORD_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, TexCoords);
// Draw first triangle strip with texture map
glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
// Draw second triangle strip without texture map
glDisableVertexAttribArray(TEXCOORD_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 8, 8);
glDisableVertexAttribArray(VERTEX_ARRAY);
glDisableVertexAttribArray(NORMAL_ARRAY);
};
我希望这会有所帮助。