How to manage objects

Objects are always used using the following steps:

  1. CREATION OpenGL associates GLuint with every single object created.
  2. BINDING OpenGL can only modify one object of each kind at a time. Therefore, you need to “bind” an object to specify that any further modification on a kind of object are gonna affect a specific one.
  3. MANIPULATION Several manipulation can be done depending on the type of object. Keep reading for further explanation.
  4. DELETION most of the objects can be delete using glDelete prefix instead of glCreate or glGen

Unbinding

The unbinding process needs one to be extra careful. Indeed, the VAO needs to be unbound first because the unbound process “saves” the state of being of the object including the bound objects. Therefore, unbinding the EBO before the VAO for example would end up detaching the EBO from the VAO which might not be the expected behavior.

VBO (Vertex Buffer Object)

Overview

A VBO (Vertex Buffer Object) is a memory buffer in which vertex data (such as positions, normals, texture coordinates)

Specs

glGenBuffers(nb, array_of_ids); // Creation of the buffers
glBindBuffer(type, id); // Binding
glBufferData(type, size, data, lifetime); // Populate the buffer with data
// See under for lifetime explanation

//UNBIND (Optional but recommended)
glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind the buffer from GL_ARRAY_BUFFER target

<aside> ⚠️ Binding the type allows you to update the values of this buffer specifically. You can only update one buffer at a time

</aside>

Lifetime

Lifetime is built by concatenating the occurrence of usage and the kind of usage in this way: GL_{OCCURRENCE}_{KIND}