Reputation: 31
I've been trying to get the NSOpenGLView to resize correctly when resizing the window, but I keep getting weird behaviour which I cannot explain. It looks like so:
Original (What it looks like at the beginning):
After resize:
This is my resize code:
- (void)reshape
{
[super reshape];
CGLLockContext([[self openGLContext] CGLContextObj]);
NSRect viewRectPoints = [self bounds];
#if SUPPORT_RETINA_RESOLUTION
NSRect viewRectPixels = [self convertRectToBacking:viewRectPoints];
#else //if !SUPPORT_RETINA_RESOLUTION
NSRect viewRectPixels = viewRectPoints;
#endif // !SUPPORT_RETINA_RESOLUTION
[self resizeWithWidth:viewRectPixels.size.width
AndHeight:viewRectPixels.size.height];
CGLUnlockContext([[self openGLContext] CGLContextObj]);
}
- (void) resizeWithWidth:(GLuint)width AndHeight:(GLuint)height
{
glViewport(0, 0, width, height);
m_width = width;
m_height = height;
}
and I'm using: "glViewport(0, 0, m_width, m_height);" whenever I call glDrawArrays();
Can anyone help?
Upvotes: 3
Views: 454
Reputation: 6638
Seriously, in these days you might want to consider to leave NSOpenGLView
behind and move to CAOpenGLLayer
directly.
I've had too many issues with this silly class to bother any more about NSOpenGLView
and in layer backed views particularly having a CAOpenGLLayer
IMHO just gives you more flexibility - and control.
(and less bugs - try getting NSOpenGLView
to work in a layer backed view hierarchy under 10.9 or pre..).
Plus more functionality right out of the box - or at least under your finger tips (like built-in CVDisplayLink
support).
Just my 2c.
Upvotes: 0
Reputation: 3811
When resizing the window you should also set the projection matrix to reflect the new dimensions. You didn't post your setup/drawing code, but usually that looks something like:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(...); // or glFrustum(), glOrtho(), gluOrtho2D(), ...
glMatrixMode(GL_MODELVIEW);
Upvotes: 1