[英]glVertexAttribPointer - OpenGLES/OpenGL
我试图将OpenGLES代码移植到OpenGL,但对glVertexAttribPointer感到有些困惑。 这是OpenGLES代码的一部分:
//DRAWING OBJECT
// Get buffers from mesh
Mesh mesh = obj.getMesh();
FloatBuffer _vb = mesh.get_vb();
ShortBuffer _ib = mesh.get_ib();
short[] _indices = mesh.get_indices();
//the vertex info
_vb.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
gl.glVertexAttribPointer(gl.glGetAttribLocation(shader.get_program(), "aPosition"), 3, gl.GL_FLOAT, false,TRIANGLE_VERTICES_DATA_STRIDE_BYTES, _vb);
gl.glEnableVertexAttribArray(gl.glGetAttribLocation(shader.get_program(), "aPosition"));
// Draw with indices
gl.glDrawElements(gl.GL_TRIANGLES, _indices.length, gl.GL_UNSIGNED_SHORT, _ib);
那么如何使用OpenGL创建缓冲区? 因为在OpenGLES中,顶点是直接从glVertexAttribArray函数中的当前数组缓冲区获取的。 我尝试使用glBufferData,但是没有用。
public static FloatBuffer createFloatBuffer(float[] coords) {
// Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.
ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * SIZEOF_FLOAT);
bb.order(ByteOrder.nativeOrder());
FloatBuffer fb = bb.asFloatBuffer();
fb.put(coords);
fb.position(0);
return fb;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.