我使用顶点数组对象在我的框架中绘制网格。这很好,并且在我的计算机和大多数其他计算机上没有错误,但在某些计算机上(使用OGL 3.2)会出现此错误:
看起来很模糊。我甚至尝试了gDEBugger,但我也找不到任何相关的东西。
我使用Java和lwjgl。
以下是负责创建VAO图纸的代码:
/**
* Store the mesh's data on the GPU
*/
public void setup() {
setup = true;
vaoID = glGenVertexArrays();
glBindVertexArray(vaoID);
vboID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboID);
/* Create a floatbuffer containing the vertex positions */
FloatBuffer buffer = BufferUtils.createFloatBuffer(vertices.size()*3).put(vecListToArray3(vertices));
buffer.flip();
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
/* Set attribute list 0 */
GL20.glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
if (!colors.isEmpty()) {
colorVboID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, colorVboID);
/* Create a floatbuffer containing the vertex colors */
buffer = BufferUtils.createFloatBuffer(colors.size()*4).put(vecListToArray4(colors));
buffer.flip();
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
/* Set attribute list 1 */
GL20.glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, 0);
}
if (!texCoords.isEmpty()) {
texVboID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, texVboID);
/* Create a floatbuffer containing the texture coords */
buffer = BufferUtils.createFloatBuffer(texCoords.size()*4).put(vecListToArray4(texCoords));
buffer.flip();
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
/* Set attribute list 2 */
GL20.glVertexAttribPointer(2, 4, GL_FLOAT, false, 0, 0);
}
if (!normals.isEmpty()) {
normalVboID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, normalVboID);
/* Create a floatbuffer containing the normals */
buffer = BufferUtils.createFloatBuffer(normals.size()*4).put(vecListToArray3(normals));
buffer.flip();
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
/* Set attribute list 2 */
GL20.glVertexAttribPointer(3, 3, GL_FLOAT, false, 0, 0);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
/**
* Render the mesh
* @return
*/
public Matrix4f draw() {
if (!setup) {
Log.fatalError("Mesh not initialized! Call setup before drawing!");
}
Matrix4f mvp = Start.container.world.setShaderValues(Graphics.shader);
glBindVertexArray(vaoID);
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
if (!texCoords.isEmpty()) {
GL20.glEnableVertexAttribArray(2);
}
if (!normals.isEmpty()) {
GL20.glEnableVertexAttribArray(3);
}
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
if (!normals.isEmpty()) {
GL20.glDisableVertexAttribArray(3);
}
if (!texCoords.isEmpty()) {
GL20.glDisableVertexAttribArray(2);
}
GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(0);
glBindVertexArray(0);
return mvp;
}