Adding some utility code from openglbook.com