0

I'm trying to draw two similar rectangles with this code:

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

GL20.glUseProgram(pId);

GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

GL30.glBindVertexArray(vaoId);
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2);

GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);

GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);

GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
GL20.glDisableVertexAttribArray(2);
GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);

GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

GL20.glUseProgram(0);

Strangely just the second of the two is drawn, although they have exactly the same drawing code. The only difference is, that one of them is shifted a bit. I tested to just draw the first one and it worked. So does the second rectangle somehow overwrite the first one?

4

1 回答 1

2

删除 GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); 它基本上清除了屏幕上的所有颜色,这意味着只有您最后绘制的三角形可见。

于 2013-07-12T10:29:06.547 回答