我正在使用java和lwjgl编写一个基于opengl的体素引擎体素引擎。我跟着this tutorial并试图将它的渲染方法更新为现代opengl,所以我可以使用着色器。当我将glVertexPointer转换为glVertexAttribPointer时,它正确地显示了所有顶点,但当我为glTexCoordPointer执行时,颜色停止显示。
这里是块的两种渲染方法(来自更新的和旧的)
public void Render() { //updated render method
GL30.glBindVertexArray(VAOHandle);
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL11.glDrawArrays(GL11.GL_QUADS, 0, CHUNK_SIZE * CHUNK_SIZE
* CHUNK_SIZE * 24);
GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);
}
public void Render() { //old render method
GL11.glPushMatrix();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0L);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
GL11.glColorPointer(3, GL11.GL_FLOAT, 0, 0L);
GL11.glDrawArrays(GL11.GL_QUADS, 0, CHUNK_SIZE * CHUNK_SIZE
* CHUNK_SIZE * 24);
GL11.glPopMatrix();
}
以下是将日期加载到VAO / VBO的部分(两种情况下的数据都相同,所以我认为我不需要添加它,但如果需要我会这样做):
// updated method
VAOHandle = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vaoID);
VBOColorHandle = GL15.glGenBuffers();
VBOVertexHandle = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexPositionData,
GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexColorData, GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL30.glBindVertexArray(0);
// old method
VBOColorHandle = GL15.glGenBuffers();
VBOVertexHandle = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexPositionData,
GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexColorData,
GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
如果有人能弄清楚为什么渲染顶点但没有应用颜色我会很高兴,提前谢谢