I’ve been trying to make a scene with OpenGL in Objective-C for weeks, and I just can’t seem to get it to work. I started with Drawing to an NSOpenGLView Class: A Tutorial, and that worked fine for me, and I was even able to expand it a little, but the the OpenGL Programming Guide leaves a sort of hole after that step. They explain the details of how to double buffer and synchronize refresh rates and all of that, but they don’t provide any actual examples of how to update your view. So currently I can draw lots of cool stuff to the screen, but once it’s there it’s just a static image. No moving, no spinning.
Does anyone know of a good, simple example of how this is actually done?
I’ve been trying to make a scene with OpenGL in Objective-C for weeks, and
Share
This is a problem I frequently encounter, and it surprises me that this crucial step isn’t part of the NSOpenGLView tutorial documentation.
You need to set up a callback timer to notify the view that it needs to be redrawn:
Notice that this happens in
awakeFromNib.The timer will fire off at an interval of 1/30, which you can change if you like.
Each time it fires, it calls a function named
idle. This function can be implemented like so:This causes the view to redraw itself every update, including your OpenGL graphics.