Factored out some common OpenGL code into helper functions.