Professional Documents
Culture Documents
Introduction
Lets get started on how to make a simple coloured
triangle using OpenGL
Well talk about the different pieces of the project:
Helper Libraries
See todays exercises for info on how to intialise
these libraries in order to use their functions.
Shaders
In order to draw to the screen we need to program parts of the graphics
pipeline.
In our 2D games we only need to worry about vertex shaders and
fragment shaders.
Shaders run on the graphics card in parallel. That is, each vertex or pixel is
operated on by a shader at the same time.
These are separate files that we compile into a separate shader program.
We output data from our OpenGL program and send this to the vertex shader (which
moves our vertex positions from world space into screen space).
The vertex shader then sends data to the fragment shader (which determines the
colour value of each pixel depending on many factors).
Vertex Arrays
For now, we need to store the info
for our geometry in arrays.
Well be using one for the vertex
positions, and one for the colours
There are 4 components for
position: x, y, z and w
Also 4 components for colour: red,
green, blue and alpha
glDrawArrays
Finally, we can draw our data to the screen!
We only need to specify the OpenGL primitive we
want to use, and the number of points well be using.
Er, primitive?
OpenGL Primitives
Here are the different
options we can use in
the glDrawArrays call.
Triangle Strip re-uses
the last 2 points
along with a new
point to create the
next triangle.
Next
Try to draw some different shapes
Change the colours and locations of these shapes