Hi,

I'm trying to render a scene onto a UIView that's part of a UIViewController, 
so that I can have iOS UI overlay on top of the OSG view.
I tried to achieve this by using the GraphicsWindowIOS class and binding it to 
my internal view. This works fine except for one issue, the scene seems 
stretched horizontally (in landscape orientation), even though its rendered at 
fullscreen and there's no resizing happening.
This is the relevant part of the code I'm using: 

Code:

        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;
        CGRect lFrame = [self.osgView convertRect:self.osgView.frame 
fromView:[UIApplication sharedApplication].keyWindow];
        unsigned int w = lFrame.size.width * [[UIScreen mainScreen] scale];
        unsigned int h = lFrame.size.height * [[UIScreen mainScreen] scale];

    osg::DisplaySettings* settings = osg::DisplaySettings::instance();
    settings->setNumMultiSamples(4);
    
    osg::ref_ptr<osgViewer::GraphicsWindowIOS::WindowData> windata = new 
osgViewer::GraphicsWindowIOS::WindowData(self.osgView, 
osgViewer::GraphicsWindowIOS::WindowData::LANDSCAPE_LEFT_ORIENTATION, -1.0f);

        // Setup the traits parameters
        traits->x = lFrame.origin.x * [[UIScreen mainScreen] scale];
        traits->y = lFrame.origin.y * [[UIScreen mainScreen] scale];
        traits->width = w;
        traits->height = h;
    
        traits->windowDecoration = false;
        traits->doubleBuffer = true;
        traits->sharedContext = 0;
        traits->setInheritedWindowPixelFormat = false;
    traits->inheritedWindowData = windata;
    
        // Create the Graphics Context
        osg::ref_ptr<osg::GraphicsContext> graphicsContext = 
osg::GraphicsContext::createGraphicsContext(traits.get());
        
    _root = new osg::MatrixTransform();

    osg::ref_ptr<osg::Node> model = (osgDB::readNodeFile("full.ive"));
    _root->addChild(model);
        _viewer = new osgViewer::Viewer();
        

        if(graphicsContext)
        {
                _viewer->getCamera()->setGraphicsContext(graphicsContext);
                _viewer->getCamera()->setViewport(new osg::Viewport(traits->x, 
traits->y, traits->width, traits->height));
        }
        
        _viewer->setSceneData(_root.get());
    _cameraManipulator = new osgGA::MultiTouchTrackballManipulator();
        _viewer->setCameraManipulator(_cameraManipulator);
        _viewer->realize();
                
        // draw a frame
        _viewer->frame();




Here are my insights so far:
I tried playing with the traits parameters and that had no effect.
Using view.bounds or just view.frame as the lFrame also has no effect.
As I'm testing this on an iPhone 5, the only scale parameter from the OS that 
would get the right value was [[UIScreen mainScreen] scale], using 
view.contentScaleFactor returned 1 which was incorrect.

The most import thing I noticed was that if I do not use a graphics context 
(for example by commenting out the setGraphicsContext line) the view appears on 
the entire screen (like before) but with the correct aspect ratio, again, even 
though there is seemingly no difference in the view's size.

I'm relatively new to OSG and I've been struggling with this issue for a couple 
of days now so any tips on how to fix it will be greatly appreciated.

Thank you!
[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=55456#55456





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to