Opengl es 立方体的OpenGl顶点顺序

Opengl es 立方体的OpenGl顶点顺序,opengl-es,3d,cube,vertices,Opengl Es,3d,Cube,Vertices,我一直在研究OpenGL,并潜入3D世界。这个问题通常与OpenGL有关,但我一直在使用WebGL(如果我相信的话,这就是OpenGL ES)。我在理解立方体是如何绘制的方面遇到了问题。我知道要画一个四边形,你需要按(默认)CCW顺序创建两个三角形,就像 1 0 |‾ ‾ ‾ ‾| | | Indices = 0,1,2, 0,2,3 (2 triangles one face) | | |_ _ _ _| 2 3 1 0 |

我一直在研究OpenGL,并潜入3D世界。这个问题通常与OpenGL有关,但我一直在使用WebGL(如果我相信的话,这就是OpenGL ES)。我在理解立方体是如何绘制的方面遇到了问题。我知道要画一个四边形,你需要按(默认)CCW顺序创建两个三角形,就像

1 0 |‾ ‾ ‾ ‾| | | Indices = 0,1,2, 0,2,3 (2 triangles one face) | | |_ _ _ _| 2 3 1 0 |‾ ‾ ‾ ‾| ||指数=0,1,2,0,2,3(一个面上有两个三角形) | | |_ _ _ _| 2 3
然而,我在理解绘制立方体的最佳方法时遇到了一些困难。有没有一个具体的方法我应该画立方体?例如,在前->右->下->左->上->后-/strong>中绘制面是最佳顺序还是其他方式。我是不是也要逆时针画立方体面呢?我只需要了解表示模型/立方体的不同方式以及原因。

可以使用两个三角形条带来完成,但是对于更复杂的几何体,条带通常会被索引三角形所取代,因为当需要多个条带时,它们会更有效。我认为如果你用一个退化三角形连接两个,也可以用一个条带来完成,但是对于较大的几何体,索引通常更好。四边形被转换成三角形

只有启用背面消隐时,卷绕方向才很重要。此外,当为照明添加纹理坐标和曲面法线时,事情会变得更加复杂。法线可以用来使立方体看起来是多面的或平滑着色的,这确实适用于更大的模型,如球体。以下是我多年前为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);
};
我希望这有帮助