1

I have a NSOpenGLView object within a floating NSPanel of which I render an image using glDrawPixels. Everything works fine until the window gets resized. I've prevented resizing by returning a fixed size when the resize function of the NSPanel object is called, but when the cursor click is on the edge of the window and attempts to resize the window, the window doesn't resize but after holding on for a few seconds, the automatic update for the OpenGL view stops getting called.

Below are a simplified list of steps:

  1. drawRect called automatically
  2. User attempts to resize window (click & drag for a few seconds)
  3. drawRect stops getting called automatically. (setNeedsDisplay or [openglcontext update] in the reshape function doesn't help)

My OpenGLContext is setup with the following format:

NSOpenGLPFANoRecovery,
NSOpenGLPFAWindow,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 2,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFAAccumSize, 0, 0

Within drawRect:

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
[[self openGLContext] makeCurrentContext];
glOrtho(0, self.frame.size.width, 0, self.frame.size.height, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
// Drawing code here.
[[self openGLContext] flushBuffer];

Does anyone know a solution to get the automatic updating of drawRect to be restarted? I know that alternatively I can get rid of the automatic updating completely and call it myself using the NSNotificationCenter or using a NSTimer, but I would prefer if I could use the default OpenGL context and default updating methods. Thanks in advance for any help!

--------- EDIT -----------

I found a possible solution to the above problem but I realise there was another problem whereby the update would randomly stop abruptly. The problem to the above solution isn't a graceful one but it works. I basically disabled the window style mask that enables the resize mask. Anyone has any ideas why the drawRect would stop randomly? Sometimes it renders fully but sometimes it freezes and never continues.

Sev
  • 4,858
  • 1
  • 14
  • 11
  • Did you manage to find a solution for the drawRect random stops? – Mark S May 28 '14 at 11:07
  • @MarkS yes, I completed the project awhile back so I can't really remember what was it exactly I did but I believe I got it to work by using a timer on top of the auto refresh because if I used one way without the other something crops up, so I ended up just letting them both run their ways. Performance didn't drop noticeably so I left it as that. – Sev Jul 05 '14 at 09:35

0 Answers0