Triangle_Strip应该换行吗?

时间:2013-03-24 21:28:08

标签: java android opengl-es opengl-es-2.0

我正面临着一段时间前所遇到的问题(Incorrect VBO for mesh: some triangles are connected and shouldn't [2D]),而且由于我的着色器变得越来越复杂,并且出现了与此相关的不同问题,我需要在其基础上解决它!

这是VBO的内容:

[0.0, 0.0,
 0.0, 240.0,

 10.0, 0.0,
 10.0, 240.0,

 20.0, 0.0,
 20.0, 240.0,

 30.0, 0.0,
 30.0, 240.0

 and so on up to

 1190.0, 0.0,
 1190.0, 240.0,

 1200.0, 0.0,
 1200.0, 240.0,

 1210.0, 0.0,
 1210.0, 240.0]

因此数组长度为244点* 2坐标= 488个元素。

这是框架的opengl轨迹

glClearColor(red = 0,100000, green = 0,100000, blue = 0,100000, alpha = 1,000000)
glClear(mask = 16384)
glEnable(cap = GL_BLEND)
glBindBuffer(target = GL_ARRAY_BUFFER, buffer = 2)
glDisableVertexAttribArray(index = 1)
glVertexAttribPointer(indx = 0, size = 2, type = GL_FLOAT, normalized = false, stride = 8, ptr = 0x0)
glUniformMatrix4fv(location = 1, count = 1, transpose = false, value = [0.0025, 0.0, 0.0, 0.0, 0.0, 0.004166667, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, -1.0, 0.0, 1.0])
glUniform1i(location = 5, x = 0)
glUniform4f(location = 3, x = 0,000000, y = 0,000000, z = 1,000000, w = 0,500000)
glUniform1f(location = 4, x = 2,491089)
glUniform1f(location = 0, x = 1780,000000)
glUniformMatrix4fv(location = 2, count = 1, transpose = false, value = [-100.0, 40.0, 260.0, 430.0, 165.6131, 122.20027, 247.55757, 189.05222, 680.0, 880.0, -268.66666, -268.66666, 126.442535, 1.7712338, 160.0, 160.0])
glDrawArrays(mode = GL_TRIANGLE_STRIP, first = 0, count = 486)
glEnableVertexAttribArray(index = 1)
glDisable(cap = GL_BLEND)
glEnable(cap = GL_BLEND)
glBindBuffer(target = GL_ARRAY_BUFFER, buffer = 3)
glDisableVertexAttribArray(index = 1)
glVertexAttribPointer(indx = 0, size = 2, type = GL_FLOAT, normalized = false, stride = 8, ptr = 0x0)
glUniformMatrix4fv(location = 1, count = 1, transpose = false, value = [0.0025, 0.0, 0.0, 0.0, 0.0, 0.004166667, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 1.0, 0.0, 1.0])
glUniform1i(location = 5, x = 0)
glUniform4f(location = 3, x = 0,000000, y = 0,500000, z = 1,000000, w = 0,500000)
glUniform1f(location = 4, x = 2,491089)
glUniform1f(location = 0, x = 1780,000000)
glUniformMatrix4fv(location = 2, count = 1, transpose = false, value = [-60.0, 150.0, 330.0, 550.0, -71.13025, -193.20978, -11.679321, -223.35025, 740.0, 990.0, -268.66666, -268.66666, -394.54395, -270.3169, -160.0, -160.0])
glDrawArrays(mode = GL_TRIANGLE_STRIP, first = 0, count = 486)
glEnableVertexAttribArray(index = 1)
glDisable(cap = GL_BLEND)
eglSwapBuffers

我的着色器有点长而且很复杂,但除了沿Y轴移动Y分量与0不同的顶点之外什么也没做。均匀值正确,着色器工作正常。

当我用TRIANGLE_STRIP渲染时,屏幕显示连接第一个顶点(0,0)和最后一个顶点(1210,???)的线条(???因为我的着色器移动它,而不是240。我知道它在哪里,它应该在哪里,但它会不断变化。)

TRIANGLE_STRIP rendering glitch

使用LINE_STRIP渲染确认问题。

LINE_STRIP rendering glitch

那么,这是TRIANGLE_STRIP的预期行为吗?或者是错的?阅读opengl规范它接缝不应该包装,但它确实(在不同的设备中,所以它不是特定的驱动程序问题)

1 个答案:

答案 0 :(得分:0)

完全找到了解决方案。

我将数组的长度减去2作为要绘制的顶点数。错误是我的顶点数组同时包含X和Y坐标,因此它实际上是要绘制的基元数量的两倍。

我现在使用array.length / 2,一切正常。

是的,当我发现它时,我认为表现会增加。相反,它没有发生。