OpenGL defines an API of a rendering system.
Create data on CPU
Generate buffer object name for vertex positions and bind it to the GL_ARRAY_BUFFER target
GLuint posVBO, colVBO, indicesVBO;
glGenBuffer(1, &posVBO);
glBindBuffer(GL_ARRAY_BUFFER, posVBO);
Create and initialize buffer object's data store of the currently bound buffer object
GLuint posVBO, colVBO, indicesVBO;
glGenBuffer(1, &posVBO);
glBindBuffer(GL_ARRAY_BUFFER, posVBO);
glBufferData(GL_ARRAY_BUFFER, 12*sizeof(float), vPos, GL_STATIC_DRAW);
Create and initialize buffer object for vertex colors
GLuint posVBO, colVBO, indicesVBO;
glGenBuffer(1, &posVBO);
glBindBuffer(GL_ARRAY_BUFFER, posVBO);
glBufferData(GL_ARRAY_BUFFER, 12*sizeof(float), vPos, GL_STATIC_DRAW);
glGenBuffer(1, &colVBO);
glBindBuffer(GL_ARRAY_BUFFER, colVBO);
glBufferData(GL_ARRAY_BUFFER, 16*sizeof(float), vCol, GL_STATIC_DRAW);
Create and initialize buffer object for triangle indices
GLuint posVBO, colVBO, indicesVBO;
glGenBuffer(1, &posVBO);
glBindBuffer(GL_ARRAY_BUFFER, posVBO);
glBufferData(GL_ARRAY_BUFFER, 12*sizeof(float), vPos, GL_STATIC_DRAW);
glGenBuffer(1, &colVBO);
glBindBuffer(GL_ARRAY_BUFFER, colVBO);
glBufferData(GL_ARRAY_BUFFER, 16*sizeof(float), vCol, GL_STATIC_DRAW);
glGenBuffer(1, &indicesVBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesVBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6*sizeof(unsigned int), vIndices, GL_STATIC_DRAW);
Specify the value of a uniform variables for the program object
int projLoc = glGetUniformLocation(program, "projMat");
int viewlLoc = glGetUniformLocation(program, "viewMat");
int modelLoc = glGetUniformLocation(program, "modelMat");
glUniformMatrix4fv(projLoc, 1, GL_FALSE, projMat);
glUniformMatrix4fv(viewlLoc, 1, GL_FALSE, viewMat);
glUniformMatrix4fv(modellLoc, 1, GL_FALSE, modelMat);
Enable a generic vertex attribute array for vertex position
int posLoc = glGetAttribLocation(program, "vPos");
glEnableVertexAttribArray(posLoc);
Specify location and data layout for a generic vertex array
int posLoc = glGetAttribLocation(program, "vPos");
glEnableVertexAttribArray(posLoc);
glBindBuffer(GL_ARRAY_BUFFER, posVBO);
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
Enable and specify data of a generic vertex attribute array for vertex color
int posLoc = glGetAttribLocation(program, "vPos");
glEnableVertexAttribArray(posLoc);
glBindBuffer(GL_ARRAY_BUFFER, posVBO);
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
int colLoc = glGetAttribLocation(program, "vCol");
glEnableVertexAttribArray(colLoc);
glBindBuffer(GL_ARRAY_BUFFER, colVBO);
glVertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, (void*)0);
Bind the IBO and render
int posLoc = glGetAttribLocation(program, "vPos");
glEnableVertexAttribArray(posLoc);
glBindBuffer(GL_ARRAY_BUFFER, posVBO);
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
int colLoc = glGetAttribLocation(program, "vCol");
glEnableVertexAttribArray(colLoc);
glBindBuffer(GL_ARRAY_BUFFER, colVBO);
glVertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, (void*)0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vIndices);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, (void*)0);
Release the vertex array attrbutes
int posLoc = glGetAttribLocation(program, "vPos");
glEnableVertexAttribArray(posLoc);
glBindBuffer(GL_ARRAY_BUFFER, posVBO);
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
int colLoc = glGetAttribLocation(program, "vCol");
glEnableVertexAttribArray(colLoc);
glBindBuffer(GL_ARRAY_BUFFER, colVBO);
glVertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, (void*)0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vIndices);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, (void*)0);
glDisableVertexAttribArray(posLoc);
glDisableVertexAttribArray(colLoc);
Vertices are processed via a series of Shaders
Data layout for vertex array was specified by
glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *offset)