2015-04-28 20 views
0

我想玩WebGL,我可以渲染一個三角形this plunker。現在,我嘗試改變,使之成爲完整的正方形......無法獲得第四個矢量在WebGL中呈現TRIANGLE_STRIP

//This... 
this.triangleVertexPositionBuffer.numItems = 3; 
// ... 
this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, this.triangleVertexPositionBuffer.numItems); 
// To this.. 
this.triangleVertexPositionBuffer.numItems = 4; 

這對我來說應該只是做一個正方形,然而,三角形完全消失。我也收到以下警告...

GL ERROR :GL_INVALID_OPERATION : glDrawArrays: attempt to access out of range vertices in attribute 1 

我在這裏錯過了什麼?

回答

2

您還需要爲第四個頂點添加顏色屬性。

+0

是。在問題中設置'this.triangleVertexPositionBuffer.numItems'爲'4',並且在'initBuffers()'的'colors []'中添加另一行。你的第四個頂點想要畫得很好。 – ScottMichaud