Re: [osg-users] Why to reset OSG settings every time while rendering in Android

2012-09-24 Thread Koduri Lakshmi
Hi,

I came to know that the QCAR::Renderer::getInstance().drawVideoBackground() 
statement clears the OpenGLES context. I think this is the reason to reset the 
OSG setting every time.

I tried to restore the  OpenGLES context as follows. Store the State object at 
initial time and restore it after every render (viewer-frame()).
 But still I am not able to see model with background.

in initOsgWindow(int sW,int sH) (calling only once) function


Code:
prevStateSet = new osg::StateSet();

_viewer-getCamera()-getGraphicsContext()-getState()-captureCurrentState(*prevStateSet.get());
 



After render (viewer-frame()) I wrotet he code as follows


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



Even after this I am not getting model.

In the similar way I reseted the Graphics context (getGraphicsContext from 
camera at init and reset after render). But this too not working.

Can anyone please help me what to do?


... 

Thank you!

Cheers,
Koduri

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




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


Re: [osg-users] Why to reset OSG settings every time while rendering in Android

2012-09-22 Thread Koduri Lakshmi
Hi,

I got the mistake but not able to fix it. I am using a 3rd Party AR library 
(QCAR).
It is setting the background with a statement 

QCAR::Renderer::getInstance().drawVideoBackground();. If I comment this line 
then the model remains forever on screen but there is no background.

If I remove comments QCAR::Renderer::getInstance().drawVideoBackground(); and 
called OSG settings (initOsgWindow in the previous post) then the model 
displayes forever on screen but  wrong animations.

Why model is not on screen if I enable camera as background.

Can you please guide me how to solve this problem.
... 

Thank you!

Cheers,
Koduri

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




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


[osg-users] Why to reset OSG settings every time while rendering in Android

2012-09-21 Thread Koduri Lakshmi
Hi,


Hi,

I am new to Android programming. I followed the osgAndroidExampleGLES1 and 
developed a small example. It is working well but have a small issue.

First of all I will give my complete code here




Code:
#includeosgModel.hpp

OsgMainApp osgM;

void OsgMainApp::readModel()
{

loadedModel = osgDB::readNodeFile(/mnt/sdcard/OSG/Piller.osg);
if (loadedModel == 0) 
{
LOG(Model not loaded);
}
else 
{   
LOG(Model loaded);


  loadedModel-setName(/mnt/sdcard/OSG/Piller.osg);


}
 
  
}
void OsgMainApp::initOsgWindow(int sW,int sH)
{
  
x=0;
y=0;

width=sW;
height=sH;


_viewer = new osgViewer::Viewer();
_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-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;
trans=new osg::MatrixTransform();

trans-addChild(loadedModel.get());
modelSwitch-addChild(trans.get());   
_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);
  
}
void OsgMainApp::renderOsg(osg::Matrix mat)
{
modelSwitch-setAllChildrenOff(); 
modelSwitch-setChildValue(trans,1);

osg::Vec3f tr,scal;
osg::Quat rot,so,rot1,rot2;
mat.decompose(tr,rot,scal,so);

rot1=rot;
rot2=rot;

rot.makeRotate(osg::DegreesToRadians(45.0),1,0,0);
rot2.makeRotate(osg::DegreesToRadians(180.0),0,1,0);

trans-preMult(osg::Matrix::rotate(rot1));
trans-preMult(osg::Matrix::rotate(rot));
trans-preMult(osg::Matrix::rotate(rot2));
//trans-preMult(osg::Matrix::scale(osg::Vec3(0.5,0.5,0.5)));
_viewer-frame();
}

JNIEXPORT void JNICALL
Java_com_Samples_initApplicationNative(
JNIEnv* env, jobject obj, jint width, jint height)
{
screenWidth = width;
screenHeight = height;

  osgM.initOsgWindow(screenWidth,screenHeight);
  osgM.readModel();

}
JNIEXPORT void JNICALL
Java_com_Samples_renderer(
JNIEnv* env, jobject obj, jint width, jint height)
{
//osgM.initOsgWindow(screenWidth,screenHeight); //ERROR IS WITH THIS
osg::Matrix mat;
mat=osg::Matrix::scale(osg::Vec3(1.5,1.5,1.5));
osgM.renderOsg(mat);

}



In this code I called initOsgWindow and readModel in 
Java_com_Samples_initApplicationNative. 
In Java_com_Samples_renderer function I am calling renderOsg. If I call 
only this function then the
model is not appearing on the screen. If I call initosgWindow also then the 
model appears on the
screen. But my model has some animation so the animation is playing incorrect 
as the osg is setting
every time.

I have gone through the osgAndroidExampleGLES1 several times. But I am not 
able to figure out the error?

What could be the mistake to reset the osg settings every time?

  

... 

Thank you!

Cheers,
Koduri

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