In this tutorial, you have learned the following:
Buffer objects are linear arrays of memory allocated by OpenGL. They can be used to store vertex data.
GLSL shaders are compiled into shader objects that represent the code to be executed for a single shader stage. These shader objects can be linked together to produce a program object, which represent all of the shader code to be executed during rendering.
glDrawArrays function can be used to draw triangles,
using particular buffer objects as sources for vertex data and the currently
bound program object.
Even with a simple tutorial like this, there are many things to play around with and investigate.
Change the color value set by the fragment shader to different values. Use values in the range [0, 1], and then see what happens when you go outside that range.
Change the positions of the vertex data. Keep position values in the [-1, 1] range, then see what happens when triangles go outside this range. Notice what happens when you change the Z value of the positions (note: nothing should happen while they're within the range). Keep W at 1.0 for now.
Change the values that
reshape gives to
glViewport. Make them bigger or smaller than the
window and see what happens. Shift them around to different quadrants within
reshape function so that it respects
aspect ratio. This means that the area rendered to may be smaller than the
window area. Also, try to make it so that it always centers the area within
Change the clear color, using values in the range [0, 1]. Notice how this interacts with changes to the viewport above.
Add another 3 vertices to the list, and change the number of vertices sent
glDrawArrays call from 3 to 6. Add more and play
These functions clear the current viewable area of the screen.
glClearColor sets the color to clear, while
glClear with the
GL_COLOR_BUFFER_BIT value causes the image to be
cleared with that color.
These functions are used to create and manipulate buffer objects.
glGenBuffers creates one or more buffers,
glBindBuffer attaches it to a location in the
glBufferData allocates memory and
fills this memory with data from the user into the buffer object.
These functions control vertex attribute arrays.
glEnableVertexAttribArray activates the given
deactivates the given attribute index, and
glVertexAttribPointer defines the format and
source location (buffer object) of the vertex data.
This function initiates rendering, using the currently active vertex attributes and the current program object (among other state). It causes a number of vertices to be pulled from the attribute arrays in order.
This function defines the current viewport transform. It defines as a region of the window, specified by the bottom-left position and a width/height.
These functions create a working shader object.
glCreateShader simply creates an empty shader
object of a particular shader stage.
sets strings into that object; multiple calls to this function simply
overwrite the previously set strings.
glCompileShader causes the shader object to be
compiled with the previously set strings.
glDeleteShader causes the shader object to be
These functions create a working program object.
glCreateProgram creates an empty program
glAttachShader attaches a shader object to
that program. Multiple calls attach multiple shader objects.
glLinkProgram links all of the previously
attached shaders into a complete program.
glDetachShader is used to remove a shader
object from the program object; this does not affect the behavior of the
This function causes the given program to become the current program. All rendering taking place after this call will use this program for the various shader stages. If the program 0 is given, then no program is current.
This function retrieves the attribute index of a named attribute. It takes the program to find the attribute in, and the name of the input variable of the vertex shader that the user is looking for the attribute index to.