GLEssentials

Last Revision:
Version 1.7, 2013-07-09
Changes in this version include: 1) WIth OSX demonstrate going to fullscreen and back. Add window controller and fullscreen window classes. When the user types the 'F' key, the window controller hides the non-fullscreen window, creates a fullscreen window, and sets the OpenGL view this new fullscreen window. 2) Add support for retina displays on OSX. Call [NSOpenGLView setsWantsBestResolutionOpenGLSurface:YES] at view init. Also use [NSView convertRectToBacking] in order to get the OpenGL surface size in pixels not points, allowing the app to properly set the viewport and make other pixel dimension based calculations. 3) Fix flickering on window resize on OSX. Implement the [NSOpenGView drawRect:] in our OpenGL View so that we continue rendering as resize occurs. Also implement [NSOpenGView renewGState] with a calls to [NSwindow disableScreenUpdatesUntilFlush]. This will synchronize our rendering with that of other rendering in the system and avoid flickering and tearing. 4) Fix problem where OpenGL Errors were reported after closing the window on OSX(but not quitting the app) since the display link was still active, spawning rendering without any drawable present. To fix this, add the view to the notification center for a windowWillClose event which allows us to stop the display link and terminate our rendering. 5) On OSX, add example of kCGLCECrashOnRemovedFunctions to demonstrate how we can force a crash if a legacy function is called in a Core Profile context. This allows us to quickly see erroneous usage of legacy OpenGL without having to check for errors. 6) Make iOS App Universal. 7) Simplify clean up of shaders. Delete the shader objects after they've been attach to a GLSL program, which won't actually delete the shaders until the GLSL program is delated. 8) Use auto-synthesis for properties.
(Full Revision History)
Build Requirements:
OSX version: OSX v10.7 or later, Xcode 3.1 or later; iPhone version: iOS SDK 4.0 or later
Runtime Requirements:
OSX version: OSX v10.6 or later, OSX 10.7 or later to use OpenGL 3.2; iOS version: iOS 4.0 or later (with OpenGL ES 2.0 support)

This sample provides examples of some essential techniques for using the OpenGL and OpenGL ES API. It includes usages of Vertex Buffer Objects (VBOs), Vertex Array Objects (VAOs), Framebuffer Objects (FBO), and GLSL Program Objects. It creates a VAO and VBOs from model data loaded in. It then creates a texture for the model from image data and GLSL shaders from source also loaded in. Finally, it creates an FBO and texture to render a reflection of the model. It uses an environment mapping GLSL program to apply the reflection texture to a plane.

This sample also demonstrates sharing of OSX OpenGL with iOS OpenGL ES source code. Additionally, it demonstrates how to obtain and use an OpenGL 3.2 rendering context on OSX 10.7 or later.

Many of these techniques were described in the "OpenGL Essential Design Practices" session from WWDC 2010.