Guide to Game Development/Rendering and Game Engines/OpenGL/Drawing geometry

Drawing Geometry without color
This is how you pass the vertex data for triangles to OpenGL.

The data is specified in an array, where every three vertices represents a new triangle. In this format the data needs to be specified in the order that they will be connected.

This code could easily be altered to just pass 2D data only, to do this you'll need to change two things:
 * The array should only say the X and Y coordinate.
 * glVertexAttribPointer parameter 2 will need to be changed from 3 to 2.

Optimised Drawing of Geometry
This new version of the program passes the ids of the positions of the vertices to say how the triangles should be connected. For basic triangles that aren't connected, this is less efficient than before, how for most shapes, triangles will share vertices, this will mean that you won't need to specify 3 pieces of data (XYZ, more if color and light normals are added), you only pass an extra short for the index of the vertex. This saves on RAM as less data is needed, and for animated geometry, it will mean that less duplicate data will need to be sent to OpenGL and beyond.

Drawing Geometry with color (keeping optimisations from before)
Note: The color won't work until you set up the fragment shader. However, to setup the fragment shader you need to send the color data from the vertex shader.