glDrawArrays()在Mac OS X上表现异常 [英] glDrawArrays() behaving weirdly on Mac OS X
问题描述
我正在使用Java和LWJGL练习在OpenGL中使用VBO(使用本教程,并基本上复制了它的代码:
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.
我设置了一个窗口,这是我的render()函数,在主循环内调用:
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);
}
如您所见,这是一个非常简单的代码,应该绘制一个三角形.但是我在运行Intel HD 4000图形的Mac OS X Mountain Lion笔记本电脑上得到的是:
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:
在运行AMD HD 6850显卡的Windows 7上,我得到的是:
And what I get on Windows 7, running AMD HD 6850 graphics is this:
那是为什么?我真的没有理由发生这种情况,两个显卡都支持我正在使用的OpenGL 2.0,对吧?
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?
推荐答案
当我第一次开始使用VAO对象时,我花了很多时间来解决这个问题.至少可以说这是非常令人沮丧的.
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.
我最终弄清楚了,我想这归结为兼容性配置文件中的一个小问题,该问题要求您在调用glGenVertexArrays之前先在着色器上使用glLinkProgram和glUseProgram,即使该程序要求应该已经在Core之外放宽了.个人资料...
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
与APPLEVertexArrayObject.glGenVertexArraysAPPLE
GL30.glBindVertexArray
和APPLEVertexArrayObject.glBindVertexArrayAPPLE
GL30.glDeleteVertexArrays
与APPLEVertexArrayObject.glDeleteVertexArrayAPPLE
您还可以通过编译着色器并在使用GL30.glGenVertexArrays
...
You can also overcome the problem by compiling a shader and calling glUseProgram prior to using GL30.glGenVertexArrays
...
这篇关于glDrawArrays()在Mac OS X上表现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!