Edited ignore everything, I spoke too soon
Final code just in case it help someone
GLvoid *p = glMapBufferRange(GL_ARRAY_BUFFER, 0, FLOATS_PER_QUAD * sizeof(GLfloat), GL_MAP_WRITE_BIT);
if (p == NULL)
{
std::cout << "Null ptr: " << glGetError()<< std::endl;
glUnmapBuffer(GL_ARRAY_BUFFER);
return;
}
((GLfloat*)p)[0] = 0.0f;
((GLfloat*)p)[1] = 0.0f;
((GLfloat*)p)[2] = 0.0f;
((GLfloat*)p)[3] = 0.0f;
((GLfloat*)p)[4] = 32.0f;
((GLfloat*)p)[5] = 0.0f;
((GLfloat*)p)[6] = 32.0f;
((GLfloat*)p)[7] = 32.0f;
((GLfloat*)p)[8] = 0.0f;
((GLfloat*)p)[9] = 32.0f;
((GLfloat*)p)[10] = 0.0f;
((GLfloat*)p)[11] = 0.0f;
glUnmapBuffer(GL_ARRAY_BUFFER);
glUseProgram(shaderProgramID);
glUniformMatrix4fv(matrixUniform, 1, GL_FALSE, uniformMatrix->matrix);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL);
glBindVertexArray(NULL);
glUseProgram(NULL);
---------------------------------------------------------------
Edit2:
My real question:
What am I doing wrong here? I keep getting back a NULL pointer to my buffer. glGetError() gives me back a 1282 error code [ GL_INVALID_OPERATION ]
glBindBuffer(GL_ARRAY_BUFFER, vbo);
GLvoid *p = glMapBufferRange(GL_ARRAY_BUFFER, 0, FLOATS_PER_QUAD * sizeof(GLfloat), GL_WRITE_ONLY);
if (p == NULL)
{
std::cout << "Null ptr: " << glGetError()<< std::endl;
glUnmapBuffer(GL_ARRAY_BUFFER);
return;
}
((GLfloat*)p)[0] = 0.0f;
((GLfloat*)p)[1] = 0.0f;
((GLfloat*)p)[2] = 0.0f;
((GLfloat*)p)[3] = 0.0f;
((GLfloat*)p)[4] = 32.0f;
((GLfloat*)p)[5] = 0.0f;
((GLfloat*)p)[6] = 32.0f;
((GLfloat*)p)[7] = 32.0f;
((GLfloat*)p)[8] = 0.0f;
((GLfloat*)p)[9] = 32.0f;
((GLfloat*)p)[10] = 0.0f;
((GLfloat*)p)[11] = 0.0f;
glUnmapBuffer(GL_ARRAY_BUFFER);
-------------------------------------------------------------------------------------
Hey everyone, I was wondering if someone could better explain the glMapBuffer*** calls.
I understand that glMapBuffers*** returns a void pointer to the buffer, but the thing I don't understand is how do I map the buffer?
All the examples I see do a memcpy of sorts to place data into it.
EG:
void * vbo = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
memcpy(vbo_buffer, vertexs, vertex_size);
glUnmapBuffer(GL_ARRAY_BUFFER);
But is there way to directly place data into the buffer? Through pointer arithmetic or something?
EG [I know this is wrong, but somehting like]:
void * vbo = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
*(vbo+1) = 0.0f;
*(vbo+2) = 0.0f;
*(vbo+3) = 0.0f;
*(vbo+4) = 32.0f;
*(vbo+4) = 0.0f;
//etc....
glUnmapBuffer(GL_ARRAY_BUFFER);