bool GameOver::init(){ if(!Layer::init()){ return false; } //create background createBG(); return true; }
int main(int argc, char**argv) { osg::ref_ptr<osg::Group> root = new osg::Group; root->addDescription("root node"); // set up the texture state. std::string filename = "luminance.png"; osg::Image* image = osgDB::readImageFile(filename); if (!image) { throw std::ios_base::failure("Could not open image file"); } osg::Camera* bgcam = createBG( image->s(), image->t() ); root->addChild( bgcam ); { osg::Texture2D* texture = new osg::Texture2D(image); osg::Geode* geode = new osg::Geode; geode->addDescription("background texture geode"); { osg::Vec3 pos = osg::Vec3(0.0f,0.0f,0.0f); osg::Vec3 width(image->s(),0.0f,0.0); osg::Vec3 height(0.0,image->t(),0.0); osg::Geometry* geometry = osg::createTexturedQuadGeometry(pos,width,height); geode->addDrawable(geometry); osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); } bgcam->addChild(geode); } DisplaySurfaceGeometry* geometry_parameters = new DisplaySurfaceGeometry( "geom.json" ); CameraModel* cam1_params = make_real_camera_parameters(); { osg::ref_ptr<osg::Geometry> cyl = geometry_parameters->make_geom(); osg::Geode* geode = new osg::Geode; geode->addDrawable(cyl); root->addChild(geode); } osgViewer::Viewer* _viewer = new osgViewer::Viewer; _viewer->setSceneData(root.get()); // construct the viewer. _viewer->setUpViewInWindow( 32, 32, image->s(), image->t()); _viewer->realize(); float znear=0.1f; float zfar=10.0f; _viewer->getCamera()->setProjectionMatrix(cam1_params->projection(znear,zfar)); _viewer->getCamera()->setReferenceFrame(osg::Transform::ABSOLUTE_RF); osg::Matrixd viewin = cam1_params->view(); _viewer->getCamera()->setViewMatrix(viewin); _viewer->getCamera()->setClearMask( GL_DEPTH_BUFFER_BIT); osg::Matrixd proj, view; osg::Vec3 dir,m; _viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); while (!_viewer->done()) { _viewer->frame(); } return 0; }