// Vertex Index Buffer
idxVboId = glGenBuffers();
vertsIdxBuffer = MemoryUtil.memAllocInt(indices.length);
vertsIdxBuffer.put(indices).flip();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,idxVboId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,vertsIdxBuffer,GL_STATIC_DRAW);
shaderProgram.bind();
//bind to vao
glBindVertexArray(mesh.getVaoId());
//enable positions buffer
glEnableVertexAttribArray(0);
//enable colour buffer
glEnableVertexAttribArray(1);
//draw verts
glDrawElements(GL_TRIANGLES,
mesh.getVertexCount(),GL_UNSIGNED_INT,0);
//restore state (?)
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glBindVertexArray(0);
shaderProgram.unbind();
任何建议都很感谢,因为我已经盯着这几个小时了,真的看不出我犯了什么错误。
编辑:四边形网格代码
renderer.init();
float[] positions = new float[]{
-0.5f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
};
float[] colours = new float[]{0.5f,0f,0f,0f,0.5f,0f,0f,0f,0.5f,0f,0.5f,0.5f};
int[] indices = new int[]{
0, 1, 3, 3, 1, 2,
};
mesh = new BMesh(positions,colours,indices);
位置阵列更改前后
Before
After