-1

I have followed this guide.

Whereas I sincerely failed to understand what it says at point 13, I just have opened the pane of the inspector, but it doesn't say what attributes to set. However, I have copied and pasted the code in the proper classes. But it appears a normal window, without the triangle draw, just like when I make a normal program in Objective-C having an empty window.

Edit:

I thought that the problem was the initialization of the window, so I have written an awakeFromNib method to make the drawRect method start:

- (void) awakeFromNib
{
    NSRect rect=NSMakeRect(100.0, 100.0, 100.0, 100.0);
    [self drawRect: rect];
}

But at the first instruction of drawRect I get an EXC_BAD_ACCESS exception

glClearColor(0, 0, 0, 0);

Maybe the window is not initialized properly?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187
  • 1
    What are you having trouble with? I don't see a question in the post above. What have you failed to understand in step 13? – user1118321 Apr 09 '12 at 03:48
  • The problem is that the window doesn't contain the triangle, is an empty window, I'l post the screenshot later.At point 13 says: "If you need additional attributes, you need to set them programmatically.".Well I haven't understood how to set attributes. – Ramy Al Zuhouri Apr 09 '12 at 11:06
  • Step 13 isn't critical. It's just suggesting you familiarize yourself with the renderer and buffer attributes that can be set via IB. There's nothing you need to do at that step. As to why nothing's rendering, I guess just review the steps and make sure you did each correctly. Hmm, I can't check now but I wonder if IB sets NSOpenGLView instances to use the Core 3.2 profile by default. For that sample code, you want the legacy profile. – Ken Thomases Apr 09 '12 at 16:21
  • I don't know how to see the version, however I tried to modify the code.I get an EXC_BAD_ACCESS exception (I edited the question). – Ramy Al Zuhouri Apr 09 '12 at 16:59

1 Answers1

1

You are probably segfaulting because OpenGL tries to change some state in the current context while there is no current context (because you sent -drawRect: without first setting the current context).

You shouldn't ever send -drawRect: yourself. Instead, use -setNeedsDisplay and let Cocoa set the current context and send -drawRect: for you:

- (void)awakeFromNib {
  self.needsDisplay = YES;
}