mikeash.com: just this guy, you know?

Posted at 2006-02-23 00:00 | RSS feed (Full text feed) | Blog Index
Next article: Fluid Simulation for Dummies
Previous article: What Every Programmer Should Know
Tags: advice cocoa opengl
NSOpenGLContext and one-shot
by Mike Ash  

If you've done any OpenGL work in Cocoa, you may have noticed that OpenGL surfaces behave badly when it comes to things like miniaturization and deminiaturization to the Dock. This recently caused some big problems for me, and I finally found out how to get rid of these problems altogether. It wasn't excruciatingly hard to find, but I wanted to make a post about it here so that it could be found with words like "deminiaturization".

My problem was worse than usual because I'm using a raw NSOpenGLContext, not an NSOpenGLView. When I miniaturized the window to the Dock and then deminiaturized, my OpenGL content was gone and wouldn't redraw. While searching for the secret sauce to get it to redraw, I found out how to stop it from blanking in the first place, which is even better.

The "secret" is to turn off the "One shot" checkbox for your window in Interface Builder. This setting basically destroys your window while it's hidden, including while it's miniaturized to the Dock. Destroying the window breaks the link between your context and the window, resulting in it blanking out as it flies toward the Dock. Disabling this checkbox makes sure the window always sticking around, so that your OpenGL content looks indistinguishable from the rest.

I discovered this in this mailing list post: http://lists.apple.com/archives/mac-opengl/2003/Apr/msg00132.html

No comments:


Did you enjoy this article? I'm selling a whole book full of them. It's available for iBooks and Kindle, plus a direct download in PDF and ePub format. It's also available in paper for the old-fashioned. Click here for more information.

No comments have been posted.

Comments RSS feed for this page

Add your thoughts, post a comment:

Spam and off-topic posts will be deleted without notice. Culprits may be publicly humiliated at my sole discretion.

Name:
Web site:
Comment:
Formatting: <i> <b> <blockquote> <code>. URLs are automatically hyperlinked.
Hosted at DigitalOcean.