[osg-users] compositeview and offscreen rendering

Peiman Shakeri peimansh2014 at gmail.com
Wed Jan 27 06:27:47 PST 2016


Hi,
this is a part of my source
I cut unnecessary part cause of clarification

Thank you!

Cheers,
Peiman

source:


Code:

void VisSystem::CreateArea( ) 
{
city=new CityArea();
city->Create(false,7);
root->addChild(weather->group);
root->addChild(weather->skyLightSource);
city->setLight(weather->skyLight);
SystemData::getInstance()->area=city;
root->addChild(city->areaGroup->getChild(0));
rootRear=new osg::Group;
rootRear->addChild(weather->skyLightSource);
rootRear->addChild(weather->group);
rootRear->addChild(city->areaGroup->getChild(1));


viewer.Create();
viewer.CreateLeftSide();
viewer.CreateRightSide();

viewer.AddfrontScene(root);
viewer.AddfrontScene(city->TrafficGroup);
viewer.AddRearScene(rootRear);
viewer.AddRearScene(city->TrafficGroup);


viewer.CreateTopview();
viewer.AddTopScene(root);
viewer.AddTopScene(city->TrafficGroup);
viewer.AddTopScene(city->TrafficGroup2);


}

void VisSystem::Run(void)
{
CreateArea();


std::string fileName;
osgDB::DatabasePager* pager = viewer.Topview->getDatabasePager();
pager->setDoPreCompile(true);
osg::ref_ptr<CustomRenderer> customRenderer = new CustomRenderer(viewer.Topview->getCamera());
viewer.Topview->getCamera()->setRenderer(customRenderer.get());
customRenderer->setCullOnly(false);
GLenum buffer = viewer.Topview->getCamera()->getGraphicsContext()->getTraits()->doubleBuffer ? GL_BACK : GL_FRONT;

viewer.TopRTT->RTTCam->setDrawBuffer(buffer);
viewer.TopRTT->RTTCam->setReadBuffer(buffer);

const osg::FrameStamp* fs2 = viewer.Topview->getFrameStamp();

osg::ref_ptr<osg::Image> posterImage = 0;
posterImage = new osg::Image;

bool outputPoster = true, outputTiles = false;
int tileWidth = 640, tileHeight = 480;
int posterWidth = 640, posterHeight = 480;
int numCameras = 1;
std::string posterName = "poster.bmp", extName = "bmp";
char filename[50];
int i=1;


IplImage *iplimg = cvCreateImage(CvSize(640,480),IPL_DEPTH_8U,3);

CvSize size;
int isColor = 1;
int fps     = 25;  // or 30

size.width = 640;
size.height = 480;

CvVideoWriter *writer = cvCreateVideoWriter(
"D:\\PEIMAN\\video\\test.avi",
CV_FOURCC('P','I','M','1'),//CV_FOURCC('I','Y','U','V'), // VIDEO CODEC
fps,
size);

while(writer == NULL)
{
writer = cvCreateVideoWriter(
"D:\\PEIMAN\\video\\test.avi",
CV_FOURCC('P','I','M','1'),//CV_FOURCC('I','Y','U','V'), // VIDEO CODEC
fps,
size);

}

viewer.viewer.realize();
viewer.viewer.stopThreading();
viewer.Topview->getCamera()->getGraphicsContext()->releaseContext();
viewer.viewer.startThreading();

while(!viewer.viewer.done())
{
//updating stuff

viewer.viewer.frame();


std::ostringstream os;
std::string snum;
os<<fs2->getFrameNumber();
snum=os.str();
fileName="D:\\PEIMAN\\image\\poster"+snum+".bmp";
char* Fname=new char[fileName.size()+1];
std::copy(fileName.begin(),fileName.end(),Fname);
Fname[fileName.size()]='\0';
std::cout<<Fname<<std::endl;	
viewer.viewer.renderingTraversals();
viewer.Topview->getCamera()->setFinalDrawCallback( new WindowCaptureCallback(buffer, fileName,posterImage.get()));

if ( (fs2->getFrameNumber()%2)==0 )
{
 
iplimg->imageData=(char*)posterImage->data();
cvCvtColor(iplimg,iplimg,CV_BGR2RGB);
cvFlip(iplimg, iplimg, 0);
cvWriteFrame(writer,iplimg);

}




}

cvReleaseVideoWriter(&writer);
cvReleaseImage(&iplimg);

}





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








More information about the osg-users mailing list