【问题标题】:OpenGL to OpenGL-ES - Changing color of triangles in a stripOpenGL 到 OpenGL-ES - 改变条带中三角形的颜色
【发布时间】:2010-12-15 04:18:46
【问题描述】:

在 opengl 中使用 glBegin() 和 glEnd() 时,您可以设置和更改每个 glVertex3f() 之间的颜色。使用顶点数组和 glDrawArrays() 时如何重新创建此行为。这是普通的opengl。

for(angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f))
    {
    // Calculate x and y position of the next vertex
    x = 50.0f*sin(angle);
    y = 50.0f*cos(angle);

    // Alternate color between red and green
    if((iPivot %2) == 0)
        glColor3f(0.0f, 1.0f, 0.0f);
    else
        glColor3f(1.0f, 0.0f, 0.0f);

    // Increment pivot to change color next time
    iPivot++;

    // Specify the next vertex for the triangle fan
    glVertex2f(x, y);
    }

【问题讨论】:

    标签: iphone opengl-es


    【解决方案1】:

    使用 glDrawArrays 你必须启用 glVertexPointer 来设置顶点数据。

    同样,您还可以为颜色设置客户端内存指针。

    归结为这些调用:

      glEnableClientState (GL_VERTEX_ARRAY);
      glEnableClientState (GL_COLOR_ARRAY); // enables the color-array.
    
      glVertexPointer (...  // set your vertex-coordinates here..
      glColorPointer (...   // set your color-coorinates here..
    
      glDrawArrays (... // draw your triangles
    

    顺便说一句 - 纹理坐标的处理方式相同。只需为此使用 GL_TEXCOORD_ARRAY 和 glTexCoordPointer。

    【讨论】:

    • 但是 color_array 不会应用于所有三角形吗?我想为每个其他三角形着色不同?红白交替。
    • 你必须为每个顶点设置颜色。 OpenGL|ES 删除了只为其他三角形着色的功能,因为大多数应用程序没有用只为一些三角形着色。请记住,OpenGL|ES 是 OpenGL 的精简版本,所有很少使用和非必要的东西都被删除了。
    • 哦,我现在明白了。我误解了颜色数组的工作原理。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多