Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: OpenGL Prog Guide for OSX - override initWithFrame
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OpenGL Prog Guide for OSX - override initWithFrame




On 25/03/2009, at 3:45 AM, email@hidden wrote:
You should implement initWithFrame:pixelFormat: by yourself (as explained in the guide tutorial), if you want it to be called during NIB loading.

Yes, although I see that implementing the initWithFrame:pixelFormat: isn't so much the point, as the fact that the method has to be called during the initWithFrame: method, after you have obtained a pixel format.


Though, you have to download the CustomCocoaOpenGL example (http://developer.apple.com/samplecode/Custom_Cocoa_OpenGL/, in fact, in the tutorial of the guide, they say to download it and use as a reference) and read the CustomOpenGLView.h and CustomOpenGLView.m sources, because the tutorial of the guide does not display all the code, needed to implement the view.

The sample code uses the CustomOpenGLView as an abstract class, which I have not done. Neat for re-usability, but I didn't take this approach, and I thought it would be a bit strange to have two init methods in one class. So as in my original post, since the duties normally performed by initWithFrame:pixelFormat: can be handled in the initWithFrame: method, I assume that the inclusion of the initWithFrame:pixelFormat is a convention?


Here, http://developer.apple.com/qa/qa2004/qa1167.html#//apple_ref/doc/uid/DTS10003419, are explained the advantages gained using a custom OpenGL view instead of a NSOpenGLView.


Thank you for that link. I hadn't seen it before. A few reasons for using the Custom view approach are also mentioned in the guide. For myself, I just wanted to try this approach so that the process of setting up the OpenGL view could be plainly seen.

As for the guide, I would assume references to sample code are somewhat optional. Understanding the whole thing better now, I can see that all the information is in the guide. IMO, it could be clearer though, in particular:

You need to override the update and initWithFrame: methods of the NSView class.

  • update calls the update method of the NSOpenGLContext class.

  • initWithFrame:pixelFormat retains the pixel format and sets up the notification NSViewGlobalFrameDidChangeNotification. See Listing 2-6.

seems a bit confusing to me.

Thanks for pointing me in the right direction there. As always, it turned out to be not so mysterious after all.

Ian.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: OpenGL Prog Guide for OSX - override initWithFrame (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.