I'm trying to port an OpenGLES code to OpenGL and I'm a little confused about the glVertexAttribPointer. Here is part of the OpenGLES code:
//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);
So how can I create a buffer using OpenGL? Because in OpenGLES the vertices are directly taken from the current Array Buffer in the glVertexAttribArray function. I tried to use glBufferData but it didn't work.
0L
toglVertexAttribPointer (...)
if you are using a VBO, instead of_vb
. You cannot use a client memory address (FloatBuffer
in this case) as the vertex attrib pointer location if you are using a VBO. When using a VBO, the address is supposed to be an offset into the memory allocated by the VBO that was bound at the time you called the function. – Andon M. Coleman