OpenGL: how to use buffer_objects to draw <p>In page 103 of OpenGL redbook, they give an example (example 2-17) about how to use buffer_object to draw something.</p> <pre><code>#define BUFFER_OFFSET(bytes) ((GLubyte*) NULL + (bytes)) GLuint buffers[NUM_BUFFERS]; GLfloat vertices[][3] = { { -1.0, -1.0, -1.0 }, { 1.0, -1.0, -1.0 }, { 1.0, 1.0, -1.0 }, { -1.0, 1.0, -1.0 }, { -1.0, -1.0, 1.0 }, { 1.0, -1.0, 1.0 }, { 1.0, 1.0, 1.0 }, { -1.0, 1.0, 1.0 } }; GLubyte indices[][4] = { { 0, 1, 2, 3 }, { 4, 7, 6, 5 }, { 0, 4, 5, 1 }, { 3, 2, 6, 7 }, { 0, 3, 7, 4 }, { 1, 5, 6, 2 } }; glGenBuffers(NUM_BUFFERS, buffers); //Generate NUM_BUFFERS of buffers and put them in buffers array. glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTICES]); //bind buffers glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); //allocate space for buffers glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0)); </code></pre> <p>Here, we suppose to have a point to a array to specify in which array we will find the data. Then is that should be a pointer to some memory address in server?</p> <p>I just do not understand that BUFFER_OFFSET(0).</p> <p>Does that mean that there is always only one Vertex_Array in server and the program will choose that address automatically? The BUFFER_OFFSET(0) just tell you where to start in this array?????????</p> <pre><code>glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[INDICES]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0)); </code></pre> <p>Same thing here. We suppose to give a address at the last parameter. But I do not see that BUFFER_OFFSET(0) is a useful address.</p>