本文整理汇总了C++中osg::NodeUnrecPtr::setCore方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeUnrecPtr::setCore方法的具体用法?C++ NodeUnrecPtr::setCore怎么用?C++ NodeUnrecPtr::setCore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::NodeUnrecPtr
的用法示例。
在下文中一共展示了NodeUnrecPtr::setCore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start_name
TEST_FIXTURE(FileFixture, TestNameRetention)
{
std::string start_name("node");
OSG::NodeUnrecPtr n = OSG::Node::create();
OSG::setName(n, start_name);
n->setCore(OSG::Group::create());
CHECK(!bf::exists(test_file));
OSG::SceneFileHandler::the()->write(n, test_file.native_file_string().c_str());
CHECK(bf::exists(test_file));
OSG::NodeUnrecPtr new_n =
OSG::SceneFileHandler::the()->read(test_file.native_file_string().c_str());
CHECK(new_n != NULL);
CHECK(OSG::getName(new_n) != NULL);
std::string cur_name = std::string(OSG::getName(new_n));
CHECK(cur_name == start_name);
}
示例2: initGeometries
void VTKPolyDataMapper::initGeometries(void)
{
NodeUnrecPtr pRoot = Node::create();
pRoot->setCore(Group::create());
setRoot(pRoot);
for(UInt32 i = 0; i < 4; ++i)
{
GeometryUnrecPtr pGeo = Geometry::create();
ChunkMaterialUnrecPtr pMat = ChunkMaterial::create();
MaterialChunkUnrecPtr pMatChunk = MaterialChunk::create();
GeoPnt3fPropertyUnrecPtr pPoints = GeoPnt3fProperty ::create();
GeoUInt32PropertyUnrecPtr pLengths = GeoUInt32Property ::create();
GeoUInt8PropertyUnrecPtr pTypes = GeoUInt8Property ::create();
GeoColor4fPropertyUnrecPtr pColors = GeoColor4fProperty::create();
GeoVec3fPropertyUnrecPtr pNormals = GeoVec3fProperty ::create();
if(i < 2)
{
pMatChunk->setLit(false);
}
pMatChunk->setDiffuse (OSG::Color4f(1.0, 1.0, 1.0, 1.0));
pMatChunk->setSpecular (OSG::Color4f(0.0, 0.0, 0.0, 1.0));
pMatChunk->setShininess(10.0f);
pMat->addChunk(pMatChunk);
TwoSidedLightingChunkUnrecPtr pTSLChunk =
TwoSidedLightingChunk::create();
pMat->addChunk(pTSLChunk);
pGeo->setDlistCache(false );
pGeo->setMaterial (pMat );
pGeo->setPositions (pPoints );
pGeo->setLengths (pLengths);
pGeo->setTypes (pTypes );
pGeo->setColors (pColors );
if(i > 1)
{
pGeo->setNormals(pNormals);
}
OSG::NodeUnrecPtr pGeoRoot = OSG::Node::create();
pGeoRoot->setCore (pGeo);
pGeoRoot->setTravMask(0 );
pRoot->addChild(pGeoRoot);
this->pushToGeometries (pGeo );
this->pushToMaterials (pMat );
this->pushToMaterialChunks(pMatChunk);
this->pushToPositions (pPoints );
this->pushToLength (pLengths );
this->pushToTypes (pTypes );
this->pushToColors (pColors );
this->pushToNormals (pNormals );
this->pushToGeoRoots (pGeoRoot );
}
}
示例3: doMain
//.........这里部分代码省略.........
OSG::TextureEnvChunkUnrecPtr tex_earth_night_env =
OSG::TextureEnvChunk::create();
tex_earth_night->setImage(earth_night_map_img);
tex_earth_night->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
tex_earth_night->setMagFilter(GL_LINEAR);
tex_earth_night->setWrapS(GL_REPEAT);
tex_earth_night->setWrapT(GL_REPEAT);
tex_earth_night_env->setEnvMode(GL_MODULATE);
// Read the image for the normal texture
OSG::ImageUnrecPtr earth_clouds_map_img = OSG::Image::create();
if(!earth_clouds_map_img->read("EarthClouds.jpg"))
{
fprintf(stderr, "Couldn't read texture 'EarthClouds.jpg'\n");
return 1;
}
OSG::TextureObjChunkUnrecPtr tex_earth_clouds =
OSG::TextureObjChunk::create();
OSG::TextureEnvChunkUnrecPtr tex_earth_clouds_env =
OSG::TextureEnvChunk::create();
tex_earth_clouds->setImage(earth_clouds_map_img);
tex_earth_clouds->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
tex_earth_clouds->setMagFilter(GL_LINEAR);
tex_earth_clouds->setWrapS(GL_REPEAT);
tex_earth_clouds->setWrapT(GL_REPEAT);
tex_earth_clouds_env->setEnvMode(GL_MODULATE);
_shl = OSG::ShaderProgramChunk::create();
_shl_vp = OSG::ShaderProgram::create();
_shl_fp = OSG::ShaderProgram::create();
if(!_shl_vp->readProgram("Earth.vp"))
fprintf(stderr, "Couldn't read vertex program 'Earth.vp'\n");
if(!_shl_fp->readProgram("Earth.fp"))
fprintf(stderr, "Couldn't read fragment program 'Earth.fp'\n");
_shl_vp->setShaderType(GL_VERTEX_SHADER);
_shl_fp->setShaderType(GL_FRAGMENT_SHADER);
_shl->addVertexShader (_shl_vp);
_shl->addFragmentShader(_shl_fp);
_shl_fp->addUniformVariable("EarthDay", 0);
_shl_fp->addUniformVariable("EarthNight", 1);
_shl_fp->addUniformVariable("EarthCloudGloss", 2);
_shl_vp->addUniformVariable("season", 0.0f);
_shl_vp->addUniformVariable("cos_time_0_2PI", -0.406652f);
_shl_vp->addUniformVariable("sin_time_0_2PI", -0.913583f);
// _shl->setUniformParameter("foo", -0.913583f);
cmat->addChunk(_shl);
cmat->addChunk(tex_earth);
cmat->addChunk(tex_earth_env);
cmat->addChunk(tex_earth_night);
cmat->addChunk(tex_earth_night_env);
cmat->addChunk(tex_earth_clouds);
cmat->addChunk(tex_earth_clouds_env);
// create root node
_scene = OSG::Node::create();
OSG::GeometryUnrecPtr geo = OSG::makeLatLongSphereGeo (100, 100, 1.0);
geo->setMaterial(cmat);
OSG::NodeUnrecPtr torus = OSG::Node::create();
torus->setCore(geo);
// add torus to scene
OSG::GroupUnrecPtr group = OSG::Group::create();
_scene->setCore(group);
_scene->addChild(torus);
// create the SimpleSceneManager helper
_mgr = OSG::SimpleSceneManager::create();
// tell the manager what to manage
_mgr->setWindow(gwin );
_mgr->setRoot(_scene);
// show the whole scene
_mgr->showAll();
return 0;
}
示例4: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
printf("Usage: testCGShader <filename.vp> <filename.fp>\n");
if( argc < 3 )
return 0;
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->setSize( 800, 800 );
gwin->init();
// Create the shader material
OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create();
OSG::MaterialChunkUnrecPtr matc = OSG::MaterialChunk::create();
matc->setAmbient(OSG::Color4f(0.1, 0.1, 0.1, 1.0));
matc->setDiffuse(OSG::Color4f(0.3, 0.3, 0.3, 1.0));
matc->setSpecular(OSG::Color4f(0.8, 0.8, 0.8, 1.0));
matc->setShininess(100);
matc->setLit(true);
OSG::SHLChunkUnrecPtr shl = OSG::SHLChunk::create();
shl->readVertexProgram(argv[1]);
shl->readFragmentProgram(argv[2]);
cmat->addChunk(shl);
// create root node
_scene = OSG::Node::create();
// create torus
OSG::GeometryUnrecPtr geo = OSG::makeTorusGeo(.8, 1.8, 128, 128);
geo->setMaterial(cmat);
OSG::NodeUnrecPtr torus = OSG::Node::create();
torus->setCore(geo);
// add torus to scene
OSG::GroupUnrecPtr group = OSG::Group::create();
_scene->setCore(group);
_scene->addChild(torus);
// create the SimpleSceneManager helper
_mgr = OSG::SimpleSceneManager::create();
// tell the manager what to manage
_mgr->setWindow(gwin );
_mgr->setRoot(_scene);
/*
// create point headlight
_mgr->turnHeadlightOff();
NodePtr headlight = _mgr->getHighlight();
PointLightPtr light = PointLight::create();
beginEditCP(light);
light->setAmbient (.3, .3, .3, 1);
light->setDiffuse ( 1, 1, 1, 1);
light->setSpecular ( 1, 1, 1, 1);
light->setBeacon (_mgr->getCamera()->getBeacon());
endEditCP(light);
beginEditCP(_scene);
_scene->setCore(light);
endEditCP(_scene);
*/
// show the whole scene
_mgr->showAll();
// GLUT main loop
glutMainLoop();
return 0;
}
示例5: init
int init(int argc, char **argv)
{
OSG::osgInit(argc,argv);
// GLUT init
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG");
glutKeyboardFunc(key);
glutVisibilityFunc(vis);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIdleFunc(display);
// OSG
OSG::SceneFileHandler::the()->print();
// create the graph
// beacon for camera and light
OSG::NodeUnrecPtr b1n = OSG::Node::create();
OSG::GroupUnrecPtr b1 = OSG::Group::create();
b1n->setCore(b1);
// transformation
OSG::NodeUnrecPtr t1n = OSG::Node::create();
OSG::TransformUnrecPtr t1 = OSG::Transform::create();
t1n->setCore (t1 );
t1n->addChild(b1n);
cam_trans = t1;
// light
OSG::NodeUnrecPtr dlight = OSG::Node::create();
OSG::DirectionalLightUnrecPtr dl = OSG::DirectionalLight::create();
dlight->setCore(dl);
dl->setAmbient (0.0, 0.0, 0.0, 1.0);
dl->setDiffuse (0.8, 0.8, 0.8, 1.0);
dl->setDirection(0.0, 0.0, 1.0 );
dl->setBeacon (b1n );
// root
OSG::NodeUnrecPtr root = OSG::Node::create();
OSG::GroupUnrecPtr gr1 = OSG::Group::create();
root->setCore (gr1 );
root->addChild(t1n );
root->addChild(dlight);
// Load the file
OSG::NodeUnrecPtr file = NULL;
if(argc > 1)
{
file = OSG::SceneFileHandler::the()->read(argv[1], NULL);
}
if(file == NULL)
{
std::cerr << "Couldn't load file, ignoring" << std::endl;
//file = OSG::makeSphere(4, 2.0);
file = OSG::Node::create();
OSG::AlgorithmStageUnrecPtr pStage = OSG::AlgorithmStage::create();
file->setCore(pStage);
pAlgo = OSG::GPUVolRTV2::create();
pStage->setAlgorithm(pAlgo);
// fix/freeze the node volume
file->editVolume().setStatic(true);
file->editVolume().setBounds( 0.f, 0.f, 0.f,
1.f, 1.f, 1.f);
}
OSG::commitChanges();
file->updateVolume();
OSG::Vec3f min,max;
file->getVolume().getBounds( min, max );
std::cout << "Volume: from " << min << " to " << max << std::endl;
//.........这里部分代码省略.........
示例6: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
printf("Usage: testCGShader [normal map filename]\n");
const char *normal_map_img_name = "opensg_logoDOT3.png";
OSG::Color4f tmp;
if( argc > 1 )
normal_map_img_name = argv[1];
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->setSize( 800, 800 );
gwin->init();
// Create the shader material
// Read the image for the normal texture
OSG::ImageUnrecPtr normal_map_img = OSG::Image::create();
if(!normal_map_img->read(normal_map_img_name))
{
fprintf(stderr, "Couldn't read normalmap texture '%s'!\n", normal_map_img_name);
return 1;
}
OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create();
OSG::MaterialChunkUnrecPtr matc = OSG::MaterialChunk::create();
matc->setAmbient(OSG::Color4f(0.1, 0.1, 0.1, 1.0));
matc->setDiffuse(OSG::Color4f(0.3, 0.3, 0.3, 1.0));
matc->setSpecular(OSG::Color4f(0.8, 0.8, 0.8, 1.0));
matc->setShininess(100);
matc->setLit(true);
OSG::SHLChunkUnrecPtr shl = OSG::SHLChunk::create();
shl->setVertexProgram(_vp_program);
shl->setFragmentProgram(_fp_program);
OSG::TextureObjChunkUnrecPtr tex_normal_map =
OSG::TextureObjChunk::create();
OSG::TextureEnvChunkUnrecPtr tex_normal_map_env =
OSG::TextureEnvChunk::create();
tex_normal_map->setImage(normal_map_img);
tex_normal_map->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
tex_normal_map->setMagFilter(GL_LINEAR);
tex_normal_map->setWrapS(GL_REPEAT);
tex_normal_map->setWrapT(GL_REPEAT);
tex_normal_map_env->setEnvMode(GL_MODULATE);
//cmat->addChunk(matc);
cmat->addChunk(shl);
cmat->addChunk(tex_normal_map);
cmat->addChunk(tex_normal_map_env);
// create root node
_scene = OSG::Node::create();
// create geometry
//GeometryPtr geo = makeLatLongSphereGeo (100, 100, 1.0);
OSG::GeometryUnrecPtr geo = OSG::makePlaneGeo(1.0, 1.0, 100, 100);
geo->setMaterial(cmat);
OSG::NodeUnrecPtr torus = OSG::Node::create();
torus->setCore(geo);
// add torus to scene
OSG::GroupUnrecPtr group = OSG::Group::create();
_scene->setCore(group);
_scene->addChild(torus);
// create the SimpleSceneManager helper
_mgr = new OSG::SimpleSceneManager;
// tell the manager what to manage
_mgr->setWindow(gwin );
_mgr->setRoot(_scene);
/*
// create point headlight
_mgr->turnHeadlightOff();
NodePtr headlight = _mgr->getHighlight();
PointLightPtr light = PointLight::create();
beginEditCP(light);
light->setAmbient (.3, .3, .3, 1);
light->setDiffuse ( 1, 1, 1, 1);
light->setSpecular ( 1, 1, 1, 1);
//.........这里部分代码省略.........
示例7: init
void init(std::vector<std::string> &filenames)
{
size_t i;
OSG::DirectionalLightUnrecPtr dl;
OSG::Real32 x,y,z;
OSG::BoxVolume volume;
OSG::Vec3f min,max;
OSG::Vec3f size;
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
// GLint twoSide = 1;
// glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE,&twoSide);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
// create the graph
// beacon for camera and light
OSG::NodeUnrecPtr b1n = OSG::Node::create();
OSG::GroupUnrecPtr b1 = OSG::Group::create();
b1n->setCore( b1 );
// transformation
OSG::NodeUnrecPtr t1n = OSG::Node::create();
OSG::TransformUnrecPtr t1 = OSG::Transform::create();
t1n->setCore( t1 );
t1n->addChild( b1n );
cam_trans = t1;
// light
OSG::NodeUnrecPtr dlight = OSG::Node::create();
dl = OSG::DirectionalLight::create();
dlight->setCore( dl );
dl->setAmbient( .3f, .3f, .3f, 1 );
dl->setDiffuse( 1, 1, 1, 1 );
dl->setDirection(0,0,1);
dl->setBeacon( b1n);
// root
root = OSG::Node::create();
OSG::GroupUnrecPtr gr1 = OSG::Group::create();
root->setCore( gr1 );
root->addChild( t1n );
root->addChild( dlight );
// Load the file
OSG::NodeUnrecPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
OSG::NodeUnrecPtr file;
for(i=0;i<filenames.size();i++)
{
file = OSG::SceneFileHandler::the()->read(filenames[i].c_str(),0);
if(file != NULL)
scene->addChild(file);
else
std::cerr << "Couldn't load file, ignoring " << filenames[i] << std::endl;
}
if ( filenames.size()==0 )
{
file = OSG::makeTorus( .5, 2, 16, 16 );
scene->addChild(file);
// scene->addChild(makeBox(.6,.6,.6,5,5,5));
}
prepareSceneGraph(scene);
OSG::Thread::getCurrentChangeList()->commitChanges();
scene->invalidateVolume();
scene->updateVolume();
volume=scene->getVolume();
volume.getBounds(min,max);
size = max-min;
if(ca>0)
{
if(cb==-1)
cb=ca;
if(cc==-1)
cc=cb;
OSG::NodeUnrecPtr node;
OSG::NodeUnrecPtr geoNode;
OSG::TransformUnrecPtr trans;
for(x=-ca/2.0 ; x<ca/2.0 ; x++)
for(y=-cb/2.0 ; y<cb/2.0 ; y++)
for(z=-cc/2.0 ; z<cc/2.0 ; z++)
{
trans=OSG::Transform::create();
node=OSG::Node::create();
node->setCore(trans);
//.........这里部分代码省略.........
示例8: initVTK
OSG::NodeTransitPtr initVTK(void)
{
OSG::NodeUnrecPtr returnValue = NULL;
OSG::Char8 *szDataRoot = getenv("VTK_DATA_ROOT");
if(szDataRoot == NULL)
{
fprintf(stderr, "VTK_DATA_ROOT not set\n");
exit(0);
}
std::string szFilename;
szFilename.assign(szDataRoot);
szFilename += "/Data/office.binary.vtk";
vtkStructuredGridReader *reader = vtkStructuredGridReader::New();
reader->SetFileName(szFilename.c_str());
reader->Update();
#if 0
OSG::Real64 length = reader->GetOutput()->GetLength();
OSG::Real64 maxVelocity =
reader->GetOutput()->GetPointData()->GetVectors()->GetMaxNorm();
OSG::Real64 maxTime = 35.0 * length / maxVelocity;
#endif
returnValue = OSG::Node::create();
returnValue->setCore(OSG::Group::create());
// Create source for streamtubes
vtkPointSource *seeds = vtkPointSource::New();
seeds->SetRadius(0.15);
seeds->SetCenter(0.1, 2.1, 0.5);
seeds->SetNumberOfPoints(6);
vtkRungeKutta4 *integ = vtkRungeKutta4::New();
vtkStreamLine *streamer = vtkStreamLine::New();
streamer->SetInputConnection(reader->GetOutputPort());
#if VTK_MAJOR_VERSION >= 6
streamer->SetSourceData(seeds->GetOutput());
#else
streamer->SetSource(seeds->GetOutput());
#endif
streamer->SetMaximumPropagationTime(500);
streamer->SetStepLength(0.5);
streamer->SetIntegrationStepLength(0.05);
streamer->SetIntegrationDirectionToIntegrateBothDirections();
streamer->SetIntegrator(integ);
// The tube is wrapped around the generated streamline. By varying the
// radius by the inverse of vector magnitude, we are creating a tube
// whose radius is proportional to mass flux (in incompressible flow).
vtkTubeFilter *streamTube = vtkTubeFilter::New();
streamTube->SetInputConnection(streamer->GetOutputPort());
streamTube->SetRadius(0.02);
streamTube->SetNumberOfSides(12);
streamTube->SetVaryRadiusToVaryRadiusByVector();
vtkPolyDataMapper *mapStreamTube = vtkPolyDataMapper::New();
mapStreamTube->SetInputConnection(streamTube->GetOutputPort());
mapStreamTube->SetScalarRange(
reader->GetOutput()->GetPointData()->GetScalars()->GetRange());
vtkActor *streamTubeActor = vtkActor::New();
streamTubeActor->SetMapper(mapStreamTube);
streamTubeActor->GetProperty()->BackfaceCullingOn();
addActor(returnValue, streamTubeActor);
vtkStructuredGridGeometryFilter *table1 =
vtkStructuredGridGeometryFilter::New();
table1->SetInputConnection(reader->GetOutputPort());
table1->SetExtent(11, 15, 7, 9, 8, 8);
vtkPolyDataNormals *normTable1 = vtkPolyDataNormals::New();
normTable1->SetInputConnection(table1->GetOutputPort());
vtkPolyDataMapper *mapTable1 = vtkPolyDataMapper::New();
mapTable1->SetInputConnection(normTable1->GetOutputPort());
mapTable1->ScalarVisibilityOff();
vtkActor *table1Actor = vtkActor::New();
table1Actor->SetMapper(mapTable1);
table1Actor->GetProperty()->SetColor(.59, .427, .392);
addActor(returnValue, table1Actor);
vtkStructuredGridGeometryFilter *table2 =
vtkStructuredGridGeometryFilter::New();
table2->SetInputConnection(reader->GetOutputPort());
table2->SetExtent(11, 15, 10, 12, 8, 8);
//.........这里部分代码省略.........
示例9: CHECK
TEST_FIXTURE(FileFixture, TextureChunkIO)
{
OSG::NodeUnrecPtr n = OSG::Node::create();
OSG::GeometryUnrecPtr geo = OSG::makeBoxGeo(2.0, 2.0, 2.0, 1, 1, 1);
OSG::ChunkMaterialUnrecPtr mat = OSG::ChunkMaterial::create();
OSG::ImageUnrecPtr img = OSG::Image::create();
img->set(OSG::Image::OSG_RGBA_PF, 2, 2);
img->editData()[0 * 2 * 4 + 0 * 4 + 0] = 255;
img->editData()[0 * 2 * 4 + 0 * 4 + 1] = 0;
img->editData()[0 * 2 * 4 + 0 * 4 + 2] = 0;
img->editData()[0 * 2 * 4 + 0 * 4 + 3] = 255;
img->editData()[0 * 2 * 4 + 1 * 4 + 0] = 255;
img->editData()[0 * 2 * 4 + 1 * 4 + 1] = 255;
img->editData()[0 * 2 * 4 + 1 * 4 + 2] = 0;
img->editData()[0 * 2 * 4 + 1 * 4 + 3] = 255;
img->editData()[1 * 2 * 4 + 0 * 4 + 0] = 0;
img->editData()[1 * 2 * 4 + 0 * 4 + 1] = 0;
img->editData()[1 * 2 * 4 + 0 * 4 + 2] = 255;
img->editData()[1 * 2 * 4 + 0 * 4 + 3] = 255;
img->editData()[1 * 2 * 4 + 1 * 4 + 0] = 0;
img->editData()[1 * 2 * 4 + 1 * 4 + 1] = 255;
img->editData()[1 * 2 * 4 + 1 * 4 + 2] = 255;
img->editData()[1 * 2 * 4 + 1 * 4 + 3] = 255;
OSG::TextureChunkUnrecPtr tex = OSG::TextureChunk::create();
tex->setImage(img);
mat->addChunk(tex);
geo->setMaterial(mat);
n->setCore(geo);
OSG::SceneFileHandler::the()->write(n, test_file.native_file_string().c_str());
OSG::NodeUnrecPtr n2 =
OSG::SceneFileHandler::the()->read(test_file.native_file_string().c_str());
CHECK(n2 != NULL);
CHECK(n2->getCore() != NULL);
OSG::GeometryUnrecPtr geo2 =
dynamic_cast<OSG::Geometry *>(n2->getCore());
CHECK(geo2 != NULL);
CHECK(geo2->getMaterial() != NULL);
OSG::ChunkMaterialUnrecPtr mat2 =
dynamic_cast<OSG::ChunkMaterial *>(geo2->getMaterial());
CHECK(mat2 != NULL);
CHECK(mat2->getChunk(0) != NULL);
const OSG::TextureChunk *tex2 =
dynamic_cast<const OSG::TextureChunk *>(mat2->getChunk(0));
const OSG::TextureObjChunk *texObj =
dynamic_cast<const OSG::TextureObjChunk *>(mat2->getChunk(0));
const OSG::TextureEnvChunk *texEnv =
dynamic_cast<const OSG::TextureEnvChunk *>(mat2->getChunk(1));
CHECK(tex2 == NULL);
CHECK(texObj != NULL);
CHECK(texEnv != NULL);
CHECK(texObj->getImage() != NULL);
OSG::Image *img2 = texObj->getImage();
CHECK(img2 != NULL);
CHECK_EQUAL(255, img2->getData()[0 * 2 * 4 + 0 * 4 + 0]);
CHECK_EQUAL( 0, img2->getData()[0 * 2 * 4 + 0 * 4 + 1]);
CHECK_EQUAL( 0, img2->getData()[0 * 2 * 4 + 0 * 4 + 2]);
CHECK_EQUAL(255, img2->getData()[0 * 2 * 4 + 0 * 4 + 3]);
CHECK_EQUAL(255, img2->getData()[0 * 2 * 4 + 1 * 4 + 0]);
CHECK_EQUAL(255, img2->getData()[0 * 2 * 4 + 1 * 4 + 1]);
CHECK_EQUAL( 0, img2->getData()[0 * 2 * 4 + 1 * 4 + 2]);
CHECK_EQUAL(255, img2->getData()[0 * 2 * 4 + 1 * 4 + 3]);
CHECK_EQUAL( 0, img2->getData()[1 * 2 * 4 + 0 * 4 + 0]);
CHECK_EQUAL( 0, img2->getData()[1 * 2 * 4 + 0 * 4 + 1]);
CHECK_EQUAL(255, img2->getData()[1 * 2 * 4 + 0 * 4 + 2]);
CHECK_EQUAL(255, img2->getData()[1 * 2 * 4 + 0 * 4 + 3]);
CHECK_EQUAL( 0, img2->getData()[1 * 2 * 4 + 1 * 4 + 0]);
CHECK_EQUAL(255, img2->getData()[1 * 2 * 4 + 1 * 4 + 1]);
CHECK_EQUAL(255, img2->getData()[1 * 2 * 4 + 1 * 4 + 2]);
CHECK_EQUAL(255, img2->getData()[1 * 2 * 4 + 1 * 4 + 3]);
}
示例10: doMain
// Initialize GLUT & OpenSG and set up the scene
int doMain(int argc, char **argv)
{
printf("Usage: testCGShader [normal map filename]\n");
const char *normal_map_img_name = "opensg_logoDOT3.png";
OSG::Color4f tmp;
if( argc > 1 )
normal_map_img_name = argv[1];
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->setSize( 800, 800 );
gwin->init();
// Create the shader material
// Read the image for the normal texture
OSG::ImageUnrecPtr normal_map_img = OSG::Image::create();
if(!normal_map_img->read(normal_map_img_name))
{
fprintf(stderr, "Couldn't read normalmap texture '%s'!\n", normal_map_img_name);
return 1;
}
OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create();
OSG::MaterialChunkUnrecPtr matc = OSG::MaterialChunk::create();
matc->setAmbient(OSG::Color4f(0.1, 0.1, 0.1, 1.0));
matc->setDiffuse(OSG::Color4f(0.3, 0.3, 0.3, 1.0));
matc->setSpecular(OSG::Color4f(0.8, 0.8, 0.8, 1.0));
matc->setShininess(100);
matc->setLit(true);
OSG::ShaderProgramChunkUnrecPtr shl = OSG::ShaderProgramChunk::create();
OSG::ShaderProgramUnrecPtr shl_vp =
OSG::ShaderProgram::createVertexShader();
shl_vp->setProgram(_vp_program);
shl_vp->setProgramAttribute(OSG::ShaderConstants::TexCoordsIndex, "TexCoord0");
shl_vp->setProgramAttribute(OSG::ShaderConstants::NormalsIndex, "Normal" );
shl_vp->setProgramAttribute(OSG::ShaderConstants::PositionsIndex, "Position");
shl->addShader(shl_vp);
OSG::ShaderProgramUnrecPtr shl_fp =
OSG::ShaderProgram::createFragmentShader();
shl_fp->setProgram(_fp_program);
shl->addShader(shl_fp);
OSG::TextureObjChunkUnrecPtr tex_normal_map =
OSG::TextureObjChunk::create();
OSG::TextureEnvChunkUnrecPtr tex_normal_map_env =
OSG::TextureEnvChunk::create();
tex_normal_map->setImage(normal_map_img);
tex_normal_map->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
tex_normal_map->setMagFilter(GL_LINEAR);
tex_normal_map->setWrapS(GL_REPEAT);
tex_normal_map->setWrapT(GL_REPEAT);
tex_normal_map_env->setEnvMode(GL_MODULATE);
//cmat->addChunk(matc);
cmat->addChunk(shl);
cmat->addChunk(tex_normal_map);
cmat->addChunk(tex_normal_map_env);
// create root node
_scene = OSG::Node::create();
// create geometry
//GeometryPtr geo = makeLatLongSphereGeo (100, 100, 1.0);
OSG::GeometryUnrecPtr geo = OSG::makePlaneGeo(1.0, 1.0, 100, 100);
geo->setMaterial(cmat);
OSG::NodeUnrecPtr torus = OSG::Node::create();
torus->setCore(geo);
// add torus to scene
OSG::GroupUnrecPtr group = OSG::Group::create();
_scene->setCore(group);
_scene->addChild(torus);
// create the SimpleSceneManager helper
//.........这里部分代码省略.........
示例11: doMain
// Initialize GLUT & OpenSG and set up the scene
int doMain(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
OSG::GLUTWindowUnrecPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->setSize( 800, 800 );
gwin->init();
// Create the shader material
OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create();
OSG::SHLChunkUnrecPtr shl = OSG::SHLChunk::create();
shl->setProgramParameter(GL_GEOMETRY_INPUT_TYPE_EXT,
GL_TRIANGLES);
shl->setProgramParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT,
GL_TRIANGLE_STRIP);
shl->setProgramParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 6);
shl->setVertexProgram(_vertex_shader);
shl->setFragmentProgram(_fragment_shader);
shl->setGeometryProgram(_geometry_shader);
cmat->addChunk(shl);
// create root node
_scene = OSG::Node::create();
// create torus
OSG::GeometryUnrecPtr geo = OSG::makeTorusGeo(.8, 1.8, 128, 128);
geo->setMaterial(cmat);
OSG::NodeUnrecPtr torus = OSG::Node::create();
torus->setCore(geo);
// add torus to scene
OSG::GroupUnrecPtr group = OSG::Group::create();
_scene->setCore(group);
_scene->addChild(torus);
// create the SimpleSceneManager helper
_mgr = OSG::SimpleSceneManager::create();
// tell the manager what to manage
_mgr->setWindow(gwin );
_mgr->setRoot(_scene);
// show the whole scene
_mgr->showAll();
return 0;
}
示例12: doMain
//.........这里部分代码省略.........
tree7_trans_node->addChild(cloneTree(tree1));
tree8_trans_node->addChild(cloneTree(tree1));
tree9_trans_node->addChild(cloneTree(tree1));
OSG::NodeUnrecPtr trees = OSG::makeCoredNode<OSG::Group>();
trees->addChild(tree1_trans_node);
trees->addChild(tree2_trans_node);
trees->addChild(tree3_trans_node);
trees->addChild(tree4_trans_node);
trees->addChild(tree5_trans_node);
trees->addChild(tree6_trans_node);
trees->addChild(tree7_trans_node);
trees->addChild(tree8_trans_node);
trees->addChild(tree9_trans_node);
/*//load Airplane Object
NodePtr obj1_trans_node = makeCoredNode<Transform>(&_obj1_trans);
_obj1_trans->editMatrix().setTranslate(0.0, 0.0, 10.0);
_obj1_trans->editMatrix().setScale(Vec3f(0.15,0.15,0.15));
NodePtr object1 = SceneFileHandler::the().read("triplane.3ds");
obj1_trans_node->addChild(object1);
*/
//Load a Quad as Pointlight
OSG::GeometryUnrecPtr boxGeo = OSG::makeBoxGeo(15, 15, 15, 1, 1, 1);
OSG::NodeUnrecPtr boxNode = OSG::Node::create();
boxNode->setCore(boxGeo);
OSG::SimpleMaterialUnrecPtr box_mat = OSG::SimpleMaterial::create();
box_mat->setAmbient(OSG::Color3f(0.95f, 1.0f, 0.2f));
box_mat->setDiffuse(OSG::Color3f(0.95f, 1.0f, 0.2f));
boxGeo->setMaterial(box_mat);
OSG::NodeUnrecPtr obj1_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_obj1_trans);
obj1_trans_node->addChild(boxNode);
//load Dino Objects
OSG::NodeUnrecPtr dino1_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_dino1_trans);
OSG::NodeUnrecPtr dino2_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_dino2_trans);
OSG::NodeUnrecPtr dino3_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_dino3_trans);
OSG::NodeUnrecPtr dino4_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_dino4_trans);
_dino1_trans->editMatrix().setTranslate(-20.0, -20.0, 10.0);
_dino1_trans->editMatrix().setScale(OSG::Vec3f(5.0, 5.0, 5.0));
_dino2_trans->editMatrix().setTranslate(-20.0, -20.0, 6.0);
_dino2_trans->editMatrix().setScale(OSG::Vec3f(3.0, 3.0, 3.0));
_dino3_trans->editMatrix().setTranslate(-20.0, -20.0, 6.0);
_dino3_trans->editMatrix().setScale(OSG::Vec3f(3.0, 3.0, 3.0));
示例13: doMain
int doMain (int argc, char **argv)
{
int dummy;
// OSG init
OSG::osgInit(argc, argv);
// create the graph
// beacon for camera and light
OSG::NodeUnrecPtr b1n = OSG::Node::create();
OSG::GroupUnrecPtr b1 = OSG::Group::create();
b1n->setCore( b1 );
// transformation
OSG::NodeUnrecPtr t1n = OSG::Node::create();
OSG::TransformUnrecPtr t1 = OSG::Transform::create();
t1n->setCore( t1 );
t1n->addChild( b1n );
cam_trans = t1;
// light
OSG::NodeUnrecPtr dlight = OSG::Node::create();
OSG::DirectionalLightUnrecPtr dl = OSG::DirectionalLight::create();
dlight->setCore( dl );
dl->setAmbient( .3, .3, .3, 1 );
dl->setDiffuse( 1, 1, 1, 1 );
dl->setDirection(0,0,1);
dl->setBeacon( b1n);
// root
root = OSG::Node::create();
OSG::GroupUnrecPtr gr1 = OSG::Group::create();
root->setCore( gr1 );
root->addChild( t1n );
root->addChild( dlight );
// Load the file
OSG::NodeUnrecPtr file = NULL;
if ( argc > 1 )
file = OSG::SceneFileHandler::the()->read(argv[1]);
if ( file == NULL )
{
std::cerr << "Couldn't load file, ignoring" << std::endl;
file = OSG::makeTorus( .5, 2, 16, 16 );
}
OSG::Thread::getCurrentChangeList()->commitChanges();
file->updateVolume();
OSG::Vec3f min,max;
file->getVolume().getBounds( min, max );
std::cout << "Volume: from " << min << " to " << max << std::endl;
dlight->addChild( file );
std::cerr << "Tree: " << std::endl;
//root->dump();
// Camera
cam = OSG::PerspectiveCamera::create();
cam->setBeacon( b1n );
cam->setFov( OSG::osgDegree2Rad( 90 ) );
cam->setNear( 0.1 );
cam->setFar( 100000 );
// Background
OSG::SolidBackgroundUnrecPtr bkgnd = OSG::SolidBackground::create();
bkgnd->setColor(OSG::Color3f(0,0,1));
// Viewport
vp = OSG::Viewport::create();
vp->setCamera( cam );
vp->setBackground( bkgnd );
vp->setRoot( root );
vp->setSize( 0,0, 1,1 );
// Action
ract = OSG::RenderAction::create();
// tball
OSG::Vec3f pos;
pos.setValues(min[0] + ((max[0] - min[0]) * 0.5),
min[1] + ((max[1] - min[1]) * 0.5),
max[2] + ( max[2] - min[2] ) * 1.5 );
//.........这里部分代码省略.........
示例14: main
int main(int argc, char **argv)
{
OSG::osgInit(argc,argv);
OSG::PerfMonitor::the()->enable(true); // Enable performance monitoring
// GLUT init
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(500, 500);
glutCreateWindow("PerfMonitor FG Test");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
pwin=OSG::PassiveWindow::create();
pwin->init();
// create the scene
OSG::NodeUnrecPtr scene;
if(argc > 1)
{
scene = OSG::Node::create();
OSG::GroupUnrecPtr g = OSG::Group::create();
scene->setCore(g);
for(OSG::UInt16 i = 1; i < argc; ++i)
scene->addChild(OSG::SceneFileHandler::the()->read(argv[i]));
}
else
{
scene = OSG::makeTorus(.5, 3, 16, 16);
}
// create the SimpleSceneManager helper
mgr = OSG::SimpleSceneManager::create();
// create the window and initial camera/viewport
mgr->setWindow(pwin );
// tell the manager what to manage
mgr->setRoot (scene);
OSG::Thread::getCurrentChangeList()->commitChanges();
// show the whole scene
mgr->showAll();
// add the statistics forground
perfmon_fg = OSG::PerfMonitorForeground::create();
pwin->getPort(0)->addForeground(perfmon_fg);
//statfg->setMaxSize(25);
//statfg->setColor(Color4f(0,1,0,0.7));
act = OSG::RenderAction::create();
mgr->setAction(act);
// GLUT main loop
glutMainLoop();
return 0;
}
示例15: doMain
// Initialize GLUT & OpenSG and set up the scene
int doMain(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc, argv);
// GLUT init
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG CGFX Shader");
// the connection between GLUT and OpenSG
_gwin = OSG::GLUTWindow::create();
_gwin->setGlutId(winid);
_gwin->setSize( 800, 800 );
_gwin->init();
// init callbacks
glutSetWindow(winid);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
const char *effectFile = "blinn_bump_reflect.vinstruct.cgfx";
if(argc > 1)
{
effectFile = argv[1];
}
_cgfxmat = OSG::CgFXMaterial::create();
_cgfxmat->setEffectFile(effectFile);
// this multipass technique leads to a render bug,
// I have no idea what's wrong :-(
//_cgfxmat->setTechnique(1);
OSG::ChunkMaterialUnrecPtr mat2 = OSG::ChunkMaterial::create();
OSG::MaterialChunkUnrecPtr matc = OSG::MaterialChunk::create();
matc->setDiffuse(OSG::Color4f(1, 0, 0, 1));
mat2->addChunk(matc);
//mat2->addChunk(texc);
// create root node
_scene = OSG::Node::create();
OSG::GeometryUnrecPtr geo1 = OSG::makeLatLongSphereGeo(50, 50, 2.0f);
OSG::calcVertexTangents(geo1,
0,
OSG::Geometry::TexCoords6Index,
OSG::Geometry::TexCoords7Index);
geo1->setMaterial(_cgfxmat);
OSG::NodeUnrecPtr sphere1 = OSG::Node::create();
sphere1->setCore(geo1);
OSG::TransformUnrecPtr trans1 = OSG::Transform::create();
trans1->editMatrix().setTranslate(-2 , 0, 0);
OSG::NodeUnrecPtr transn1 = OSG::Node::create();
transn1->setCore(trans1);
transn1->addChild(sphere1);
//
OSG::GeometryUnrecPtr geo2 = OSG::makeLatLongSphereGeo(50, 50, 1.0f);
geo2->setMaterial(mat2);
OSG::NodeUnrecPtr sphere2 = OSG::Node::create();
sphere2->setCore(geo2);
OSG::TransformUnrecPtr trans2 = OSG::Transform::create();
trans2->editMatrix().setTranslate(2 , 0, 0);
OSG::NodeUnrecPtr transn2 = OSG::Node::create();
transn2->setCore(trans2);
transn2->addChild(sphere2);
_scene->setCore (OSG::Group::create());
_scene->addChild(transn1 );
_scene->addChild(transn2 );
// create the SimpleSceneManager
//.........这里部分代码省略.........