GPU upload

Using the GPU requires three main steps: input, process, and output.

Input (upload)

Process

Output

All upload steps must take place before rendering. First allocate CPU side:

GLfloat positions[10] = {-1,-1, 1,1, -0.5,-0.366, 0,0.5, 0.5,-0.366};

Prepare an OpenGL buffer object.

// Generate a GPU side buffer
glGenBuffers(1, &positionBuffer);

You can allocate several buffers at once with glGenBuffers(count,dest_array), where count is how many you want and dest_array is where the handles go.

Next, activate the buffer so OpenGL knows which to use. Afterwards, all buffer operations will use the bound buffer.

// Tell OpenGL we want to work with the buffer we just made
glBindBuffer(GL_ARRAY_BUFFER, positionBuffer);

Finally, allocate space on the GPU and upload the data.

// Alloate and upload data to GPU
glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);

Now the data is on the GPU!

API details: glBufferData(target, size, data_ptr, usage).