本文介绍了带缓冲的glDrawArrays在JOGL中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有人可以帮助我找出为什么我的JOGL代码没有显示三角形的原因.出于某些原因也没有例外.我想念什么吗?
I was wondering whether someone can help me find out why my JOGL code does not show a triangle. There are no exceptions for some reason. Am I missing something?
IntBuffer vacantNameBuffer = IntBuffer.allocate(3);
gl.glGenBuffers(1, vacantNameBuffer);
int vertexBufferName = vacantNameBuffer.get();
float[] triangleArray = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f
};
FloatBuffer triangleVertexBuffer = FloatBuffer.wrap(triangleArray);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vacantNameBuffer.get());
gl.glBufferData(
GL2.GL_ARRAY_BUFFER,
triangleVertexBuffer.capacity() * Buffers.SIZEOF_FLOAT,
triangleVertexBuffer,
GL2.GL_STATIC_DRAW);
gl.glEnableVertexAttribArray(vacantNameBuffer.get());
gl.glVertexAttribPointer(0, 3, GL2.GL_FLOAT, false, 0, 0);
gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 3);
gl.glDisableVertexAttribArray(vacantNameBuffer.get());
gl.glFlush();
推荐答案
glEnableVertexAttribArray
需要属性位置(您设置为glVertexAttribPointer
的第一个参数的数字),因此应将其更改为:
glEnableVertexAttribArray
expects the attribute location (the number you set as first parameter of glVertexAttribPointer
) so you should change it to:
gl.glEnableVertexAttribArray(0);
gl.glVertexAttribPointer(0, 3, GL2.GL_FLOAT, false, 0, 0);
gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 3);
gl.glDisableVertexAttribArray(0);
这篇关于带缓冲的glDrawArrays在JOGL中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!