setting up opengl w/cocoa

Member
Posts: 105
Joined: 2007.03
Post: #1
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.
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #2
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Quote this message in a reply
Member
Posts: 105
Joined: 2007.03
Post: #4
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.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #5
this xcode template may give some ideas.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #6
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Texture Loading Cocoa/OpenGL ultitech 1 6,933 Jan 31, 2011 12:51 PM
Last Post: mk12
  Cocoa/OpenGL drawing full-screen problem ultitech 5 8,304 Jan 13, 2011 01:11 PM
Last Post: SethWillits
  Cocoa OpenGL clapton541 3 4,932 Aug 5, 2007 09:22 PM
Last Post: BenRose3d
  Cocoa OpenGL clapton541 3 4,533 Mar 26, 2007 03:55 AM
Last Post: MattDiamond
  Cocoa OpenGL clapton541 3 5,164 Mar 9, 2007 06:33 PM
Last Post: GolfHacker