Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
[build] Why Restoring OpenGL currentState is not working with OpenGLES2 but working with GLES1
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Koduri Lakshmi  
View profile  
 More options Nov 10 2012, 2:07 am
From: "Koduri Lakshmi" <ankiredd...@gmail.com>
Date: Sat, 10 Nov 2012 08:07:20 +0100
Local: Sat, Nov 10 2012 2:07 am
Subject: [osg-users] [build] Why Restoring OpenGL currentState is not working with OpenGLES2 but working with GLES1
Hi,

I am using a 3rd party lib(QCAR) with OSG on Android. This lib clears OpenGLES graphics  context every time after rendering a frame. So the model renders only once (first time) and disappears  on the viewer. So to preserve graphics context i did as follows

---> Created Embeded View
---> Captured current Graphics context as follws

Code:
        m_lastStateSet = new osg::StateSet();
_viewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState (*m_lastStateSet.get());

---> In RendererFrame function
      ---> Restore graphics context as follows

Code:
    osgState = _viewer->getCamera()->getGraphicsContext()->getState();
    osgState->reset();
    osgState->apply(m_lastStateSet.get());

    ---> render Frame Code

    ----> Save the current state of the graphics context as follows

Code:
_viewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState (*m_lastStateSet.get());

This works fine with OpenGLES1. The same is not working if I build the same code with OpenGLES2 version.

Can you please help me what could be the mistake.

Here is the complete code

OSG INIT Function

Code:
 void OsgApp::initOsgWindow(int sW,int sH)
     {
_viewer = new osgViewer::Viewer();
        embeddedWindow=_viewer->setUpViewerAsEmbeddedInWindow(x, y, width, height);
          _root = new osg::Group();

        _viewer->realize();
        _state = _root->getOrCreateStateSet();
        _state->setMode(GL_LIGHTING, osg::StateAttribute::ON);
        _state->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
        _state->setMode(GL_CULL_FACE, osg::StateAttribute::ON);

        //_viewer->setSceneData(_root.get());

         _viewer->addEventHandler(new osgViewer::StatsHandler);
        _viewer->addEventHandler(new osgGA::StateSetManipulator(_viewer->getCamera()->getOrCreateStateSet()));
        _viewer->addEventHandler(new osgViewer::ThreadingHandler);
        _viewer->addEventHandler(new osgViewer::LODScaleHandler);

        _manipulator = new osgGA::KeySwitchMatrixManipulator;

        _manipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
        _manipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
        _manipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
        _manipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
        _manipulator->addMatrixManipulator( '5', "Orbit", new osgGA::OrbitManipulator() );
        _manipulator->addMatrixManipulator( '6', "FirstPerson", new osgGA::FirstPersonManipulator() );
        _manipulator->addMatrixManipulator( '7', "Spherical", new osgGA::SphericalManipulator() );

        _viewer->setCameraManipulator( _manipulator.get() );

        _viewer->getViewerStats()->collectStats("scene", true);

    _viewer->getCamera()->setViewport(0,0,sW, sH);

    _viewer->getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT );

        modelSwitch=new osg::Switch;

        LOG("READING Model_0");
        readModels("/mnt/sdcard/test/0.osg",MODEL_1);

  _root->addChild(modelSwitch.get());

    _viewer->setSceneData(NULL);
    _viewer->setSceneData(_root.get());
    _manipulator->getNode();
    _viewer->home();

    _viewer->getDatabasePager()->clear();
    _viewer->getDatabasePager()->registerPagedLODs(_root.get());
    _viewer->getDatabasePager()->setUpThreads(3, 1);
    _viewer->getDatabasePager()->setTargetMaximumNumberOfPageLOD(2);
    _viewer->getDatabasePager()->setUnrefImageDataAfterApplyPolicy(true, true);

[color=red][b]m_lastStateSet = new osg::StateSet();
 _viewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState (*m_lastStateSet.get()); [/b][/color]

}

Renderer Function

Code:
void OsgApp::renderer(osg::Matrix mat)  
  {

   [color=red] [b]osgState = _viewer->getCamera()->getGraphicsContext()->getState();
    osgState->reset();
    osgState->apply(m_lastStateSet.get()); [/b][/color]

        renderModel_1(mat);

     _viewer->frame();
    [color=red][b]_viewer->getCamera()->getGraphicsContext()->getState()->captu reCurrentState(*m_lastStateSet.get());         [/b] [/color]

  }

...

Thank you!

Cheers,
Koduri

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

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Koduri Lakshmi  
View profile  
 More options Nov 16 2012, 4:37 am
From: "Koduri Lakshmi" <ankiredd...@gmail.com>
Date: Fri, 16 Nov 2012 10:37:02 +0100
Local: Fri, Nov 16 2012 4:37 am
Subject: Re: [osg-users] [build] Why Restoring OpenGL currentState is not working with OpenGLES2 but working with GLES1
Hi,

The error is not with the previous post code.

When I added the following code then the model is displayed.

Code:
 mtForMarker[idx]=new osg::MatrixTransform();

             osg::Shader * vshader = new osg::Shader(osg::Shader::VERTEX, gVertexShader );
            osg::Shader * fshader = new osg::Shader(osg::Shader::FRAGMENT, gFragmentShader );

            osg::Program * prog = new osg::Program;
           prog->addShader ( vshader );
            prog->addShader ( fshader );

            mtForMarker[idx]->getOrCreateStateSet()->setAttribute ( prog );

             mtForMarker[idx]->addChild(loadedModel[idx].get());
             modelSwitch->addChild(mtForMarker[idx].get());

              osgViewer::Viewer::Windows windows;
    _viewer->getWindows(windows);
    for(osgViewer::Viewer::Windows::iterator itr = windows.begin();itr != windows.end();++itr)
    {
      (*itr)->getState()->setUseModelViewAndProjectionUniforms(true);
      (*itr)->getState()->setUseVertexAttributeAliasing(true);
    }

This code I added from osgAndroidOpenGLES2 example.

As I am new to OSG I have two doubts

1) Why should I add the shaders in OpenGLES2 to display model. If I remove this code then the model is not displayed. OpenGLES1 dosnt have this shaders.

2) If I add this code then the textures are not applied to my model. I got  model from 3DS MAX. How can I get textures?

Can you please guide me how to get textures? If shaders are necessary to render model on Android then how can I handle textures (or any others) ? Is there any tutorial to handle this in Android?

...

Thank you!

Cheers,
Koduri

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

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »