OpenGL learning log
# Vertex buffer object (VBO)
Create a buffer, set its id to vbo
:
|
|
Then we need to activate the buffer:
|
|
And then send the data to the GPU:
|
|
Notice that this function doesn’t refer to the id of our VBO, but instead to the active array buffer.
# Shaders
Example of vertex shader creation:
|
|
Unlike VBOs, you can simply pass a reference to shader functions instead of making it active or anything like that.
There are also some magic spells to check for compilation errors. See OpenGL.
Then you have to create a program:
|
|
And use it:
|
|
Just like a vertex buffer, only one program can be active at a time.
# Attribute pointers
After sending the vertex data to the GPU, we should specify how to interpret it:
|
|
Google that up :)
A good explanation can be found here:
OpenGL - Drawing polygons.
# Vertex array object (VAO)
Creating (you should do it before creating and binding any VBO’s):
|
|
Using:
|
|
# Element buffer objects (EBO)
Sort of a “view” into a VBO. A single vertex can be used multiple times. The reason is that vertices often overlap and it’s cheaper to use indices instead of duplicating vertices.
|
|
|
|
The index buffer binding is stored within the VAO.
# Various functions
glDrawArrays
- draw stuff stored in VAO’s.
It will use the most recently bound vertex array, and the most recently used shader program to draw. If we want to draw a different set of buffers, then we need to bind that before drawing again. If no valid buffer or shader has been set in the state machine then it will crash.
glDrawBuffers
- huh? Probably for VBO’s.glDrawElements
- I think it’s for EBO’s.
glGetError
- if something goes wrong, returns the error code.