【发布时间】:2014-02-12 12:04:02
【问题描述】:
我是 jogl 的新手,并尝试使用 VBO 渲染矩形。 有两个数组:第一个数组是
float vertex[] = {-2.0f, -2.0f, -2.0f,
2.0f, -2.0f, -2.0f,
-2.0f, -2.0f, 2.0f,
2.0f, -2.0f, 2.0f
};
第二个数组是
float colors[] = {1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f
};
然后我尝试初始化顶点缓冲区
pointsbf = Buffers.newDirectFloatBuffer(vertex.length);
colorsbf = Buffers.newDirectFloatBuffer(colors.length);
pointsbf.put(vertex);
colorsbf.put(colors);
pointsbf.rewind();
colorsbf.rewind();
上面的代码已经写在 INIT() 函数中; 下面的代码已经写在 DISPLAY() 函数中;
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, pointsbf);
gl.glColorPointer(3, GL.GL_FLOAT, 0, colorsbf);
gl.glDrawArrays(GL.GL_TRIANGLES, 0, totalNumVerts);
gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL2.GL_COLOR_ARRAY);
但运行后的代码只显示黑屏(((
【问题讨论】: