Hi Vishwa,
the only way I can help you is giving you my code of initialization:
Try to adapt it for non your platform.
variables of instance:
osg::ref_ptr<osgViewer::Viewer> _viewer;
osg::ref_ptr<osg::MatrixTransform> _root;


- (osg::ref_ptr<osg::GraphicsContext>)createGraphicContext
{
    //create our graphics context directly so we can pass our own window 
    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;
    
    // probably you need to change this because it is for iOS
    osg::ref_ptr<osg::Referenced> windata = new 
osgViewer::GraphicsWindowIOS::WindowData(self.view, 
osgViewer::GraphicsWindowIOS::WindowData::IGNORE_ORIENTATION);
    
    // Setup the traits parameters
    traits->x = 0;
    traits->y = 0;
    traits->width = //put here the width of the window view
    traits->height = //put here the height of the window view
    traits->depth = 24; //keep memory down, you can put 16
    traits->windowDecoration = false;
    traits->alpha = 1;
    traits->doubleBuffer = true;
    traits->sharedContext = 0;
    traits->setInheritedWindowPixelFormat = true;
    //traits->windowName = "osgViewer";
    
    traits->inheritedWindowData = windata;
    
    // Create the Graphics Context
    osg::ref_ptr<osg::GraphicsContext> graphicsContext = 
osg::GraphicsContext::createGraphicsContext(traits.get());
    
    osg::setNotifyLevel(osg::INFO);
    
    return graphicsContext;
    
    
}

This is the function that initialize everything:
//here I call the function I previously defined to create graphics context 
osg::ref_ptr<osg::GraphicsContext> graphicsContext = [self 
createGraphicContext];
    
    //create the viewer    
    _viewer = new osgViewer::Viewer();
    //if the context was created correctly then attach to our viewer
    if(graphicsContext)
    {
        //suppress annoying opengl warnings //attention please, you can comment 
the lines to debug
        
graphicsContext->getState()->setCheckForGLErrors(osg::State::NEVER_CHECK_GL_ERRORS);
        _viewer->getCamera()->setGraphicsContext(graphicsContext);
        _viewer->getCamera()->setViewport(new osg::Viewport(0, 0, 
graphicsContext->getTraits()->width, graphicsContext->getTraits()->height));
    }
    else
    {
        std::cout << "ERROR: I can't create graphic context" <<std::endl;
    }
    
    //create root of the scenegraph tree
    _root = new osg::MatrixTransform();

    //what I do here is simply create new nodes representing what i want to 
draw and add them as child of _root
    [self initModels];
    
    //YOU PROBABLY DON'T NEED TO DO THIS part about shaders
    std::cout << "initing shaders" <<std::endl;
    //initialize the shaders and attach them to _root
    [self initShaders];
    

    std::cout << "setting scene data to root" <<std::endl;
    //create scene and attach it to _viewer
    _viewer->setSceneData(_root.get());
    

    //Set the threading model for the viewer,
    //Possible options are: SingleThreaded || DrawThreadPerContext
    _viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
    
    std::cout << "setup camera" <<std::endl;
    //I setup the camera parameters such as clear color, clear mask, render 
order ...
    [self setupCamera];
    
    _viewer->frame();


Then you call back _viewer->frame in a way I think you know.

The function [self setupCamera] is this:

- (void)setupCamera
{
    //set the clear color of the camera to be semitransparent
    _viewer->getCamera()->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 0.75f)); 
    //set the clear mask for the camera
    _viewer->getCamera()->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    
    _viewer->getCamera()->setRenderOrder(osg::CameraNode::PRE_RENDER);    
    
_viewer->getCamera()->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR);
    
    
}


I personally tried the semi-transparency (with that value of 0.75) and it is 
working.

I hope this helps.
Just remember to attach a Camera manipulator or manually set ViewMatrix and 
ProjectionMatrix

Cheers,
John


On Jun 6, 2012, at 10:58 AM, Robert Osfield wrote:

> Hi Vishwa,
> 
> On 6 June 2012 05:46, shekhar vishwa <vishwa.shek...@gmail.com> wrote:
>> I am trying to implement the multiple views in same window. Each view render
>> the diffrent models.User can set the view position at run time by mouse
>> dragging. If dragged view is overlapped with any view then dragged view
>> backgroud should be semi-trasparent.
>> 
>> Please suggest me to resolve this.
> 
> When you say background of the view being moved do you simply mean the
> clear colour that provides the normal background colour of a viewport
> needs to be disabled?  This is an important point as there isn't
> really any concept of "background" in OpenGL or the OSG.  Also be
> specific about what you mean by semi-transparent.  I'm guessing that
> you want to see the underlying views being the viewport, but what
> blending do you intend between the view at the front and the back?
> 
> Robert.
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to