Render multiple objects with one buffer using glMapBuffer?
<p>I'm confused on the concept of buffers. I understand the very basics with <strong>glBufferData</strong> and <strong>glBufferSubData</strong>. Using <strong>glBufferSubData</strong> before a render function in your main loop you can use a <em>offset</em> and <em>size</em> parameter to store multiple model objects in a vertex buffer and a index buffer. Then at render you bind the single vertex buffer and call <strong>glDrawElements</strong> with the correct offsets and sizes to render multiple objects.</p>

<p>Is this the case with <strong>glMapBuffer</strong>? Or am I suppose to call <strong>glMapBuffer</strong> to link vertex and index data at render, then draw?</p>

<pre><code>GLuint vertexArrayId;
GLuint verticesBufferId;
GLuint indicesBufferId;

void setupBuffers() {
    glGenVertexArrays(1, &amp;vertexArrayId);
    glBindVertexArray(vertexArrayId);
    glGenBuffers(1, &amp;verticesBufferId);
    glGenBuffers(1, &amp;indicesBufferId);

    glBindBuffer(GL_ARRAY_BUFFER, verticesBufferId);
    glBufferData(GL_ARRAY_BUFFER, VERTICES_SIZE, NULL, GL_STATIC_DRAW);
    // glMapBuffer stuff here 

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBufferId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDICES_SIZE, NULL, GL_STATIC_DRAW);
    // glMapBuffer stuff here
}

void render() {
    glBindBuffer(GL_ARRAY_BUFFER, verticesBufferId);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)((sizeof(GLfloat) * 0)));

    glEnableVertexAttribArray(0);
    // glDrawElements stuff here
    glDisableVertexAttribArray(0);

    // Model, View, Projection transformations here
    // glUniformMatrix4fv 
}
</code></pre>