本文整理汇总了C++中osg::GeometryUnrecPtr::setMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryUnrecPtr::setMaterial方法的具体用法?C++ GeometryUnrecPtr::setMaterial怎么用?C++ GeometryUnrecPtr::setMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::GeometryUnrecPtr
的用法示例。
在下文中一共展示了GeometryUnrecPtr::setMaterial方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doMain
//.........这里部分代码省略.........
shl_fp->setProgram(_fp_program);
shl->addShader(shl_fp);
shl_vp->addProceduralVariable ("Light0Active", &light0Active);
shl_vp->addProceduralVariable ("Light1Active", &light1Active);
shl_vp->addNodeProceduralVariable("Light2Active", &light2Active);
cmat->addChunk(matc);
cmat->addChunk(shl);
// create root node
_scene = OSG::Node::create();
// create two light sources.
OSG::TransformUnrecPtr point1_trans;
OSG::NodeUnrecPtr point1 =
OSG::makeCoredNode<OSG::PointLight>(&_point1_core);
point1_beacon = OSG::makeCoredNode<OSG::Transform >(&point1_trans);
point1_trans->editMatrix().setTranslate(-10.0, 5.0, 5.0);
_point1_core->setAmbient(0.0f, 0.0f, 0.0f , 1.0f);
_point1_core->setDiffuse(1.0f, 0.0f, 0.0f, 1.0f);
_point1_core->setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
_point1_core->setBeacon(point1_beacon);
_point1_core->setOn(true);
OSG::TransformUnrecPtr point2_trans;
OSG::NodeUnrecPtr point2 =
OSG::makeCoredNode<OSG::PointLight>(&_point2_core);
point2_beacon = OSG::makeCoredNode<OSG::Transform >(&point2_trans);
point2_trans->editMatrix().setTranslate(10.0, 5.0, 5.0);
_point2_core->setAmbient(0.0f, 0.0f, 0.0f, 1.0f);
_point2_core->setDiffuse(0.0f, 1.0f, 0.0f, 1.0f);
_point2_core->setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
_point2_core->setBeacon(point2_beacon);
_point2_core->setOn(true);
point1->addChild(point2);
OSG::TransformUnrecPtr point3_trans;
OSG::NodeUnrecPtr point3 =
OSG::makeCoredNode<OSG::PointLight>(&_point3_core);
point3_beacon = OSG::makeCoredNode<OSG::Transform >(&point3_trans);
point3_trans->editMatrix().setTranslate(0.0, -12.0, 5.0);
_point3_core->setAmbient(0.0f, 0.0f, 0.0f, 1.0f);
_point3_core->setDiffuse(0.5f, 0.0f, 1.0f, 1.0f);
_point3_core->setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
_point3_core->setBeacon(point3_beacon);
_point3_core->setOn(true);
point2->addChild(point3);
// create a sphere.
OSG::GeometryUnrecPtr geo = OSG::makeLatLongSphereGeo (100, 100, 1.0);
geo->setMaterial(cmat);
OSG::NodeUnrecPtr sphere = OSG::makeNodeFor(geo);
point3->addChild(sphere);
_scene->setCore(OSG::Group::create());
_scene->addChild(point1);
// create the SimpleSceneManager helper
_mgr = OSG::SimpleSceneManager::create();
// tell the manager what to manage
_mgr->setWindow(gwin );
_mgr->setRoot(_scene);
_mgr->turnHeadlightOff();
// show the whole scene
_mgr->showAll();
// enable local lights.
// OSG::RenderAction *ract =
// dynamic_cast<OSG::RenderAction *>(_mgr->getRenderAction());
// ract->setLocalLights(true);
return 0;
}
示例2: 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;
}
示例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: setupAnim
OSG::NodeTransitPtr setupAnim(void)
{
OSG::NodeTransitPtr returnValue = OSG::Node::create();
returnValue->setCore(OSG::Group::create());
static const OSG::Real32 aOffsets[6][3] =
{
{ -5.5, 0.0, 0.0 },
{ 5.5, 0.0, 0.0 },
{ 0.0, -5.5, 0.0 },
{ 0.0, 5.5, 0.0 },
{ 0.0, 0.0, -5.5 },
{ 0.0, 0.0, 5.5 }
};
static const OSG::Real32 aDiffuse[6][3] =
{
{ 1.f, 0.f, 0.f },
{ 0.f, 1.f, 0.f },
{ 0.f, 0.f, 1.f },
{ 1.f, 1.f, 0.f },
{ 1.f, 0.f, 1.f },
{ 0.f, 1.f, 1.f }
};
for(OSG::UInt32 i = 0; i < 6; ++i)
{
OSG::NodeUnrecPtr pTN = OSG::Node::create();
pAnimTrs[i] = OSG::ComponentTransform::create();
OSG::GeometryUnrecPtr pGeo = OSG::makeBoxGeo(1.f, 1.f, 1.f,
2, 2, 2);
OSG::NodeUnrecPtr pGeoNode = OSG::Node::create();
pGeoNode->setCore(pGeo);
OSG::SimpleMaterialUnrecPtr pMat = OSG::SimpleMaterial::create();
pMat->setDiffuse(OSG::Color3f(aDiffuse[i][0],
aDiffuse[i][1],
aDiffuse[i][2]));
pMat->setAmbient(OSG::Color3f(aDiffuse[i][0],
aDiffuse[i][1],
aDiffuse[i][2]));
pGeo->setMaterial(pMat);
pAnimTrs[i]->editTranslation().setValues(aOffsets[i][0],
aOffsets[i][1],
aOffsets[i][2]);
pTN->setCore (pAnimTrs[i]);
pTN->addChild(pGeoNode );
returnValue->addChild(pTN);
}
return returnValue;
}
示例5: 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);
//.........这里部分代码省略.........
示例6: 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]);
}
示例7: 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;
}
示例8: 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
//.........这里部分代码省略.........
示例9: doMain
//.........这里部分代码省略.........
Pcamera = OSG::PerspectiveCamera::create();
cam_beacon = OSG::makeCoredNode<OSG::Transform>(&cam_trans);
cam_trans->editMatrix().setTranslate(0.0, 0.0, 25.0);
Pcamera->setBeacon(cam_beacon);
Pcamera->setFov(OSG::osgDegree2Rad(60));
Pcamera->setNear(1.0);
Pcamera->setFar(1000);
// create scene
// bottom
OSG::NodeUnrecPtr plane = OSG::makePlane(300.0, 300.0, 256, 256);
OSG::ImageUnrecPtr plane_img = OSG::Image::create();
plane_img->read("gras.jpg");
OSG::TextureObjChunkUnrecPtr plane_tex_obj = OSG::TextureObjChunk::create();
OSG::TextureEnvChunkUnrecPtr plane_tex_env = OSG::TextureEnvChunk::create();
plane_tex_obj->setImage(plane_img);
plane_tex_obj->setMinFilter(GL_LINEAR);
plane_tex_obj->setMagFilter(GL_LINEAR);
plane_tex_obj->setWrapS(GL_REPEAT);
plane_tex_obj->setWrapT(GL_REPEAT);
plane_tex_env->setEnvMode(GL_MODULATE);
OSG::SimpleMaterialUnrecPtr plane_mat = OSG::SimpleMaterial::create();
plane_mat->setAmbient(OSG::Color3f(0.3f, 0.3f, 0.3f));
plane_mat->setDiffuse(OSG::Color3f(1.0f, 1.0f, 1.0f));
plane_mat->addChunk(plane_tex_obj);
plane_mat->addChunk(plane_tex_env);
OSG::Geometry *plane_geo = dynamic_cast<OSG::Geometry *>(plane->getCore());
plane_geo->setMaterial(plane_mat);
//load Tree Objects
OSG::NodeUnrecPtr tree1_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_tree1_trans);
OSG::NodeUnrecPtr tree2_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_tree2_trans);
OSG::NodeUnrecPtr tree3_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_tree3_trans);
OSG::NodeUnrecPtr tree4_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_tree4_trans);
OSG::NodeUnrecPtr tree5_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_tree5_trans);
OSG::NodeUnrecPtr tree6_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_tree6_trans);
OSG::NodeUnrecPtr tree7_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_tree7_trans);
OSG::NodeUnrecPtr tree8_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_tree8_trans);
OSG::NodeUnrecPtr tree9_trans_node = OSG::makeCoredNode<OSG::Transform>
(&_tree9_trans);
_tree1_trans->editMatrix().setTranslate(-80.0, -80.0, 0.0);
_tree1_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
_tree2_trans->editMatrix().setTranslate(0.0, -80.0, 0.0);
_tree2_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
_tree3_trans->editMatrix().setTranslate(80.0, -80.0, 0.0);
_tree3_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
_tree4_trans->editMatrix().setTranslate(-80.0, 0.0, 0.0);
示例10: initPlaneSetup
void initPlaneSetup(void)
{
// beacon for camera and light
OSG::GroupNodeRefPtr beacon = OSG::GroupNodeRefPtr::create();
// transformation
OSG::TransformNodeRefPtr cam_transPlane =
OSG::TransformNodeRefPtr::create();
cam_transPlane.node()->addChild(beacon);
// light
OSG::DirectionalLightNodeRefPtr dl =
OSG::DirectionalLightNodeRefPtr::create();
dl->setAmbient (.3f, .3f, .3f, 1);
dl->setDiffuse ( 1, 1, 1, 1);
dl->setDirection( 0, 0, 1 );
dl->setBeacon (beacon );
// planeRoot
planeRoot = OSG::GroupNodeRefPtr::create();
planeRoot.node()->addChild(cam_transPlane);
planeRoot.node()->addChild(animRoot);
planeRoot.node()->addChild(dl);
// Create plane to project the staged render
OSG::NodeUnrecPtr plane_node = OSG::makePlane(10, 10, 5, 5);
// Setup the shared texture and texture environment
// - Create an empty image so texture can allocate size and memory
OSG::ImageUnrecPtr pImg = OSG::Image::create();
pImg->set(OSG::Image::OSG_RGB_PF, 512, 512);
tx1o->setImage (pImg );
tx1o->setMinFilter(GL_LINEAR );
tx1o->setMagFilter(GL_LINEAR );
tx1o->setWrapS (GL_REPEAT );
tx1o->setWrapT (GL_REPEAT );
tx1e->setEnvMode (GL_REPLACE);
#ifdef USE_DEPTH_TEXTURE
OSG::ImageUnrecPtr dImg = OSG::Image::create();
dImg->set(Image::OSG_L_PF, 512, 512);
txDepth->setImage (dImg);
txDepth->setMinFilter(GL_NEAREST );
txDepth->setMagFilter(GL_LINEAR );
txDepth->setWrapS (GL_CLAMP_TO_EDGE );
txDepth->setWrapT (GL_CLAMP_TO_EDGE );
txDepth->setExternalFormat(GL_DEPTH_COMPONENT);
txDepth->setInternalFormat(GL_DEPTH_COMPONENT32);
#endif
// Material for plane
// - Create a material that will reference the texture and render
// it on the plane
OSG::SimpleMaterialUnrecPtr mat = OSG::SimpleMaterial::create();
mat->setDiffuse(OSG::Color3f(1,1,1));
mat->setLit (false );
#ifdef USE_DEPTH_TEXTURE
mat->addChunk (txDepth );
#else
mat->addChunk (tx1o );
#endif
mat->addChunk (tx1e );
OSG::GeometryUnrecPtr pGeo =
dynamic_cast<OSG::Geometry *>(plane_node->getCore());
pGeo->setMaterial(mat);
// Finish connecting graph
OSG::TransformNodeRefPtr scene_trans = OSG::TransformNodeRefPtr::create();
scene_trans.node()->addChild(plane_node );
dl.node()->addChild(scene_trans);
}