updated code following opengl wikibook tutorial tut02.