NSOpenGLView subclass not overriding super?

Post: #1
My game uses a subclass of NSOpenGLView in a window, set as the window's initialFirstResponder. I'm having two issues, which seem to be connected: I can't override any of init, initWithRect:, initWithRect: pixelFormat:, and I can't get keyDown: to do anything either. It's as if the code's not there; whatever I put in them is completely ignored, not even log functions called.
What makes this really weird is that mouseUp, prepareOpenGL, drawRect, reshape, dealloc, etc, are all being called and overridden just fine. Anyone know what might be wrong here? Annoyed
Posts: 1,560
Joined: 2003.10
Post: #2
As I recall, this is an issue that can be worked around by telling Interface Builder that your NSOpenGLView subclass is actually an NSView subclass.
Posts: 1,140
Joined: 2005.07
Post: #3
Override the initWithCoder: method, since that's what's actually called with the nib. For keyDown, does it still not work after you click on the view? Also, did you make sure that you set the custom class in the NIB to your custom NSOpenGLView?
Post: #4
Yes, it still doesn't work after clicking – the mouseUp event fires, but no key events before or after. And the one in the NIB is definitely my custom view – all the graphics code works, just not the inits or the keys.
initWithCoder does get called, though; thanks on that. Smile
Posts: 87
Joined: 2006.08
Post: #5
As others have pointed out, initWithFrame isn't being called, beacause initWithCoder is being called instead (as the OpenGL view was archived by IB).

To get around this, drag an NSView into your window in IB, rather than NSOpenGLView, and set the custom subclass as normal.

You're not receiving KeyDown events, because your subclass must include the following.

- (BOOL)acceptsFirstResponder
    return YES;

- (BOOL)becomeFirstResponder
    return  YES;

- (BOOL)resignFirstResponder
    return YES;
Post: #6
Aha! Works. Still having initWithCoder called, but I can set the pixel format from there so all's still well. Thanks for your help. Smile
Posts: 5,143
Joined: 2002.04
Thread Closed 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Super Mario Galaxy Physics SethWillits 0 2,487 Mar 27, 2008 11:38 AM
Last Post: SethWillits
  Get super triangle/bounding triangle of points Danny77uk 12 7,611 Mar 15, 2008 12:30 PM
Last Post: Danny77uk
  drawRect in NSOpenGLView help fakeOne 3 4,234 Sep 3, 2006 09:04 AM
Last Post: Xenos
  Problems with rendering using NSOpenGLView wyrmmage 3 3,281 Aug 24, 2006 08:27 AM
Last Post: wyrmmage
  Full-screen with NSOpenGLView not working forseti 9 5,322 Jun 24, 2002 01:53 AM
Last Post: forseti