问题
I am practicing the usage of VBOs in OpenGL with Java and LWJGL (using this tutorial, and basically copying it's code: http://www.arcsynthesis.org/gltut/index.html) and right now something really weird is happening.
I have a window set up and this is my render() function, called inside the main loop:
public void render() {
FloatBuffer buffer = BufferUtils.createFloatBuffer(3 * 3);
buffer.put(-1);
buffer.put(-1);
buffer.put(0);
buffer.put(0);
buffer.put(1);
buffer.put(0);
buffer.put(1);
buffer.put(-1);
buffer.put(0);
buffer.flip();
int vbo = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 3 * 4, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
}
As you can see, it's very simple code which should draw a triangle. But what I get on a Mac OS X Mountain Lion laptop, running Intel HD 4000 graphics is this:

And what I get on Windows 7, running AMD HD 6850 graphics is this:

Why is that? I really see no reason for this to happen, both of the video cards support OpenGL 2.0, which is what I'm using, right?
回答1:
I devoted a lot of time to solving this issue when I first started to use VAO objects. It was very frustrating to say the least.
I ultimately figured it out and I guess it comes down to a glitch in the compatibility profile that requires you to have used glLinkProgram and glUseProgram on a shader prior to calling glGenVertexArrays, even though the program requirement should have been relaxed outside the Core profile...
The easiest solution is to simply replace:
GL30.glGenVertexArrays
with APPLEVertexArrayObject.glGenVertexArraysAPPLE
GL30.glBindVertexArray
with APPLEVertexArrayObject.glBindVertexArrayAPPLE
GL30.glDeleteVertexArrays
with APPLEVertexArrayObject.glDeleteVertexArrayAPPLE
You can also overcome the problem by compiling a shader and calling glUseProgram prior to using GL30.glGenVertexArrays
...
来源:https://stackoverflow.com/questions/18368914/gldrawarrays-behaving-weirdly-on-mac-os-x