Posts

Showing posts from October, 2015

3.0: Giving Life to the View

Image
There are two ways to animate the scene, NSTimer and CVDisplayLink.  NSTimer is the shotgun approach.  You set the timer to go off a 100 times each second and hope that one of them is going to hit the mark and be displayed.  CVDisplayLink can be used to request a frame according to the display's refresh rate (60Hz or 60 frames per second).  Once choice is not necessarily better than the other; however, a strict design choice is made when you choose one over the other.  NSTimer is innately single-threaded while CVDisplayLink is multi-threaded.  When working with OpenGL in a multi-threaded environment, you cannot make changes to the OpenGL state until you have "locked the focus" to the context you are affecting.  We're going to use the CVDisplayLink going forward, but for completeness, we're going to set up an NSTimer first. First, add a timer property to the top of the class after the other class properties. private var timer = NSTimer () Second, tell the