Created
May 3, 2019 10:47
-
-
Save RobertHue/186ecbadd76b8f67388fa548c42986e5 to your computer and use it in GitHub Desktop.
Create and initialize a buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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