Skip to content

Instantly share code, notes, and snippets.

@RobertHue
Created May 3, 2019 10:47
Show Gist options
  • Save RobertHue/186ecbadd76b8f67388fa548c42986e5 to your computer and use it in GitHub Desktop.
Save RobertHue/186ecbadd76b8f67388fa548c42986e5 to your computer and use it in GitHub Desktop.
Create and initialize a buffer
// Type used for names in OpenGL is GLuint
GLuint buffer;
// Create a buffer
glCreateBuffer( sizeof(buffer)/sizeof(GLuint), &buffer);
// Specify the data store parameters for the buffer
glNamedBufferStorage(
buffer, // Name of the buffer
1024 * 1024, // 1 MiB of space
NULL, // No initial data
GL_MAP_WRITE_BIT // Allow map for writing
);
// Now bind it to the context using the GL_ARRAY_BUFFER binding point
glBindBuffer(GL_ARRAY_BUFFER, buffer);
// This is the data that will be placed into the buffer object
static const float data[] =
{
0.25, -0.25, 0.5, 1.0,
-0.25, -0.25, 0.5, 1.0,
0.25, 0.25, 0.5, 1.0
}
// Put the data ino the buffer at offset zero
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(data), data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment