Re: How to Get Image out of NSOpenGLView using offline renderer.
Re: How to Get Image out of NSOpenGLView using offline renderer.
- Subject: Re: How to Get Image out of NSOpenGLView using offline renderer.
- From: Erik Buck <email@hidden>
- Date: Thu, 1 Dec 2005 08:10:08 -0800 (PST)
In general, there is no problem scrolling an NSOpenGLView or a subclass within an NScrollView.
- You must disable copy-on-scroll because that optimization is incompatible with the OpenGL backing store (frame buffer). You probably also want to disable background drawing because it is redundant. See
<Quote>
setDrawsBackground:
Sets whether the receiver draws its background.
- (void)setDrawsBackground:(BOOL)flag
Discussion
If flag is NO, copy-on-scroll is automatically disabled.
If your NSScrollView encloses an NSClipView sending a setDrawsBackground: message with a parameter of NO to the NSScrollView has the added effect of sending the NSClipView a setCopiesOnScroll: message with a parameter of NO. The side effect of sending the setDrawsBackground: message directly to the NSClipView instead would be the appearance of "trails" (vestiges of previous drawing) in the document view as it is scrolled.
See Also
" - drawsBackground
" - copiesOnScroll (NSClipView)
" - setDrawsBackground: (NSClipView)
<End Quote>
- You must also realize that there is a fundamental difference between the way NSView coordinate systems are computed via frame and bounds vs. the 3D coordinate system of OpenGL. When a NSView is scrolled, the enclosing clip view's bounds are changed to effectively translate its subviews. The clip view's bounds size may also be changed to effectively zoom its subviews. During scrolling, the coordinate systems changes apply to the enclosing clip view and not the scroll view's document view. The -display and -lockFocus machinery of the AppKit takes care of managing the coordinate system... None of the work done by the AppKit automatically applies to the OpenGL 3D coordinate system.
The solution is quite simple: Implement your NSOpenGLView's -reshape method to call glOrtho() and set the NSOpenGLView's coordinate system equal to the rectangle returned from the NSOpenGLView's -visibleRect method. Then make any other coordinate system transformations from that. This also automatically handles zooming...
To handle resizing of the visible portion of the NSOpenGLView, use glViewport() to set the GL viewport to the enclosing clip view's frame in Window coordinates.
Finally, OpenGL is fundamentally constrained to using viewports that fit within available video memory. In practice, there are at least two frame buffers needed plus memory for textures, z-buffers etc. Therefore it is problematic to create huge GL viewports. The common solution is to use a viewport that is the same size as the visible portion of the NSOpenGLView and use normal GL coordinate system transformations to limit/adjust drawing to the visible portions of the view. In this way, giant virtual coordinate systems are possible within available physical frame buffer memory.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden