setting up opengl w/cocoa
Ok, so I'm using cocoa (and Im still very new to it)for the opengl context and interface of my app, while the rest of the app is written in C. I've run into a minor problem, which is, when I overwrite the functions: prepare and initWithFrame, they are not called automatically (as I was under the impression that they should be). Where did I go wrong?
Also, ive been calling my input routine through mouseDown and my graphics routines through drawRect, and some other stuff through a timer, but should I init all my engine stuff in prepare? Thats what Ive been doing but it just seems not very elegant.
Also, ive been calling my input routine through mouseDown and my graphics routines through drawRect, and some other stuff through a timer, but should I init all my engine stuff in prepare? Thats what Ive been doing but it just seems not very elegant.
You're using that pre-made NSOpenGLView in Interface Builder aren't you...
I think it's better to use an NSView, and then set its custom subclass to your own NSOpenGLView -- you gotta drag your header file into IB so it knows about it first, then it'll show up in the custom class list. The one from IB calls initWithCoder I believe, instead of initWithFrame. If you use your own custom subclass it'll use initWithFrame. You won't use prepare in this case, just do your inits in initWithFrame.
I think it's better to use an NSView, and then set its custom subclass to your own NSOpenGLView -- you gotta drag your header file into IB so it knows about it first, then it'll show up in the custom class list. The one from IB calls initWithCoder I believe, instead of initWithFrame. If you use your own custom subclass it'll use initWithFrame. You won't use prepare in this case, just do your inits in initWithFrame.
Actually, I was using some code from an opengl reference book(written some time ago) which called "prepare" instead of 'prepareOpenGL', I realize now, after look at you book, the code had other stuff wrong with it too. Thanks for the link.
I'm assuming you're using a Nib with a custom view... In which case, you're not catching it because it's not being called. See: initWithCoder:. Preferably though, if you want to do some kind of initialization at app start up, stick it in -awakeFromNib; in an NSApp delegate. Likewise (if my assumptions are correct), you're missing the prepare because the Nib is instantiating the base NSOpenGLContext class, not your own. If you want to use your own, you'll need to use a custom view and override the context creation as it is instantiated.
---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Texture Loading Cocoa/OpenGL | ultitech | 1 | 5,663 |
Jan 31, 2011 12:51 PM Last Post: mk12 |
|
| Cocoa/OpenGL drawing full-screen problem | ultitech | 5 | 7,015 |
Jan 13, 2011 01:11 PM Last Post: SethWillits |
|
| Cocoa OpenGL | clapton541 | 3 | 4,518 |
Aug 5, 2007 09:22 PM Last Post: BenRose3d |
|
| Cocoa OpenGL | clapton541 | 3 | 4,116 |
Mar 26, 2007 03:55 AM Last Post: MattDiamond |
|
| Cocoa OpenGL | clapton541 | 3 | 4,702 |
Mar 9, 2007 06:33 PM Last Post: GolfHacker |
|

