Hi,

I am now working on a project of augmented reality. To make it work, I have to 
make osg drawing on a transparent background . (The view below osg is camera 
capture.) 

I use setClearColor as follows, this code really works on the older version of 
osg 3.1.4 with opengles 1.1. But when I change to osg 3.2.1 with opengles 2.0, 
it does not make a transparent background but a black one.


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



Also my shaders is as follows :
[code]    static const char gVertexShader1[] =
    "varying vec2 v_texCoord;                                         \n"
    "void main() {                                                          \n"
    "    gl_Position  = gl_ModelViewProjectionMatrix * gl_Vertex;           \n"
    "         v_texCoord   = gl_MultiTexCoord0.xy;                              
                          \n"
    "}                                                                  \n";
    
    static const char gFragmentShader1[] =
    "varying  mediump vec2 v_texCoord;                                          
                        \n"
    "uniform sampler2D sam;                                                     
                                                   \n"
    "void main() {                                                              
                                                          \n"
    "gl_FragColor = texture2D(sam, v_texCoord);                                 
                                       \n"
    "}                                                                      \n";
    osg::Shader* vShader = new osg::Shader( osg::Shader::VERTEX, gVertexShader1 
);
    osg::Shader* fShader = new osg::Shader( osg::Shader::FRAGMENT, 
gFragmentShader1 );
    
    osg::Program* program = new osg::Program;
    program->addShader( vShader );
    program->addShader( fShader );
    stateSet->setAttribute( program );[/color]

And the other code of drawing osg file:
[code]    // Init the Windata Variable that holds the handle for the Window to 
display OSG in.
    osg::ref_ptr<osgViewer::GraphicsWindowIOS::WindowData> windowData = new 
osgViewer::GraphicsWindowIOS::WindowData(self->osgView, 
osgViewer::GraphicsWindowIOS::WindowData::IGNORE_ORIENTATION, windowFactor);
    
    // Init the Windata Variable that holds the handle for the Window to 
display OSG in.
    osg::ref_ptr<osg::Referenced> windata = windowData;
    
    // Setup the traits parameters
    traits->x = 0;
    traits->y = 0;
    traits->width = m_glview.frame.size.width*windowFactor;
    traits->height = m_glview.frame.size.height*windowFactor;
    traits->depth = 16; //keep memory down, default is currently 24
    traits->alpha = 1;
    //traits->stencil = 8;
    traits->windowDecoration = false;
    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());
    
    //create the viewer
    _viewer = new osgViewer::Viewer();
    //if the context was created then attach to our viewer
    
    if(graphicsContext)
    {
        _viewer->getCamera()->setGraphicsContext(graphicsContext);
        _viewer->getCamera()->setViewport(new osg::Viewport(0, 0, 
traits->width, traits->height));
    }
[/code]

Does anybody know how to solve this problem ? 

Thank you!

Cheers,
Liu

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





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

Reply via email to