glDrawArrays() behaving weirdly on Mac OS X

萝らか妹 提交于 2019-12-13 20:52:35

问题


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.glBindVertexArraywith 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!