Hi Yu,
here’s a snippet of an app using osg inside a classic Cocoa-app. The trick is
to let osg create a view only and then add this view into your
NSView-hierarchy.
osg::ref_ptr<osgViewer::GraphicsWindowCocoa::WindowData> win_data = new
osgViewer::GraphicsWindowCocoa::WindowData(
osgViewer::GraphicsWindowCocoa::WindowData::CreateOnlyView |
osgViewer::GraphicsWindowCocoa::WindowData::CheckForEvents
);
// self is a NSWindow/NSView
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits();
traits->inheritedWindowData = win_data;
traits->x = 0;
traits->y = 0;
traits->width = [self frame].size.width;
traits->height = [self frame].size.height;
traits->doubleBuffer = true;
traits->vsync = true;
traits->windowDecoration = false;
traits->supportsResize = false;
// the following steps are deep inside my own app and it’s to cumbersome to
quote them here.
// 1. create the graphics-context with the traits-object
// 2. create a osg::Viewer or a osg::View and set the gc accordingly.
// 3. realize the graphics-context
// 4. after realizing the GraphicsContext you can get the created view via the
win_data-object.
openglView = win_data->getCreatedNSView();
[self addSubview: openglView];
[openglView setFrame: NSMakeRect(0, 0, [self frame].size.width, [self
frame].size.height)];
Another approach is the usage of GraphicsWindowEmbedded, here you’ll create and
control the OpenGL graphics-context by yourself.
HTH,
Stephan
On 20 Jun 2014, at 18:08, Yu Zhang <[email protected]> wrote:
> Hi Experts,
>
> Could you please provide a OS X sample in using GraphicsWindowCocoa?
>
> I need bind a cocoa window to an osgview.
>
> BTW, the osgviewerCocoa example works, it used setUpViewerAsEmbeddedInWindow
> and seems only works in single draw/cull thread mode.
>
> I tried
>
> osgViewer::GraphicsWindowCocoa::WindowData(osgViewer::GraphicsWindowCocoa::WindowData::PoseAsStandaloneApp);
>
> In a new window and displays the node but hanged, and
> osgViewer::GraphicsWindowCocoa::WindowData(osgViewer::GraphicsWindowCocoa::WindowData::CreateOnlyView);
> looks not work in my side.
>
> Macbook pro 13 late 1013, OS X 10.9.3 XCode 5.02
>
> Thank you!
>
> Cheers,
> Yu
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=59836#59836
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org