NSView OpenGL Oddity

Apprentice
Posts: 5
Joined: 2012.04
Post: #1
Hi,

I encountered this strange behavior that I've searched the Internet for days without finding a good answer.

Here is my OpenGL embedding scenario:

I have this NSView, say viewB, which is set to render an OpenGL scene. [NSOpenGLContext setView: viewB].

This View is put into another view, say viewA. [viewA addSubview: viewB].

when viewB is well within the bounds of viewA. The openGL scene is rendered correctly.

when viewB is partially outside the top or the right borders of viewA, the openGL scene is also rendered correctly with correct clipping of viewB by viewA.

However, when viewB is partially outside the bottom or the left borders of viewA, I see a strange offset of the OpenGL scene or viewport that put the scene origin within the bounds of viewA. ( as opposed to the expected behavior where scene origin is outside viewA and only the right/top half of the scene is visible.)

Has anyone seen this before? is it something simple that I've overlooked.

Appreciate any help. I am a newbie to both cocoa and opengl programming.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Where do you call glViewport, and what do you pass it?
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2012.04
Post: #3
glViewport( 0, 0, width of viewB, height of viewB);

This is called on each resize event of viewB.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
via
Code:
NSRect r = [viewB bounds];
glViewport(0, 0, r.size.width, r.size.height);
?
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2012.04
Post: #5
viewB is moved programmatically using

[viewB setFrame:NSMakeRect(-25, -30, width, height)];

and glViewport is set using

glViewport( 0, 0, width, height );

where width and height are given by external routine that manages the view size.
(viewB's dimension is driven by user's interactions with the program and are kept in
a global variables.)




Basically, I let uses drag a rectangle representing viewB around viewA.

When the user double click on that rectangle, I displays the view

[viewB setFrame:NSMakeRect(-25, -30, width, height)];
glViewport( 0, 0, width, height );
[viewB setHidden:NO];
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2012.04
Post: #6
side note:

This is done in a secondary thread while both views were created on the main thread.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
Confirmed independently that this happens. Not sure why or what to do about it yet.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
This is a bug (or maybe a "misfeature") in NSOpenGLView. You can reproduce it trivially simply by dragging an NSOpenGLView around in Interface Builder.

I filed Radar 11239780: NSOpenGLView clips surface when origin is outside window on your behalf, but you should probably file a bug too so you have some means of tracking it.

You can work around this behavior by altering the arguments to glViewport (and possibly your projection) to compensate.
Layer-backed NSOpenGLViews do not have this problem.
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2012.04
Post: #9
Thank you for spending time looking into this issue.

I am not familiar with Layer-backed NSView.
Setting NSView setWantsLayer to YES and the scene is rendered as garbage from frame buffer.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How would I save an NSView as a JPG? Joseph Duchesne 0 2,938 Sep 30, 2005 07:51 PM
Last Post: Joseph Duchesne
  CGL and NSView KiroNeem 1 3,208 Feb 10, 2005 12:11 PM
Last Post: OneSadCookie
  QuickTime texture oddity sealfin 4 4,446 Jan 13, 2003 09:51 AM
Last Post: sealfin