Skip to content

Drawing in OpenGL 3.0+

2010 October 8
by Daniel

[Updated 3.40pm 8/10/2010 - minor fix to downloadable code]

Avoiding the use of the deprecated and non-core features of OpenGL is a big change for anyone used to working with earlier versions of OpenGL. A partial list of the removed functionality includes almost all the basic features:

glVertex
glBegin
glEnd
glTranslate
glRotate
glMatrixMode
glLoadIdentity
glColor
glDrawElements
glEnableClientState

also display lists, all lighting commands and the entire glu library! Big changes all round.

Instead, the principle is to upload arrays of data in buffer objects, and pass these into the pipeline.

A vertex buffer object (VBO) can contain an array of vertex position data, colour data, texture data, normals, or other values relating to a particular object. A number of these arrays (e.g. a VBO of vertex position data and another of colour data) are placed into a vertex array object (VAO), and the VAO sent to the graphics pipeline with a simple command. Setting up all these buffers is the hard part – but its a basic and small set of steps that you’ll have to carry out each time.

There is a tutorial on the OpenGL wiki to get you started here. This example uses the WGL library, and so is windows only. I’ve prepared my own version of this, which uses GLUT instead – and which should run out of the box, hopefully on a range of platforms (you’ll need to have freeglut and GLTools or GLEW installed first). I’ve included comments throughout to indicate areas where the program could be improved. You can download the code from here, or check it out online on gist at GitHub http://gist.github.com/628320

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS