Add the following code to your existing OpenGL application:
To build, ensure you link to GLU. (Linux: GLU, Windows: glu32, MacOS: included when linking -framework OpenGL).
OpenGL functions don't directly return errors - instead, they generally return void and store the errors in the driver. In order to discover that any errors have occured, you must call glGetError(). This function prints out all errors currently recorded, clearing them, then returns true if there were any errors. Try adding the following after every gl() function call in your program to catch errors quickly:
assert (!GLHadError());
Calling glGetError() inside a glBegin()/glEnd() pair is invalid and will actually cause an error!
glGetError() may be rather slow, so it should only be used so heavily in debug mode - putting GLHadError() inside an assertion ensures these calls are removed when compiling in release modes.