ios - glDrawElements 三角形使用顶点数组开始和结束的顶点渲染(使用 GL_TRIANGLE_STRIP)

标签 ios opengl-es-2.0 gl-triangle-strip

我正在尝试使用对 glDrawElements() 的单个调用来呈现一组线条。每条线都是一个四边形,我在它们之间使用退化三角形来分隔它们。

渲染时,使用索引 0n-1n-2 处的顶点绘制了一个额外的三角形,我不相信是 GL_TRIANGLE_STRIPS 的正常行为。

例如,12 个顶点组成 3 个四边形,我的索引数组如下所示:

(0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 7, 8, 8, 9, 10, 11)

结果是这样的:

Triangle rendered between first and last vertices

无论我尝试渲染多少个顶点,或者我在索引列表中放入多少个索引,它仍然用三角形连接开始和结束。我正在使用 VBO 和 IBO 进行绘图,包裹在 VAO 中。所以要画画,我只需调用:

glBindVertexArrayOES(vao);
glDrawElements(GL_TRIANGLE_STRIP, indexCount * sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
glBindVertexArrayOES(0);

VAO 设置:

// Bind VAO.
glBindVertexArrayOES(vao);

// Bind and set VBO data.
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexStructure), vertices, GL_STATIC_DRAW);

// Enable attribute pointers.
glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, sizeof(VertexStructure), (void*)offsetof(VertexStructure, vertex));
glEnableVertexAttribArray(position);
glVertexAttribPointer(color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(VertexStructure), (void*)offsetof(VertexStructure, color));
glEnableVertexAttribArray(color);

// Bind and set IBO data.
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * sizeof(GLushort), indices, GL_STATIC_DRAW);

// Unbind VBO & VAO.
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArrayOES(0);

// Disable attribute pointers.                                                       
glDisableVertexAttribArray(position);
glDisableVertexAttribArray(color);


我可能做了什么愚蠢的事情来导致这种行为?

最佳答案

count Specifies the number of elements to be rendered.

glDrawElements(GL_TRIANGLE_STRIP, indexCount, GL_UNSIGNED_SHORT, 0);

关于ios - glDrawElements 三角形使用顶点数组开始和结束的顶点渲染(使用 GL_TRIANGLE_STRIP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14839065/

相关文章:

ios - 如何让音乐在所有 View 中继续播放

ios - UIImagePickerController 在照片库中错误地指出 "No photos or libraries"

ios - 无法在 CADisplayLink 渲染循环中绑定(bind) EAGLDrawable

android - 为什么我的点 openGL 着色器程序有 strip 伪像?

java - 外观呈三角形 strip 。表面法线?还是绕组?

ios - 重建应用程序时推送 token 会改变吗?

ios - 在 iOS 上处理大量像素

c++ - OpenGL实际上是如何读取索引的?

opengl - 有没有办法在用三角形带绘制的网格上实现类似行进正方形的东西?

ios - 禁用AppStore Connect中的可用国家/地区后,对用户的副作用是什么