Пример #1
0
void CharacterModel::deactivateShader(void)
{
    for(UInt32 i = 0; i < getMaterials().size(); ++i)
    {
        ChunkMaterialPtr m = getMaterials(i);
        
        beginEditCP(m);
        m->subChunk(getShader());
        endEditCP(m);
    }
}
Пример #2
0
void VRMLAppearanceBinder::finish(VRMLToOSGAction *)
{
    ChunkMaterialPtr pChunkMat = 
        ChunkMaterialPtr::dcast(_pFieldContainer);

    TextureChunkPtr pTexChunk = 
        TextureChunkPtr::dcast(pChunkMat->find(TextureChunk::getClassType()));
    
    MaterialChunkPtr pMatChunk = 
        MaterialChunkPtr::dcast(
            pChunkMat->find(MaterialChunk::getClassType()));
    
    if(pTexChunk != NullFC)
    {    
        beginEditCP(pTexChunk, TextureChunk::EnvModeFieldMask);
        {
            if(pMatChunk == NullFC)
            {
                pTexChunk->setEnvMode(GL_REPLACE);
            }
            else
            {
                pTexChunk->setEnvMode(GL_MODULATE);
            }
        }
        endEditCP  (pTexChunk, TextureChunk::EnvModeFieldMask);
    }
    
    if(pChunkMat != NullFC && (pChunkMat->isTransparent() == true || 
                               _has_alpha))
    {
        BlendChunkPtr pBlendChunk = OSG::BlendChunk::create();

        beginEditCP(pBlendChunk, BlendChunk::SrcFactorFieldMask | 
                                 BlendChunk::DestFactorFieldMask);
        {
            pBlendChunk->setSrcFactor (GL_SRC_ALPHA);
            pBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
        }
        endEditCP  (pBlendChunk, BlendChunk::SrcFactorFieldMask | 
                                 BlendChunk::DestFactorFieldMask);

        beginEditCP(pChunkMat, ChunkMaterial::ChunksFieldMask);
        {
            pChunkMat->addChunk(pBlendChunk);
        }
        endEditCP  (pChunkMat, ChunkMaterial::ChunksFieldMask);
    }
}
Пример #3
0
void VRMLAppearanceBinder::setMaterial(MaterialChunkPtr pMat)
{
    if(pMat == NullFC)
        return;

    ChunkMaterialPtr pChunkMat = 
        ChunkMaterialPtr::dcast(_pFieldContainer);

    if(pChunkMat != NullFC)
    {
        beginEditCP(pChunkMat, ChunkMaterial::ChunksFieldMask);
        {
            pChunkMat->addChunk(pMat);
        }
        endEditCP  (pChunkMat, ChunkMaterial::ChunksFieldMask);
    }
}
Пример #4
0
void VRMLAppearanceBinder::setTextureTransform(
    TextureTransformChunkPtr pTexTrans)
{
    if(pTexTrans == NullFC)
        return;

    ChunkMaterialPtr pChunkMat = 
        ChunkMaterialPtr::dcast(_pFieldContainer);

    if(pChunkMat != NullFC)
    {
        beginEditCP(pChunkMat, ChunkMaterial::ChunksFieldMask);
        {
            pChunkMat->addChunk(pTexTrans);
        }
        endEditCP  (pChunkMat, ChunkMaterial::ChunksFieldMask);
    }
}
Пример #5
0
ChunkMaterialPtr PhongMaterial::createChunkMaterial(void)
{
    _arbFragmentProgram = Window::registerExtension("GL_ARB_fragment_program");

    ChunkMaterialPtr cmat = ChunkMaterial::create();

    MaterialChunkPtr matc = MaterialChunk::create();
    beginEditCP(matc);
    matc->setAmbient(Color4f(0.1, 0.1, 0.2, 1.0));
    matc->setDiffuse(Color4f(0.2, 0.2, 0.8, 1.0));
    matc->setSpecular(Color4f(0.8, 0.8, 0.8, 1.0));
    matc->setShininess(100);
    endEditCP(matc);

    beginEditCP(cmat, ChunksFieldMask);
    cmat->addChunk(matc);
    endEditCP(cmat, ChunksFieldMask);

    // phong shading without a fragment shader looks quite black ;-)
    // all cards with a fragment shader should also have a vertex shader.
    if(Window::hasCommonExtension(_arbFragmentProgram))
    {
        VertexProgramChunkPtr vpc = VertexProgramChunk::create();
        beginEditCP(vpc);
        vpc->setProgram(_phong_vp_prg);
        endEditCP(vpc);

        FragmentProgramChunkPtr fpc = FragmentProgramChunk::create();
        std::string phong_fp_prg = _phong_fp_begin_prg + _phong_fp_end_prg;
        beginEditCP(fpc);
        fpc->setProgram(phong_fp_prg);
        endEditCP(fpc);

        beginEditCP(cmat, ChunksFieldMask);
        cmat->addChunk(vpc);
        cmat->addChunk(fpc);
        endEditCP(cmat, ChunksFieldMask);
    }
    return cmat;
}
Пример #6
0
void VRMLAppearanceBinder::init(VRMLToOSGAction *)
{
    VRMLAppearance *pNode = dynamic_cast<VRMLAppearance *>(_pNode);

    if(pNode == NULL)
        return;

    ChunkMaterialPtr mat = ChunkMaterial::create();

    if(pNode->getName().str() != NULL)
    {
        NamePtr node_name = Name::create();
        beginEditCP(node_name);
            node_name->getFieldPtr()->setValue(pNode->getName().str());
        endEditCP(node_name);
        beginEditCP(mat,  Node::AttachmentsFieldMask);
            mat->addAttachment(node_name);
        endEditCP  (mat, Node::AttachmentsFieldMask);
    }

    _pFieldContainer = mat;
}
Пример #7
0
void VRMLAppearanceBinder::setTexture(TextureChunkPtr pTex)
{
    if(pTex == NullFC)
        return;

    ChunkMaterialPtr pChunkMat = 
        ChunkMaterialPtr::dcast(_pFieldContainer);

    if(pChunkMat != NullFC)
    {
        beginEditCP(pChunkMat, ChunkMaterial::ChunksFieldMask);
        {
            pChunkMat->addChunk(pTex);
        }
        endEditCP  (pChunkMat, ChunkMaterial::ChunksFieldMask);
        
        // check for alpha
        ImagePtr img = pTex->getImage();

        if(img != NullFC && img->getBpp() == 4)
            _has_alpha = true;
    }
}
Пример #8
0
MaterialPtr createVideoMaterial(void)
{
    // Ok, now for the meat of the code...
    // first we need an Image to hold the picture(s) to show
    //image = Image::create();
    
    //beginEditCP(image);
    //{
        // set the image's size and type, and allocate memory
        // this example uses RGB. On some systems (e.g. Windows) BGR
        // or BGRA might be faster, it depends on how the images are 
        // acquired
    //    image->set(Image::OSG_RGB_PF, 2, 2);
    //}
    //endEditCP(image);
    
    // Now create the texture to be used for the background
    tex = TextureChunk::create();
    
    beginEditCP(tex);
    {
        // Associate image and texture
        //tex->setImage(image);
        
        // Set filtering modes. LINEAR is cheap and good if the image size
        // changes very little (i.e. the window is about the same size as 
        // the images).
        //tex->setMinFilter(GL_LINEAR);
        tex->setMinFilter(GL_NEAREST);
        tex->setMagFilter(GL_LINEAR);
        //tex->setMagFilter(GL_NEAREST);        
        
        // Set the wrapping modes. We don't need repetition, it might actually
        // introduce artifactes at the borders, so switch it off.
        tex->setWrapS(GL_CLAMP_TO_EDGE);
        tex->setWrapT(GL_CLAMP_TO_EDGE);             
        
        // Newer versions of OpenGl can handle NPOT textures directly.
        // OpenSG will do that internally automatically.
        //
        // Older versions need POT textures. By default OpenSG
        // will scale an NPOT texture to POT while defining it.
        // For changing textures that's too slow.
        // So tell OpenSG not to scale the image, but use the texture
        // matrix to scale. This only works if we're not using the
        // texture matrix for anything else, which is fine for video
        // backgrounds.
        // This does not do anything if NPOT textures are supported, so
        // it is safe to just set it.
        
        tex->setScale(false);            
        tex->setNPOTMatrixScale(true);
    }
    endEditCP(tex);

	ChunkMaterialPtr TheMaterial = ChunkMaterial::create();

	beginEditCP(TheMaterial, ChunkMaterial::ChunksFieldMask);
		TheMaterial->addChunk(tex);
		TheMaterial->addChunk(MaterialChunk::create());
	endEditCP(TheMaterial, ChunkMaterial::ChunksFieldMask);

	return TheMaterial;
}
Пример #9
0
ChunkMaterialPtr vtkOsgConverter::CreateMaterial(bool lit, bool hasTexCoords)
{
	if (_verbose)
		std::cout << "Start CreateMaterial()" << std::endl;

	vtkProperty* prop = _actor->GetProperty();
	double* diffuseColor = prop->GetDiffuseColor();
	double* ambientColor = prop->GetAmbientColor();
	double* specularColor = prop->GetSpecularColor();
	double specularPower = prop->GetSpecularPower();

	double diffuse = prop->GetDiffuse();
	double ambient = prop->GetAmbient();
	double specular = prop->GetSpecular();
	double opacity = prop->GetOpacity();

	float pointSize = prop->GetPointSize();
	float lineWidth = prop->GetLineWidth();
	// int lineStipplePattern = prop->GetLineStipplePattern();

	int representation = prop->GetRepresentation();

	if (_verbose)
	{
		std::cout << "    Colors:" << std::endl;
		std::cout << "      diffuse " << diffuse << " * " << diffuseColor[0] << " " <<
		diffuseColor[1] << " " << diffuseColor[2] << std::endl;
		std::cout << "      ambient " << ambient << " * " << ambientColor[0] << " " <<
		ambientColor[1] << " " << ambientColor[2] << std::endl;
		std::cout << "      specular " << specular << " * " << specularColor[0] << " " <<
		specularColor[1] << " " << specularColor[2] << std::endl;
	}

	PolygonChunkPtr polygonChunk = PolygonChunk::create();
	beginEditCP(polygonChunk);
	{
		if (representation == VTK_SURFACE)
		{
			polygonChunk->setFrontMode(GL_FILL);
			polygonChunk->setBackMode(GL_FILL);
		}
		else if (representation == VTK_WIREFRAME)
		{
			polygonChunk->setFrontMode(GL_LINE);
			polygonChunk->setBackMode(GL_LINE);
		}
		else
		{
			polygonChunk->setFrontMode(GL_POINT);
			polygonChunk->setBackMode(GL_POINT);
		}
	} endEditCP(polygonChunk);

	MaterialChunkPtr osgMaterialChunk = MaterialChunk::create();
	beginEditCP(osgMaterialChunk);
	{
		osgMaterialChunk->setDiffuse(Color4f(diffuseColor[0] * diffuse, diffuseColor[1] *
		                                     diffuse, diffuseColor[2] * diffuse, opacity));
		osgMaterialChunk->setSpecular(Color4f(specularColor[0] * specular,
		                                      specularColor[1] * specular,
		                                      specularColor[2] * specular, 1.0));
		osgMaterialChunk->setAmbient(Color4f(ambientColor[0] * ambient, ambientColor[1] *
		                                     ambient, ambientColor[2] * ambient, opacity));
		osgMaterialChunk->setShininess(specularPower);

		//if(opacity < 1.0)
		//{
		// osgMaterialChunk->setColorMaterial(GL_AMBIENT); // HACK: Opacity does not work with GL_AMBIENT_AND_DIFFUSE
		//osgMaterialChunk->setTransparency(1.0f - opacity);
		//}
		//else
		osgMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

		// On objects consisting only of points or lines, dont lit
		if(!lit)
			osgMaterialChunk->setLit(false);
	} endEditCP(osgMaterialChunk);

	ChunkMaterialPtr osgChunkMaterial = ChunkMaterial::create();
	beginEditCP(osgChunkMaterial);
	{
		osgChunkMaterial->addChunk(osgMaterialChunk);
		osgChunkMaterial->addChunk(TwoSidedLightingChunk::create());
		osgChunkMaterial->addChunk(polygonChunk);

		if(pointSize > 1.0f)
		{
			PointChunkPtr pointChunk = PointChunk::create();
			pointChunk->setSize(pointSize);
			osgChunkMaterial->addChunk(pointChunk);
		}

		if(lineWidth > 1.0f)
		{
			LineChunkPtr lineChunk = LineChunk::create();
			lineChunk->setWidth(lineWidth);
			osgChunkMaterial->addChunk(lineChunk);
		}

		// TEXTURE
		if (hasTexCoords)
		{
			vtkTexture* vtkTexture = _actor->GetTexture();
			if (vtkTexture)
			{
				TextureChunkPtr osgTextureChunk = NullFC;
				osgTextureChunk = CreateTexture(vtkTexture);

				if(osgTextureChunk != NullFC)
				{
					if (_verbose)
						std::cout << "    Add TextureChunk" << std::endl;
					osgChunkMaterial->addChunk(osgTextureChunk);
				}

				// Per default EnvMode is set to GL_REPLACE which does not lit the surface
				beginEditCP(osgTextureChunk);
				osgTextureChunk->setEnvMode(GL_MODULATE);
				endEditCP(osgTextureChunk);
			}
		}
	} endEditCP(osgChunkMaterial);

	if (_verbose)
		std::cout << "End CreateMaterial()" << std::endl;

	return osgChunkMaterial;
}
Пример #10
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindowEventProducer = createDefaultWindowEventProducer();
    WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();

    TutorialWindowEventProducer->setDisplayCallback(display);
    TutorialWindowEventProducer->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener);
    TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

	
    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindowEventProducer->getWindow());

    Path FBOFilePath;
    if(argc < 2)
    {
        FWARNING(("No FBO file given!\n"));
        FBOFilePath = Path("./Data/01LoadFBO.xml");
    }
    else
    {
        FBOFilePath = Path(std::string(argv[1]));
    }
    std::cout << "Loading xml File: " << FBOFilePath << std::endl;

    FCFileType::FCPtrStore NewContainers;
    NewContainers = FCFileHandler::the()->read(FBOFilePath);

    FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
        if( (*Itor)->getType() == FBOViewport::getClassType())
        {
            TheFBOViewport = FBOViewport::Ptr::dcast(*Itor);
        }
    }

    ChunkMaterialPtr BoxMaterial = ChunkMaterial::create();

    GeometryPtr BoxGeoCore = makeBoxGeo(1.0,1.0,1.0,2,2,2);
    beginEditCP(BoxGeoCore, Geometry::MaterialFieldMask);
        BoxGeoCore->setMaterial(BoxMaterial);
    endEditCP(BoxGeoCore, Geometry::MaterialFieldMask);

    NodePtr BoxGeoNode = Node::create();
    beginEditCP(BoxGeoNode, Node::CoreFieldMask);
        BoxGeoNode->setCore(BoxGeoCore);
    endEditCP(BoxGeoNode, Node::CoreFieldMask);

    NodePtr SceneNode = Node::create();
    beginEditCP(SceneNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
        SceneNode->setCore(Group::create());
        SceneNode->addChild(BoxGeoNode);
    endEditCP(SceneNode, Node::CoreFieldMask | Node::ChildrenFieldMask);

    // tell the manager what to manage
    mgr->setRoot  (SceneNode);

    // show the whole scene
    mgr->showAll();
    
    if(TheFBOViewport != NullFC)
    {
        //Add the texture chunk of the FBO to the Material for the box
        beginEditCP(BoxMaterial, ChunkMaterial::ChunksFieldMask);
            BoxMaterial->addChunk(TheFBOViewport->editTextures(0));
        endEditCP(BoxMaterial, ChunkMaterial::ChunksFieldMask);

        //Add The FBO Viewport the the Window
        beginEditCP(TheFBOViewport, FBOViewport::ParentFieldMask);
            TheFBOViewport->setParent(TutorialWindowEventProducer->getWindow());
        endEditCP(TheFBOViewport, FBOViewport::ParentFieldMask);

        beginEditCP(TutorialWindowEventProducer->getWindow());
            ViewportPtr vp = TutorialWindowEventProducer->getWindow()->getPort(0);
            addRefCP(vp);
            
            TutorialWindowEventProducer->getWindow()->subPort(0);

            //Put the FBO Vieport in front, so it is rendered first
            TutorialWindowEventProducer->getWindow()->addPort(TheFBOViewport);
            TutorialWindowEventProducer->getWindow()->addPort(vp   );
        endEditCP  (TutorialWindowEventProducer->getWindow());
    }

    Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TutorialWindowEventProducer->openWindow(WinPos,
                        WinSize,
                                        "07LoadFBO");

    //Main Loop
    TutorialWindowEventProducer->mainLoop();

    osgExit();

    return 0;
}
Пример #11
0
void updateScene()
{
    statfg->editCollector().getElem(majorAlignDesc)->set(alignmentToString(layoutParam.majorAlignment));
    statfg->editCollector().getElem(minorAlignDesc)->set(alignmentToString(layoutParam.minorAlignment));
    statfg->editCollector().getElem(dirDesc)->set(layoutParam.horizontal ? "Horizontal" : "Vertical");
    statfg->editCollector().getElem(horiDirDesc)->set(layoutParam.leftToRight ? "Left to right" : "Right to left");
    statfg->editCollector().getElem(vertDirDesc)->set(layoutParam.topToBottom ? "Top to bottom" : "Bottom to top");

    if(face == NULL)
        return;

    // Put it all together into a Geometry NodeCore.
    TextLayoutResult layoutResult;
    Real32 scale = 2.f;
    face->layout(lines, layoutParam, layoutResult);
#if 0
    GeometryPtr geo = Geometry::create();
    face->fillGeo(geo, layoutResult, scale);
    NodePtr textNode = Node::create();
    beginEditCP(textNode, Node::CoreFieldMask);
    {
        textNode->setCore(geo);
    }
    endEditCP(textNode, Node::CoreFieldMask);
#else
    NodePtr textNode = face->makeNode(layoutResult, scale);
    GeometryPtr geo = GeometryPtr::dcast(textNode->getCore());
#endif
    NodePtr transNodePtr = Node::create();
    TransformPtr transPtr = Transform::create();
    Matrix transMatrix;
    transMatrix.setTranslate(0.f, 0.f, -0.03f);
    beginEditCP(transPtr);
    {
        transPtr->setMatrix(transMatrix);
    }
    endEditCP(transPtr);
    beginEditCP(transNodePtr, Node::CoreFieldMask | Node::ChildrenFieldMask);
    {
        transNodePtr->setCore(transPtr);
        transNodePtr->addChild(textNode);
    }
    endEditCP(transNodePtr, Node::CoreFieldMask | Node::ChildrenFieldMask);

    ImagePtr imagePtr = face->getTexture();
    TextureChunkPtr texChunk = TextureChunk::create();
    beginEditCP(texChunk);
    {
        texChunk->setImage(imagePtr);
        texChunk->setWrapS(GL_CLAMP);
        texChunk->setWrapT(GL_CLAMP);
        texChunk->setMagFilter(GL_NEAREST);
        texChunk->setMinFilter(GL_NEAREST);
        texChunk->setEnvMode(GL_MODULATE);
    }
    endEditCP(texChunk);

    MaterialChunkPtr matChunk = MaterialChunk::create();
    beginEditCP(matChunk);
    {
        matChunk->setAmbient(Color4f(1.f, 1.f, 1.f, 1.f));
        matChunk->setDiffuse(Color4f(1.f, 1.f, 1.f, 1.f));
        matChunk->setEmission(Color4f(0.f, 0.f, 0.f, 1.f));
        matChunk->setSpecular(Color4f(0.f, 0.f, 0.f, 1.f));
        matChunk->setShininess(0);
    }
    endEditCP(matChunk);

    BlendChunkPtr blendChunk = BlendChunk::create();
    beginEditCP(blendChunk);
    {
        blendChunk->setSrcFactor(GL_SRC_ALPHA);
        blendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
    }
    endEditCP(blendChunk);

    ChunkMaterialPtr m = ChunkMaterial::create();
    beginEditCP(m);
    {
        m->addChunk(texChunk);
        m->addChunk(matChunk);
        m->addChunk(blendChunk);
    }
    endEditCP(m);

    beginEditCP(geo, Geometry::MaterialFieldMask);
    {
        geo->setMaterial(m);
    }
    endEditCP(geo, Geometry::MaterialFieldMask);

    beginEditCP(scene, Node::ChildrenFieldMask);
    {
        scene->editMFChildren()->clear();
        scene->addChild(createCoordinateCross());
        scene->addChild(createMetrics(face, scale, layoutParam, layoutResult));
        scene->addChild(transNodePtr);
    }
    endEditCP(scene, Node::ChildrenFieldMask);

    mgr->showAll();
    glutPostRedisplay();
}
// Initialize OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindowEventProducer = createDefaultWindowEventProducer();
    WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();

    TutorialWindowEventProducer->setDisplayCallback(display);
    TutorialWindowEventProducer->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener);
    TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener);
    TutorialUpdateListener TheTutorialUpdateListener;
    TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener);

    
    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(MainWindow);
    

    //Print key command info
    std::cout << "\n\nKEY COMMANDS:" << std::endl;
    std::cout << "space   Play/Pause the animation" << std::endl;
    std::cout << "B       Show/Hide the bind pose skeleton" << std::endl;
    std::cout << "SHIFT-B Show/Hide the bind pose mesh" << std::endl;
    std::cout << "P       Show/Hide the current pose skeleton" << std::endl;
    std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl;
    std::cout << "O       Toggle override status of TheSecondAnimation" << std::endl;
    std::cout << "CTRL-Q  Exit\n\n" << std::endl;


    
    //Import scene from XML
    ChunkMaterialPtr ExampleMaterial;
    std::vector<SkeletonPtr> SkeletonPtrs;
    std::vector<SkeletonBlendedGeometryPtr> SkeletonBlendedGeometryPtrs;
    std::vector<GeometryPtr> GeometryPtrs;

    //Skeleton materaial
    LineChunkPtr SkelLineChunk = LineChunk::create();
    beginEditCP(SkelLineChunk);
        SkelLineChunk->setWidth(0.0f);
        SkelLineChunk->setSmooth(true);
    endEditCP(SkelLineChunk);

    ChunkMaterialPtr SkelMaterial = ChunkMaterial::create();
    beginEditCP(SkelMaterial, ChunkMaterial::ChunksFieldMask);
        SkelMaterial->addChunk(SkelLineChunk);
    endEditCP(SkelMaterial, ChunkMaterial::ChunksFieldMask);

    //LOAD FIRST ANIMATION
    FCFileType::FCPtrStore NewContainers;
    NewContainers = FCFileHandler::the()->read(BoostPath("./Data/23WalkingAnimation.xml"));
    FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
        if( (*Itor)->getType() == (ChunkMaterial::getClassType()))
        {
            //Set ExampleMaterial to the ChunkMaterial we just read in
            ExampleMaterial = (ChunkMaterial::Ptr::dcast(*Itor));
        }
        if( (*Itor)->getType() == (Skeleton::getClassType()))
        {
            //Add the Skeleton we just read in to SkeletonPtrs
            SkeletonPtrs.push_back(Skeleton::Ptr::dcast(*Itor));
        }
        if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType()))
        {
            //Add the SkeletonBlendedGeometry we just read in to SkeletonBlendedGeometryPtrs
            SkeletonBlendedGeometryPtrs.push_back(SkeletonBlendedGeometry::Ptr::dcast(*Itor));
        }
        if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType()))
        {
            //Set TheWalkingAnimation to the SkeletonAnimation we just read in
            TheWalkingAnimation = (SkeletonAnimation::Ptr::dcast(*Itor));
        }
        if( (*Itor)->getType() == (Geometry::getClassType()))
        {
            //Add the Geometry we just read in to GeometryPtrs
            GeometryPtrs.push_back(Geometry::Ptr::dcast(*Itor));
        }
    }

    //LOAD SECOND ANIMATION
    NewContainers = FCFileHandler::the()->read(BoostPath("./Data/23SamAnimation.xml"));
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
         //Import only the skeletonAnimation from the second XML file; we've already imported the skeleton and the geometry
        if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType()))
        {
            TheSecondAnimation = (SkeletonAnimation::Ptr::dcast(*Itor));
        }
    }

    //Blend the two animations
    TheSkeletonBlendedAnimation = SkeletonBlendedAnimation::create();
    beginEditCP(TheSkeletonBlendedAnimation);
        TheSkeletonBlendedAnimation->addAnimationBlending(TheWalkingAnimation, BlendWalking, false);
        TheSkeletonBlendedAnimation->addAnimationBlending(TheSecondAnimation, BlendTouchScreen, false);
    endEditCP(TheSkeletonBlendedAnimation);


    
    //Create unbound geometry Node (to show the mesh in its bind pose)
    for (int i(0); i < GeometryPtrs.size(); ++i)
    {
        NodePtr UnboundGeometry = Node::create();
        beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask);
            UnboundGeometry->setCore(GeometryPtrs[i]);
            UnboundGeometry->setTravMask(0);  //By default, we don't show the mesh in its bind pose.
        endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask);

        UnboundGeometries.push_back(UnboundGeometry);
    }


    //Create skeleton nodes
    for (int i(0); i < SkeletonPtrs.size(); ++i)
    {
        //SkeletonDrawer
        SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create();
        beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask  | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask);
            ExampleSkeletonDrawable->setSkeleton(SkeletonPtrs[i]);
            ExampleSkeletonDrawable->setMaterial(SkelMaterial);
            ExampleSkeletonDrawable->setDrawPose(true);                                  //By default we draw the current skeleton
            ExampleSkeletonDrawable->setPoseColor(Color4f(1.0, 0.0, 1.0, 1.0));       //Set color of current skeleton
            ExampleSkeletonDrawable->setDrawBindPose(false);                          //By default we don't draw the bind pose skeleton
            ExampleSkeletonDrawable->setBindPoseColor(Color4f(1.0, 1.0, 0.0, 1.0));   //Set color of bind pose skeleton
        endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask  | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask);
        
        //Skeleton Node
        NodePtr SkeletonNode = osg::Node::create();
        beginEditCP(SkeletonNode, Node::CoreFieldMask);
            SkeletonNode->setCore(ExampleSkeletonDrawable);
        endEditCP(SkeletonNode, Node::CoreFieldMask);

        SkeletonNodes.push_back(SkeletonNode);
    }



    //Create skeleton blended geometry nodes
    for (int i(0); i < SkeletonBlendedGeometryPtrs.size(); ++i)
    {
        NodePtr MeshNode = osg::Node::create();
        beginEditCP(MeshNode, Node::CoreFieldMask);
            MeshNode->setCore(SkeletonBlendedGeometryPtrs[i]);
        endEditCP(MeshNode, Node::CoreFieldMask);

        MeshNodes.push_back(MeshNode);
    }



    //Setup scene
    NodePtr EmptyScene = osg::Node::create();
    beginEditCP(EmptyScene, Node::CoreFieldMask);
        EmptyScene->setCore(Group::create());
    endEditCP  (EmptyScene, Node::CoreFieldMask);

    mgr->setRoot(EmptyScene);



    //User Interface
    // Create the Graphics
    GraphicsPtr TutorialGraphics = osg::Graphics2D::create();

    // Initialize the LookAndFeelManager to enable default settings
    LookAndFeelManager::the()->getLookAndFeel()->init();

    // Create the DefaultBoundedRangeModelPtr and 
    // set its values
    DefaultBoundedRangeModelPtr UpperAnimationSliderRangeModel = DefaultBoundedRangeModel::create();
    UpperAnimationSliderRangeModel->setMinimum(0);
    UpperAnimationSliderRangeModel->setMaximum(100);
    UpperAnimationSliderRangeModel->setValue(BlendWalking * 100);
    UpperAnimationSliderRangeModel->setExtent(0);
    
    //Create the upper animation blend amount slider
    LabelPtr TempLabel;
    SliderPtr UpperAnimationSlider = Slider::create();
    beginEditCP(UpperAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask);

     //Label the slider
        TempLabel = Label::Ptr::dcast(UpperAnimationSlider->getLabelPrototype()->shallowCopy());
        beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("0.0"); endEditCP(TempLabel, Label::TextFieldMask);
        UpperAnimationSlider->getLabelMap()[0] = TempLabel;

        TempLabel = Label::Ptr::dcast(UpperAnimationSlider->getLabelPrototype()->shallowCopy());
        beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("1.0"); endEditCP(TempLabel, Label::TextFieldMask);
        UpperAnimationSlider->getLabelMap()[100] = TempLabel;

        //Customize the slider
        UpperAnimationSlider->setPreferredSize(Vec2f(100, 300));
        UpperAnimationSlider->setSnapToTicks(false);
        UpperAnimationSlider->setMajorTickSpacing(10);
        UpperAnimationSlider->setMinorTickSpacing(5);
        UpperAnimationSlider->setOrientation(Slider::VERTICAL_ORIENTATION);
        UpperAnimationSlider->setInverted(true);
        UpperAnimationSlider->setDrawLabels(true);
        UpperAnimationSlider->setRangeModel(UpperAnimationSliderRangeModel);
    endEditCP(UpperAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask);
    
    DefaultBoundedRangeModelPtr LowerAnimationSliderRangeModel = DefaultBoundedRangeModel::create();
    LowerAnimationSliderRangeModel->setMinimum(0);
    LowerAnimationSliderRangeModel->setMaximum(100);
    LowerAnimationSliderRangeModel->setValue(BlendTouchScreen * 100);
    LowerAnimationSliderRangeModel->setExtent(0);
    
    //Create the lower animation blend amount slider
    SliderPtr LowerAnimationSlider = Slider::create();
    beginEditCP(LowerAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask);

     //Label the slider
        TempLabel = Label::Ptr::dcast(LowerAnimationSlider->getLabelPrototype()->shallowCopy());
        beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("0.0"); endEditCP(TempLabel, Label::TextFieldMask);
        LowerAnimationSlider->getLabelMap()[0] = TempLabel;

        TempLabel = Label::Ptr::dcast(LowerAnimationSlider->getLabelPrototype()->shallowCopy());
        beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("1.0"); endEditCP(TempLabel, Label::TextFieldMask);
        LowerAnimationSlider->getLabelMap()[100] = TempLabel;

        //Customize the slider
        LowerAnimationSlider->setPreferredSize(Vec2f(100, 300));
        LowerAnimationSlider->setSnapToTicks(false);
        LowerAnimationSlider->setMajorTickSpacing(10);
        LowerAnimationSlider->setMinorTickSpacing(5);
        LowerAnimationSlider->setOrientation(Slider::VERTICAL_ORIENTATION);
        LowerAnimationSlider->setInverted(true);
        LowerAnimationSlider->setDrawLabels(true);
        LowerAnimationSlider->setRangeModel(LowerAnimationSliderRangeModel);
    endEditCP(LowerAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask);

    // Create Background to be used with the MainFrame
    ColorLayerPtr MainFrameBackground = osg::ColorLayer::create();
    beginEditCP(MainFrameBackground, ColorLayer::ColorFieldMask);
        MainFrameBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
    endEditCP(MainFrameBackground, ColorLayer::ColorFieldMask);

    // Create The Main InternalWindow
    // Create Background to be used with the Main InternalWindow
    ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create();
    beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
    endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask);

    LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create();

    //GL Viewport
    ComponentPtr TheGLViewport = createGLPanel();
    InternalWindowPtr MainInternalWindow = osg::InternalWindow::create();
    beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);
       MainInternalWindow->getChildren().push_back(UpperAnimationSlider);
       MainInternalWindow->getChildren().push_back(LowerAnimationSlider);
       MainInternalWindow->getChildren().push_back(TheGLViewport);
       MainInternalWindow->setLayout(MainInternalWindowLayout);
       MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
       MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
       MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f));
       MainInternalWindow->setDrawTitlebar(false);
       MainInternalWindow->setResizable(false);
    endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask);

    // Create the Drawing Surface
    UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create();
    beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer);
    endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask);
    
    TutorialDrawingSurface->openWindow(MainInternalWindow);

    // Create the UI Foreground Object
    UIForegroundPtr TutorialUIForeground = osg::UIForeground::create();

    beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);
        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
    endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask);

    ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);
        TutorialViewport->getForegrounds().push_back(TutorialUIForeground);
    beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask);

    //Attach the Slider Listeners
    BlendAmountSliderChangeListener UpperAnimationSliderListener(TheSkeletonBlendedAnimation, 0, UpperAnimationSlider);
    UpperAnimationSlider->addChangeListener(&UpperAnimationSliderListener);
    
    BlendAmountSliderChangeListener LowerAnimationSliderListener(TheSkeletonBlendedAnimation, 1, LowerAnimationSlider);
    LowerAnimationSlider->addChangeListener(&LowerAnimationSliderListener);

    //Animation Advancer
    TheAnimationAdvancer = ElapsedTimeAnimationAdvancer::create();
    beginEditCP(TheAnimationAdvancer);
    ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 );


    beginEditCP(TheAnimationAdvancer);

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
    
    // Show the whole Scene
    mgr->showAll();
    TheAnimationAdvancer->start();

     //Show window
    Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TutorialWindowEventProducer->openWindow(WinPos,
                        WinSize,
                                        "23BlendXMLAnimations");

    //Enter main Loop
    TutorialWindowEventProducer->mainLoop();

    osgExit();

    return 0;
}
Пример #13
0
int main(int argc, char **argv)
{
    osgInit(argc,argv);

    // GLUT init
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    
    int id=glutCreateWindow("OpenSG");
    
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);

    GLUTWindowPtr gwin=GLUTWindow::create();
    gwin->setId(id);
    gwin->init();

    // create the scene
//    NodePtr scene = makeTorus(.5, 2, 16, 16);
    NodePtr scene = makeBox(1,1,1, 1,1,1);

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin );
    mgr->setRoot  (scene);
    
    // Create the textured material
    UChar8 imgdata[] =
      {  255,0,0,128,  0,255,0,128,  0,0,255,255,  255,255,255,255 };
   
    ImagePtr img = Image::create();
    beginEditCP(img);
    if(argc > 1)
        img->read(argv[1]);
    else
        img->set( Image::OSG_RGBA_PF, 2, 2, 1, 1, 1, 0, imgdata );
    endEditCP(img);
    addRefCP(img);
   
    SimpleTexturedMaterialPtr mat = SimpleTexturedMaterial::create();
    beginEditCP(mat);
    mat->setLit(false);
    mat->setDiffuse(Color3f(0,1,0));
    mat->setImage(img);
    mat->setMinFilter(GL_NEAREST);
    mat->setMagFilter(GL_NEAREST);
    mat->setEnvMode(GL_REPLACE);
    endEditCP(mat);
    
    // Add the polygon foregrounds
    
    Pnt2f pos[][4] = { 
        { Vec2f(.4,.4), Vec2f(.6,.4), Vec2f(.6,.6), Vec2f(.4,.6) },
        { Vec2f(0,0), Vec2f(1,0), Vec2f(1,.1), Vec2f(0,.1) },
        { Vec2f(1,-100), Vec2f(-2,-100), Vec2f(-2,-2), Vec2f(1,-2) },
        { Vec2f(-1000,-1000), Vec2f(0,0), Vec2f(0,0), Vec2f(0,0) }
    };
    bool normx[] = { true, true, false };
    bool normy[] = { true, true, false };
    
    for(UInt16 ind = 0; pos[ind][0][0] != -1000; ++ind)
    {   
        PolygonForegroundPtr pg = PolygonForeground::create();

        beginEditCP(pg);
        pg->setMaterial(mat);
        pg->editMFTexCoords()->push_back(Vec3f( 0.,0.,0.));
        pg->editMFPositions()->push_back(pos[ind][0]);
        pg->editMFTexCoords()->push_back(Vec3f( 1.,0.,0.));
        pg->editMFPositions()->push_back(pos[ind][1]);
        pg->editMFTexCoords()->push_back(Vec3f( 1.,1.,0.));
        pg->editMFPositions()->push_back(pos[ind][2]);
        pg->editMFTexCoords()->push_back(Vec3f( 0.,1.,0.));
        pg->editMFPositions()->push_back(pos[ind][3]);
 
        pg->setNormalizedX(normx[ind]);
        pg->setNormalizedY(normy[ind]);
        endEditCP(pg);

        // take the viewport
        ViewportPtr vp = gwin->getPort(0);

        beginEditCP(vp);
        vp->editMFForegrounds()->push_back(pg);    
        endEditCP  (vp);
    }
     
    // Create the edgeblend foreground
    const int blendpixel = 50;
    
    UChar8 ebimgdata[] =
      {  0,0,0,0,  0,0,0,255 };
   
    ImagePtr ebimg = Image::create();
    beginEditCP(ebimg);
    ebimg->set( Image::OSG_RGBA_PF, 2, 1, 1, 1, 1, 0, ebimgdata );
    endEditCP(ebimg);
    addRefCP(ebimg);
   
    TextureChunkPtr tc = TextureChunk::create();
    beginEditCP(tc);
    tc->setImage(ebimg);
    tc->setMinFilter(GL_NEAREST);
    tc->setMagFilter(GL_LINEAR);
    tc->setEnvMode(GL_REPLACE);
    tc->setWrapS(GL_CLAMP);
    endEditCP(tc);
    
    BlendChunkPtr bl = BlendChunk::create();
    beginEditCP(bl);
    bl->setSrcFactor(GL_SRC_ALPHA);
    bl->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
    endEditCP(bl);
    
    ChunkMaterialPtr ebmat = ChunkMaterial::create();
    beginEditCP(ebmat);
    ebmat->addChunk(tc);
    ebmat->addChunk(bl);
    endEditCP(ebmat);

    PolygonForegroundPtr ebpg = PolygonForeground::create();

    beginEditCP(ebpg);
    ebpg->setMaterial(ebmat);
    ebpg->editMFTexCoords()->push_back(Vec3f( 0.25,0.,0.));
    ebpg->editMFTexCoords()->push_back(Vec3f( 0.75,0.,0.));
    ebpg->editMFTexCoords()->push_back(Vec3f( 0.75,1.,0.));
    ebpg->editMFTexCoords()->push_back(Vec3f( 0.25,1.,0.));

    ebpg->editMFPositions()->push_back(Pnt2f(-blendpixel-1, 0));
    ebpg->editMFPositions()->push_back(Pnt2f(           -1, 0));
    ebpg->editMFPositions()->push_back(Pnt2f(           -1, 1));
    ebpg->editMFPositions()->push_back(Pnt2f(-blendpixel-1, 1));

    ebpg->setNormalizedX(false);
    ebpg->setNormalizedY(true);
    endEditCP(ebpg);

    // take the viewport
    ViewportPtr vp = gwin->getPort(0);

    beginEditCP(vp);
    vp->editMFForegrounds()->push_back(ebpg);    
    endEditCP  (vp);

// show the whole scene
    mgr->showAll();
    
    // GLUT main loop
    glutMainLoop();

    return 0;
}
Пример #14
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    printf("Usage: testCGShader [base texture filename] [normal map filename]\n");
    char *base_img_name = "wood.jpg";
    char *normal_map_img_name = "normalmap.jpg";

    Color4f tmp;

    if( argc > 1 )
        base_img_name = argv[1];
    if( argc > 2 )
        normal_map_img_name = argv[2];

    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->setSize( 800, 800 );
    gwin->init();

    // Create the shader material

    // Read the image for the base texture
    ImagePtr base_img = Image::create();
    if(!base_img->read(base_img_name))
    {
        fprintf(stderr, "Couldn't read base texture '%s'!\n", base_img_name);
        return 1;
    }

    ImagePtr normal_map_img = 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;
    }

    ChunkMaterialPtr cmat = ChunkMaterial::create();

    MaterialChunkPtr matc = MaterialChunk::create();
    beginEditCP(matc);
        matc->setAmbient(Color4f(0.1, 0.1, 0.1, 1.0));
        matc->setDiffuse(Color4f(0.3, 0.3, 0.3, 1.0));
        matc->setSpecular(Color4f(0.8, 0.8, 0.8, 1.0));
        matc->setShininess(100);
        matc->setLit(true);
    endEditCP(matc);

    // we use the glstate in the cg program so we force
    // to use the CG_PROFILE_ARBVP1 and CG_PROFILE_ARBFP1 extensions.

    CGChunkPtr cg = CGChunk::create();
    beginEditCP(cg);
        cg->setVertexProfile(CG_PROFILE_ARBVP1);
        cg->setVertexProgram(_vp_program);
        cg->setFragmentProfile(CG_PROFILE_ARBFP1);
        cg->setFragmentProgram(_fp_program);
        // some optional parameters.
        //cg->setVertexEntryPoint("main");
        //cg->getVertexArguments().push_back("...");
        //cg->setFragmentEntryPoint("main");
        //cg->getFragmentArguments().push_back("...");
    endEditCP(cg);

    TextureChunkPtr tex_base = TextureChunk::create();
    beginEditCP(tex_base);
        tex_base->setImage(base_img);
        tex_base->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
        tex_base->setMagFilter(GL_LINEAR);
        tex_base->setWrapS(GL_REPEAT);
        tex_base->setWrapT(GL_REPEAT);
        tex_base->setEnvMode(GL_MODULATE);
    endEditCP(tex_base);

    TextureChunkPtr tex_normal_map = TextureChunk::create();
    beginEditCP(tex_normal_map);
        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->setEnvMode(GL_MODULATE);
    endEditCP(tex_normal_map);

    beginEditCP(cmat);
        cmat->addChunk(matc);
        cmat->addChunk(cg);
        cmat->addChunk(tex_base);
        cmat->addChunk(tex_normal_map);
    endEditCP(cmat);


    // create root node
    _scene = Node::create();

    // create torus
    GeometryPtr geo = makeTorusGeo(.8, 1.8, 128, 128);
    beginEditCP( geo, Geometry::MaterialFieldMask);
        geo->setMaterial(cmat);
    endEditCP(geo, Geometry::MaterialFieldMask);

    NodePtr torus = Node::create();
    beginEditCP(torus, Node::CoreFieldMask);
        torus->setCore(geo);
    endEditCP(torus, Node::CoreFieldMask);

    // add torus to scene
    GroupPtr group = Group::create();
    beginEditCP(_scene);
        _scene->setCore(group);
        _scene->addChild(torus);
    endEditCP(_scene);

    // create the SimpleSceneManager helper
    _mgr = new SimpleSceneManager;

    // tell the manager what to manage
    _mgr->setWindow(gwin );
    _mgr->setRoot(_scene);

    // show the whole scene
    _mgr->showAll();

    // GLUT main loop
    glutMainLoop();

    return 0;
}
Пример #15
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->setSize( 800, 800 );
    gwin->init();

    // Create the shader material
    ChunkMaterialPtr cmat = ChunkMaterial::create();

    // Read the image for the normal texture
    ImagePtr earth_map_img = Image::create();
    if(!earth_map_img->read("earth.jpg"))
    {
        fprintf(stderr, "Couldn't read texture 'Earth.jpg'\n");
        return 1;
    }
    TextureChunkPtr tex_earth = TextureChunk::create();
    beginEditCP(tex_earth);
        tex_earth->setImage(earth_map_img);
        tex_earth->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
        tex_earth->setMagFilter(GL_LINEAR);
        tex_earth->setWrapS(GL_REPEAT);
        tex_earth->setWrapT(GL_REPEAT);
        tex_earth->setEnvMode(GL_MODULATE);
    endEditCP(tex_earth);

    // Read the image for the normal texture
    ImagePtr earth_night_map_img = Image::create();
    if(!earth_night_map_img->read("EarthNight.jpg"))
    {
        fprintf(stderr, "Couldn't read texture 'EarthNight.jpg'\n");
        return 1;
    }
    TextureChunkPtr tex_earth_night = TextureChunk::create();
    beginEditCP(tex_earth_night);
        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->setEnvMode(GL_MODULATE);
    endEditCP(tex_earth_night);
    
    // Read the image for the normal texture
    ImagePtr earth_clouds_map_img = Image::create();
    if(!earth_clouds_map_img->read("EarthClouds.jpg"))
    {
        fprintf(stderr, "Couldn't read texture 'EarthClouds.jpg'\n");
        return 1;
    }
    TextureChunkPtr tex_earth_clouds = TextureChunk::create();
    beginEditCP(tex_earth_clouds);
        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->setEnvMode(GL_MODULATE);
    endEditCP(tex_earth_clouds);

    _shl = SHLChunk::create();
    beginEditCP(_shl);
        if(!_shl->readVertexProgram("Earth.vp"))
            fprintf(stderr, "Couldn't read vertex program 'Earth.vp'\n");
        if(!_shl->readFragmentProgram("Earth.fp"))
            fprintf(stderr, "Couldn't read fragment program 'Earth.fp'\n");
        _shl->setUniformParameter("EarthDay", 0);
        _shl->setUniformParameter("EarthNight", 1);
        _shl->setUniformParameter("EarthCloudGloss", 2);
        _shl->setUniformParameter("season", 0.0f);
        _shl->setUniformParameter("cos_time_0_2PI", -0.406652f);
        _shl->setUniformParameter("sin_time_0_2PI", -0.913583f);
    endEditCP(_shl);

    beginEditCP(cmat);
        cmat->addChunk(_shl);
        cmat->addChunk(tex_earth);
        cmat->addChunk(tex_earth_night);
        cmat->addChunk(tex_earth_clouds);
    endEditCP(cmat);


    // create root node
    _scene = Node::create();

    GeometryPtr geo = makeLatLongSphereGeo (100, 100, 1.0);
    beginEditCP( geo, Geometry::MaterialFieldMask);
        geo->setMaterial(cmat);
    endEditCP(geo, Geometry::MaterialFieldMask);

    NodePtr torus = Node::create();
    beginEditCP(torus, Node::CoreFieldMask);
        torus->setCore(geo);
    endEditCP(torus, Node::CoreFieldMask);

    // add torus to scene
    GroupPtr group = Group::create();
    beginEditCP(_scene);
        _scene->setCore(group);
        _scene->addChild(torus);
    endEditCP(_scene);

    // create the SimpleSceneManager helper
    _mgr = new SimpleSceneManager;

    // tell the manager what to manage
    _mgr->setWindow(gwin );
    _mgr->setRoot(_scene);

    // show the whole scene
    _mgr->showAll();

    // GLUT main loop
    glutMainLoop();

    return 0;
}
Пример #16
0
// 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
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->setSize( 800, 800 );
    gwin->init();

    // Create the shader material
    ChunkMaterialPtr cmat = ChunkMaterial::create();

    MaterialChunkPtr matc = MaterialChunk::create();
    beginEditCP(matc);
        matc->setAmbient(Color4f(0.1, 0.1, 0.1, 1.0));
        matc->setDiffuse(Color4f(0.3, 0.3, 0.3, 1.0));
        matc->setSpecular(Color4f(0.8, 0.8, 0.8, 1.0));
        matc->setShininess(100);
        matc->setLit(true);
    endEditCP(matc);

    SHLChunkPtr shl = SHLChunk::create();
    beginEditCP(shl);
        shl->readVertexProgram(argv[1]);
        shl->readFragmentProgram(argv[2]);
    endEditCP(shl);

    beginEditCP(cmat);
        cmat->addChunk(shl);
    endEditCP(cmat);


    // create root node
    _scene = Node::create();

    // create torus
    GeometryPtr geo = makeTorusGeo(.8, 1.8, 128, 128);
    beginEditCP( geo, Geometry::MaterialFieldMask);
        geo->setMaterial(cmat);
    endEditCP(geo, Geometry::MaterialFieldMask);

    NodePtr torus = Node::create();
    beginEditCP(torus, Node::CoreFieldMask);
        torus->setCore(geo);
    endEditCP(torus, Node::CoreFieldMask);

    // add torus to scene
    GroupPtr group = Group::create();
    beginEditCP(_scene);
        _scene->setCore(group);
        _scene->addChild(torus);
    endEditCP(_scene);

    // create the SimpleSceneManager helper
    _mgr = new 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);
        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;
}
Пример #17
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->setSize( 800, 800 );
    gwin->init();

    // Create the shader material
    ChunkMaterialPtr cmat = ChunkMaterial::create();

    SHLChunkPtr shl = SHLChunk::create();
    beginEditCP(shl);
        shl->setProgramParameter(GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES_ADJACENCY_EXT);
        shl->setProgramParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLES);
        // ok we create a maximum of 6 vertices.
        shl->setProgramParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 6);

        shl->setVertexProgram(_vertex_shader);
        shl->setFragmentProgram(_fragment_shader);
        shl->setGeometryProgram(_geometry_shader);
    endEditCP(shl);

    beginEditCP(cmat);
        cmat->addChunk(shl);
    endEditCP(cmat);

    // create root node
    _scene = Node::create();

    // create torus
    GeometryPtr geo = makeTorusGeo(.8, 1.8, 32, 32);
    beginEditCP( geo, Geometry::MaterialFieldMask);
        geo->setMaterial(cmat);
    endEditCP(geo, Geometry::MaterialFieldMask);

    NodePtr torus = Node::create();
    beginEditCP(torus, Node::CoreFieldMask);
        torus->setCore(geo);
    endEditCP(torus, Node::CoreFieldMask);

    // add torus to scene
    GroupPtr group = Group::create();
    beginEditCP(_scene);
        _scene->setCore(group);
        _scene->addChild(torus);
    endEditCP(_scene);

    // create the SimpleSceneManager helper
    _mgr = new SimpleSceneManager;

    // tell the manager what to manage
    _mgr->setWindow(gwin );
    _mgr->setRoot(_scene);

    // show the whole scene
    _mgr->showAll();

    // GLUT main loop
    glutMainLoop();

    return 0;
}
Пример #18
0
int main( int argc, char **argv )
{
    ChangeList::setReadWriteDefault();
    osgInit(argc,argv);

    _main_thread = Thread::getCurrent();
    _sync_barrier = Barrier::get("RenderBarrier");

    QApplication::setColorSpec( QApplication::CustomColor );
    QApplication a( argc, argv );

    if(!QGLFormat::hasOpenGL())
    {
        qWarning( "This system has no OpenGL support. Exiting." );
        return -1;
    }
    
    _render_widget = new OpenSGWidget(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba |
                                      QGL::DirectRendering));

    NodePtr scene = makePlane(1.0, 1.0, 50, 50);

    MaterialChunkPtr matc = MaterialChunk::create();
    beginEditCP(matc);
        matc->setAmbient(Color4f(0.3, 0.3, 0.3, 1.0));
        matc->setDiffuse(Color4f(0.2, 0.2, 0.8, 1.0));
        matc->setSpecular(Color4f(0.6, 0.6, 0.6, 1.0));
        matc->setShininess(100);
    endEditCP(matc);
    
    ChunkMaterialPtr cmat = ChunkMaterial::create();
    beginEditCP(cmat);
        cmat->addChunk(matc);
    endEditCP(cmat);
    
    _geo = GeometryPtr::dcast(scene->getCore());
    beginEditCP(_geo);
        _geo->setDlistCache(false);
        _geo->setMaterial(cmat);
    endEditCP(_geo);

    initWave();
    resetWave();


    _render_widget->getManager()->setRoot(scene);
    _render_widget->getManager()->showAll();
    _render_widget->getManager()->getNavigator()->setFrom(Pnt3f(1.0f, -1.0f, 1.0f));
    _render_widget->getManager()->getNavigator()->setUp(Vec3f(0.0f, 0.0f, 1.0f));

    _render_widget->show();
    while(!_render_widget->isInitialized())
        qApp->processEvents();

    // The gl widget is initialized in the main thread!
    // Without the doneCurrent() the next makeCurrent() call in the render thread
    // doesn't work because qt thinks that the context is already current but this
    // was in the main thread ...
    _render_widget->doneCurrent();

    // start render thread
    _render_thread = dynamic_cast<Thread *>(ThreadManager::the()->getThread("RenderThread"));
    _render_thread->runFunction(renderThread, 1, NULL);
    
    // main loop
    while(!_quit)
    {
        mainThread();

        // sync
        _sync_barrier->enter(2);
        if(_do_quit)
            _quit = true;
        _sync_barrier->enter(2);
        
        _main_thread->getChangeList()->clearAll();

        qApp->processEvents();
    }

    Thread::join(_render_thread);
    return 0;
}
Пример #19
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin = GLUTWindow::create();
    beginEditCP(gwin);
        gwin->setId(winid);
        gwin->setSize( 800, 800 );
        gwin->init();
    endEditCP(gwin);

    // create root node
    _scene = makeCoredNode<Group>();

    GeometryPtr geo = makeBoxGeo(0.5, 0.5, 0.5, 1, 1, 1);

    // share the chunk
    CGChunkPtr cg = CGChunk::create();
    beginEditCP(cg);
        cg->setVertexProfile(CG_PROFILE_ARBVP1);
        cg->setVertexProgram(_vp_program);
        cg->setFragmentProfile(CG_PROFILE_ARBFP1);
        cg->setFragmentProgram(_fp_program);
    endEditCP(cg);

    Int32 size = 4;
    
    // start color
    Vec3f sc(0.0, 0.0, 0.0);
    
    // end color
    Vec3f ec(1.0, 1.0, 1.0);

    Real32 sr = (ec[0] - sc[0]) / Real32((size*2));
    Real32 sg = (ec[1] - sc[1]) / Real32((size*2));
    Real32 sb = (ec[2] - sc[2]) / Real32((size*2));
    
    Vec3f color(sc);

    Int32 x = - size;
    Int32 y = - size;
    Int32 z = - size;

    UInt32 iterations = size*2 * size*2 * size*2;

    printf("Creating %u cubes ...\n", iterations);
    for(UInt32 i=0;i<iterations;++i)
    {
        ChunkMaterialPtr cmat = ChunkMaterial::create();

        // ok use one CGChunk and n CGParameterChunks
        CGParameterChunkPtr cgparameter = CGParameterChunk::create();
        beginEditCP(cgparameter);
            cgparameter->setCGChunk(cg);
            cgparameter->setUniformParameter("SurfaceColor", color);
        endEditCP(cgparameter);
        _cgparameter = cgparameter;

        beginEditCP(cmat);
            cmat->addChunk(cg);
            cmat->addChunk(cgparameter);
        endEditCP(cmat);
    
        TransformPtr trans;
        NodePtr trans_node = makeCoredNode<Transform>(&trans);
        beginEditCP(trans);
            trans->getMatrix().setTranslate(Real32(x), Real32(y), Real32(z));
        endEditCP(trans);

        MaterialGroupPtr mg;
        NodePtr mg_node = makeCoredNode<MaterialGroup>(&mg);
        beginEditCP(mg, MaterialGroup::MaterialFieldMask);
            mg->setMaterial(cmat);
        endEditCP(mg, MaterialGroup::MaterialFieldMask);

        NodePtr geonode = Node::create();
        beginEditCP(geonode, Node::CoreFieldMask);
            geonode->setCore(geo);
        endEditCP(geonode, Node::CoreFieldMask);
        
        beginEditCP(mg_node);
            mg_node->addChild(geonode);
        endEditCP(mg_node);

        beginEditCP(trans_node);
            trans_node->addChild(mg_node);
        endEditCP(trans_node);
    
        // add to scene
        beginEditCP(_scene);
            _scene->addChild(trans_node);
        endEditCP(_scene);
        
        // ----
        ++x;
        color[0] += sr;

        if(x == size)
        {
            x = - size;
            ++y;
            color[0] = sc[0];
            color[1] += sg;
            if(y == size)
            {
                y = - size;
                ++z;
                color[1] = sc[1];
                color[2] += sb;
            }
        }
    }


    // create the SimpleSceneManager helper
    _mgr = new SimpleSceneManager;

    // tell the manager what to manage
    _mgr->setWindow(gwin );
    _mgr->setRoot(_scene);

    // show the whole scene
    _mgr->showAll();

    // create a gradient background.
    GradientBackgroundPtr gback = GradientBackground::create();
    beginEditCP(gback, GradientBackground::LineFieldMask);
        gback->clearLines();
        gback->addLine(Color3f(0.7, 0.7, 0.8), 0);
        gback->addLine(Color3f(0.0, 0.1, 0.3), 1);
    endEditCP(gback, GradientBackground::LineFieldMask);

    WindowPtr win = _mgr->getWindow();
    beginEditCP(win);
        for(int i=0;i<win->getPort().size();++i)
        {
            ViewportPtr vp = win->getPort()[i];
            beginEditCP(vp);
                vp->setBackground(gback);
            endEditCP(vp);
        }
    endEditCP(win);
        
    // GLUT main loop
    glutMainLoop();

    return 0;
}
Пример #20
0
MaterialPtr PerformerLoader::traverseGState(NodePtr node, pfGeoState *gstate)
{
    FDEBUG(("PerformerLoader::traverseGState: traversing %p\n", gstate));
    
    if(_materials.find(gstate) != _materials.end())
    {
        FDEBUG(("PfL:traverseGState: found in matmap.\n"));    
        
        return _materials[gstate];
    }

    ChunkMaterialPtr mat = ChunkMaterial::create();
    beginEditCP(mat);
    
	uint64_t inherit;
	inherit = gstate->getInherit();
    
    static int pcolormode[] = { PFMTL_CMODE_AMBIENT_AND_DIFFUSE,
                                PFMTL_CMODE_AMBIENT,
                                PFMTL_CMODE_DIFFUSE,
                                PFMTL_CMODE_EMISSION,
                                PFMTL_CMODE_SPECULAR,
                                PFMTL_CMODE_OFF,
                                -1
                              };
    static int ocolormode[] = { GL_AMBIENT_AND_DIFFUSE,
                                GL_AMBIENT,
                                GL_DIFFUSE,
                                GL_EMISSION,
                                GL_SPECULAR,
                                GL_NONE
                              };

    pair<void *, void*> key;
    
    if((inherit & (PFSTATE_FRONTMTL | PFSTATE_BACKMTL)) != 
                  (PFSTATE_FRONTMTL | PFSTATE_BACKMTL)
      )
    {
        MaterialChunkPtr matc;
        
        key.first = NULL;
	    if (!(inherit & PFSTATE_FRONTMTL))
            key.first = gstate->getAttr(PFSTATE_FRONTMTL);

        key.second = NULL;
	    if (!(inherit & PFSTATE_BACKMTL))
            key.second = gstate->getAttr(PFSTATE_BACKMTL);

        if(_chunks.find(key) != _chunks.end())
        {    
            matc = MaterialChunkPtr::dcast(_chunks[key]);
        }
        else
        {
            matc = MaterialChunk::create();
            beginEditCP(matc);  

	        if (!(inherit & PFSTATE_FRONTMTL))
	        {
                pfMaterial *mat = (pfMaterial*)gstate->getAttr(PFSTATE_FRONTMTL);

                float r,g,b,a;
                a = mat->getAlpha();

                mat->getColor(PFMTL_AMBIENT, &r, &g, &b);        
                matc->setAmbient(Color4f(r,g,b,0));

                mat->getColor(PFMTL_DIFFUSE, &r, &g, &b);        
                matc->setDiffuse(Color4f(r,g,b,a));

                mat->getColor(PFMTL_SPECULAR, &r, &g, &b);        
                matc->setSpecular(Color4f(r,g,b,0));

                mat->getColor(PFMTL_EMISSION, &r, &g, &b);        
                matc->setEmission(Color4f(r,g,b,0));

                matc->setShininess(mat->getShininess());

                int cm = mat->getColorMode(PFMTL_FRONT);
                UInt32 om = GL_NONE;
                for (UInt16 i = 0; pcolormode[i] != -1; ++i)
                    if(pcolormode[i] == cm)
                        om = ocolormode[i];

                matc->setColorMaterial(om);
	        }

	        if (!(inherit & PFSTATE_BACKMTL))
	        {
                pfMaterial *mat = (pfMaterial*)gstate->getAttr(PFSTATE_BACKMTL);

                matc->setBackMaterial(true);
                float r,g,b,a;
                a = mat->getAlpha();

                mat->getColor(PFMTL_AMBIENT, &r, &g, &b);        
                matc->setBackAmbient(Color4f(r,g,b,0));

                mat->getColor(PFMTL_DIFFUSE, &r, &g, &b);        
                matc->setBackDiffuse(Color4f(r,g,b,a));

                mat->getColor(PFMTL_SPECULAR, &r, &g, &b);        
                matc->setBackSpecular(Color4f(r,g,b,0));

                mat->getColor(PFMTL_EMISSION, &r, &g, &b);        
                matc->setBackEmission(Color4f(r,g,b,0));

                matc->setBackShininess(mat->getShininess());

                int cm = mat->getColorMode(PFMTL_FRONT);
                UInt32 om = GL_NONE;
                for (UInt16 i = 0; pcolormode[i] != -1; ++i)
                    if(pcolormode[i] == cm)
                        om = ocolormode[i];

                matc->setBackColorMaterial(om);
	        }

            endEditCP(matc);
        }

        mat->addChunk(matc);
    }
    
    
    if((inherit & (PFSTATE_TEXTURE | PFSTATE_TEXENV)) !=
                  (PFSTATE_TEXTURE | PFSTATE_TEXENV)
      )
    {
        TextureChunkPtr texc;
        
        for(int t = 0; t < PF_MAX_TEXTURES; ++t)
        {
            if(gstate->getMultiAttr(PFSTATE_TEXTURE, t) == NULL)
                continue;
            
            key.first = NULL;
	        if (!(inherit & PFSTATE_TEXTURE) && 
                  gstate->getMultiAttr(PFSTATE_TEXTURE, t))
                key.first = gstate->getMultiAttr(PFSTATE_TEXTURE, t);

            key.second = NULL;
	        if (!(inherit & PFSTATE_TEXENV) && 
                  gstate->getMultiAttr(PFSTATE_TEXENV, t))
                key.second = gstate->getMultiAttr(PFSTATE_TEXENV, t);

            if(_chunks.find(key) != _chunks.end())
            {    
                texc = TextureChunkPtr::dcast(_chunks[key]);
            }
            else
            {
                texc = TextureChunk::create();
                beginEditCP(texc);  

	            if (!(inherit & PFSTATE_TEXTURE))
	            {
                    pfTexture *tex = 
                        (pfTexture*)gstate->getMultiAttr(PFSTATE_TEXTURE, t);
	            
                    unsigned int* pdata;
                    int pf, w, h, d, type, comp, sides;
                    UInt32 intformat = 0, extformat = 0;
                    
                    tex->getImage(&pdata, &comp, &w, &h, &d);                  

                    sides = tex->getFormat(PFTEX_CUBE_MAP) ? 6 : 1;
                    pf    = tex->getFormat(PFTEX_IMAGE_FORMAT);
                    
                    if(pf == 0x7fff)
                    {
                        switch(comp)
                        {
                        case 1: pf = Image::OSG_L_PF;      break;
                        case 2: pf = Image::OSG_LA_PF;     break;
                        case 3: pf = Image::OSG_RGB_PF;    break;
                        case 4: pf = Image::OSG_RGBA_PF;   break;
                        }
                    }
                    
                    switch(tex->getFormat(PFTEX_EXTERNAL_FORMAT))
                    {
                    case PFTEX_PACK_8:  type = Image::OSG_UINT8_IMAGEDATA;
                                        break;
                    case PFTEX_PACK_16: type = Image::OSG_UINT16_IMAGEDATA;
                                        break;
                    default:            
                        type = Image::OSG_UINT8_IMAGEDATA;
                        FWARNING(("PerformerLoader::traverseGState: "
                                  "Unknown tex format %d!\n",
                                   tex->getFormat(PFTEX_EXTERNAL_FORMAT)));
                        extformat = tex->getFormat(PFTEX_EXTERNAL_FORMAT);
                        break;
                    }
                    
                    intformat = tex->getFormat(PFTEX_INTERNAL_FORMAT);
                    
                    
                    ImagePtr img = Image::create();
                    beginEditCP(img);
                    
                    img->set(pf, w, h, d, 1, 1, 0, NULL, type, 1, sides);
                    
                    if(sides == 1)
                    {
                        memcpy(img->getData(), pdata, img->getSize());
                    }
                    else
                    {
                        FWARNING(("PerformerLoader::traverseGState: "
                                  "CubeTex not impl yet!\n"));
                    }
                    
                    endEditCP(img);
                    
                    texc->setImage(img);
                    
                    texc->setInternalFormat(intformat);
                    
                    texc->setWrapS(tex->getRepeat(PFTEX_WRAP_S));
                    texc->setWrapT(tex->getRepeat(PFTEX_WRAP_T));
                    texc->setWrapR(tex->getRepeat(PFTEX_WRAP_R));
 
                    static int ptexfilter[] = { PFTEX_POINT,
                                                PFTEX_LINEAR,
                                                PFTEX_BILINEAR,
                                                PFTEX_TRILINEAR,
                                                PFTEX_QUADLINEAR,
                                                PFTEX_MIPMAP_POINT,
                                                PFTEX_MIPMAP_LINEAR,
                                                PFTEX_MIPMAP_BILINEAR,
                                                PFTEX_MIPMAP_TRILINEAR,
                                                PFTEX_MIPMAP_QUADLINEAR,
                                                -1
                                              };
                    static int otexfilter[] = { GL_NEAREST,
                                                GL_LINEAR,
                                                GL_LINEAR,
                                                GL_LINEAR,
                                                GL_LINEAR,
                                                GL_NEAREST_MIPMAP_NEAREST,
                                                GL_NEAREST_MIPMAP_LINEAR,
                                                GL_LINEAR_MIPMAP_NEAREST,
                                                GL_LINEAR_MIPMAP_LINEAR,
                                                GL_LINEAR_MIPMAP_LINEAR
                                              };

                    int ptf = tex->getFilter(PFTEX_MINFILTER);
                    UInt32 otf = GL_NONE;
                    for (UInt16 i = 0; ptexfilter[i] != -1; ++i)
                        if(ptexfilter[i] == ptf)
                            otf = otexfilter[i];
                    texc->setMinFilter(otf);

                    ptf = tex->getFilter(PFTEX_MAGFILTER);
                    otf = GL_NONE;
                    for (UInt16 i = 0; ptexfilter[i] != -1; ++i)
                        if(ptexfilter[i] == ptf)
                            otf = otexfilter[i];
                    texc->setMagFilter(otf);
                }

	            if (!(inherit & PFSTATE_TEXENV))
	            {
                    pfTexEnv *te = 
                        (pfTexEnv*)gstate->getMultiAttr(PFSTATE_TEXENV, t);
	                
                    if(te != NULL)
                    {
                        texc->setEnvMode(te->getMode());

                        float r,g,b,a;
                        te->getBlendColor(&r,&g,&b,&a);

                        texc->setEnvColor(Color4f(r,g,b,a));
                    }
	            }

                endEditCP(texc);
            }

            mat->addChunk(texc);
        } // for t
    }
 
    /* Unhandled: lightmodel, lights, fog, texgen, texlod, vtxprog, fragprog,
                  gprogparms, colortable, highlight, lpointstate, shadprog
    */

    endEditCP(mat);
    
    _materials[gstate] = mat;
    
    return mat;
}
Пример #21
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
	cout << "Testing screen aligned text generation and file-IO." << endl;
	
    if(argc == 1)
    {
        FFATAL(("Need *.txf or *.ttf font file\n"));
        return -1;
    }

    // OSG init
    osgInit(argc, argv);

    // GLUT init
    int             winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr   gwin = GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    PathHandler paths;

    paths.push_backPath(".");

    //paths.push_backPath("/home/elmi/wrk/development/texFont");
    // create the scene
    FontStyle   *fontStyle = FontStyleFactory::the().create( paths, argv[1], 
															 0.25);
	cout << fontStyle->getFontName() << endl;

    // create the scene
    NodePtr pTorus = makeTorus( 0.02, 0.55, 16, 16);
	ChunkMaterialPtr mat = ChunkMaterial::create();

    MaterialChunkPtr pmc = MaterialChunk::create();
    pmc->setDiffuse( Color4f( 1,0,0,0.5 ) );
    pmc->setAmbient( Color4f( 0,1,0,0.5 ) );
    pmc->setSpecular( Color4f( 0,0,1,0.5 ) );
	pmc->setLit( true );
    pmc->setShininess( 20 );

	beginEditCP(mat);
	{
	mat->addChunk( pmc );
	}
	endEditCP(mat);

    scene = Node::create();
	GroupPtr group = Group::create();
    beginEditCP( scene );
    {
        scene->setCore( group );
	}
    endEditCP( scene );

	SharedFontStylePtr sfs = SharedFontStyle::create(); 
	sfs->setContainedFontStyle( fontStyle );

	for( int x=0; x<100; x += 20 )
	{
		for( int y=0; y<100; y += 20 )
		{
			for( int z=0; z<100; z += 20 )
			{
				ScreenAlignedTextPtr scaText = ScreenAlignedText::create();
				if( scaText == NullFC )
				{
					exit (2);
				}
				SharedFontStyleWrapperPtr pFSWrapper = SharedFontStyleWrapper::create();
				pFSWrapper->setFStyleContainer( sfs );
				ostringstream cString;
				cString << '(' 
						<< x 
						<< ',' 
						<< y
						<< ','
						<< z
						<< ')'
						<< endl;

				beginEditCP(scaText);
				{
					scaText->setPosition( Vec3f ( x, y, z ) );
					scaText->setFont( pFSWrapper );
					scaText->setVerticalLineDistance( 0.20 );
					scaText->setAlignment( 0 );
					scaText->editMFText()->push_back( cString.str() );
					scaText->setMaterial( mat );
				}
				endEditCP(scaText);
				NodePtr pTextNode = Node::create();
				beginEditCP( pTextNode );
				{
					pTextNode->setCore( scaText );
				}
				beginEditCP( scene );
				{
					scene->addChild( pTextNode );
				}
				endEditCP( scene );	
				cout << "Erzeugt : " 
					 << cString.str() 
					 << endl;
			}
		}
    }

	//NodePtr pCopied = scene;

#if 1
	{
		ofstream outFileStream( "/tmp/text.osg" );

		if( !outFileStream )
		{
			cerr << "cannot open file" << endl;
			exit(2);
		}
		//FILE *pFile = fopen( "isolinien.osg","w" );
		//BINWriter writer( pFile );
		OSGWriter writer( outFileStream );
		writer.write( scene );
	}
#endif

#if 0
	VRMLWriteAction *pWriter = VRMLWriteAction::create();
	scene->dump();
	pWriter->open("allesscheisse.wrl");
	pWriter->write( scene);
	pWriter->close();
	delete pWriter;
#endif

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin);
    mgr->setRoot( scene );

    // show the whole scene
    mgr->showAll();

    // GLUT main loop
    glutMainLoop();

    return 0;
}
int main (int argc, char **argv)
{

    // GLUT init

    osgInit(argc, argv);
    osgLog().setLogLevel ( OSG::LOG_DEBUG );

    FieldContainerPtr pProto = Geometry::getClassType().getPrototype();

    GeometryPtr pGeoProto = GeometryPtr::dcast(pProto);

    if(pGeoProto != NullFC)
    {
        pGeoProto->setDlistCache(true);
    }

    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    UInt32 id = glutCreateWindow("OpenSG");
    glutKeyboardFunc(key);
    glutReshapeFunc(resize);
    glutDisplayFunc(display);       
    // glutMouseFunc(mouse);   
    // glutMotionFunc(motion); 
    
    glutIdleFunc(display);
    
    // create a material (need that to test textures)
    
    ChunkMaterialPtr mat;  

    beginEditCP(mat);
    
    mat = ChunkMaterial::create();
   
    MaterialChunkPtr mc = MaterialChunk::create();  
 
    beginEditCP(mc);
    mc->setDiffuse( Color4f( 1,.8,.8,1 ) );
    mc->setAmbient( Color4f( 0.1,0.1,0.1,1 ) );
    mc->setSpecular( Color4f( 1,1,1,1 ) );
    mc->setShininess( 20 );
 
    mc->setBackMaterial(true);
    mc->setBackColorMaterial(GL_DIFFUSE);
    mc->setBackDiffuse( Color4f( 1,0,0,1 ) );
    mc->setBackAmbient( Color4f( 0.1,0.1,0.1,1 ) );
    mc->setBackSpecular( Color4f( 0,1,0,1 ) );
    mc->setBackShininess( 10 );
    mc->setLit(true);
 
    endEditCP(mc);

    mat->addChunk(mc);

    // Texture chunk
    
    UChar8 imgdata[] = 
        {  255,0,0,128,  0,255,0,128,  0,0,255,255,  255,255,255,255 };
    ImagePtr pImage = Image::create();
    pImage->set( Image::OSG_RGBA_PF, 2, 2, 1, 1, 1, 0, imgdata );

    if ( argc > 1 )
        pImage->read( argv[1] );
    
    TextureChunkPtr xchunk;
    xchunk = TextureChunk::create();
    xchunk->setImage( pImage );
    xchunk->setMinFilter( GL_NEAREST );
    xchunk->setMagFilter( GL_NEAREST );
    xchunk->setWrapS( GL_REPEAT );
    xchunk->setWrapT( GL_REPEAT );
    xchunk->setEnvMode( GL_MODULATE );

    mat->addChunk( xchunk );

    endEditCP(mat);

    objects[0] = makePolygon(ccwSquare, 
                             sizeof(ccwSquare)/sizeof(double[3]));
    objects[1] = makePolygon(ccwSquare, 
                             sizeof(ccwSquare)/sizeof(double[3]));
    
    objects[2] = makePolygon(star,
                             sizeof(star)/sizeof(double[3]));
    objects[3] = makePolygon(star,
                             sizeof(star)/sizeof(double[3]));
    
    objects[4] = makePolygon(cwSquare, 
                             sizeof(cwSquare)/sizeof(double[3]));
    objects[5] = makePolygon(cwSquare, 
                             sizeof(cwSquare)/sizeof(double[3]));
    
    objects[6] = makePolygon(doubleEight, 
                             sizeof(doubleEight)/sizeof(double[3]));
    objects[7] = makePolygon(doubleEight, 
                             sizeof(doubleEight)/sizeof(double[3]));

    //tesselate every second object
    for(int i = 1; i < nobjects; i+=2) {

      GeometryPtr::dcast(objects[i]->getCore())->setMaterial( mat );
      std::cerr << "Polygon Node: " << std::hex << objects[i] << std::endl;

      // try to create convex primitives
      OSG::GeometryPtr pGeo = GeometryPtr::dcast(objects[i]->getCore());

      std::cerr << "Tesselating polygon : "
                << i
                << std::endl;

      createConvexPrimitives(pGeo);
    }

    // normal material
    SimpleMaterialPtr nmat;     
    
    nmat = SimpleMaterial::create();
    beginEditCP(nmat);
    nmat->setEmission( Color3f( 0,1,0 ) );
    endEditCP(nmat);
    
    for ( UInt16 i = 0; i < nobjects; i++ )
    {
        normalobjects[i] = calcVertexNormalsGeo(
            GeometryPtr::dcast(objects[i]->getCore()), .5);

        GeometryPtr::dcast(normalobjects[i]->getCore())->setMaterial(nmat);
    }
    
    // 
    // The action

    win = GLUTWindow::create();
    win->setId(id);
    win->init();

    glEnable( GL_LIGHT0 );
    float p[4]={0,0,1,0};
    glLightfv(GL_LIGHT0, GL_POSITION, p);
    float c[4]={1,1,1,1};
    glLightfv(GL_LIGHT0, GL_DIFFUSE, c);
    glLightfv(GL_LIGHT0, GL_SPECULAR, c);
    
    glPointSize( 3 );
    
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
    glClearColor( .3, .3, .8, 1 );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 60, 1, 0.1, 10 );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    gluLookAt( 3, 3, 3,  0, 0, 0,   0, 0, 1 );
   
    dact = DrawAction::create();
    dact->setWindow(get_pointer(win));
    dact->setFrustumCulling( false );

    glutMainLoop();
    
    return 0;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindowEventProducer = createDefaultWindowEventProducer();
    WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();

    TutorialWindowEventProducer->setDisplayCallback(display);
    TutorialWindowEventProducer->setReshapeCallback(reshape);

	TutorialUpdateListener TheTutorialUpdateListener;
    TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener);
    TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(MainWindow);
	

	//Print key command info
	std::cout << "\n\nKEY COMMANDS:" << std::endl;
	std::cout << "space   Play/Pause the animation" << std::endl;
	std::cout << "G       Show/Hide the grid" << std::endl;
	std::cout << "A       Show/Hide the axes" << std::endl;
	std::cout << "B       Show/Hide the bind pose skeleton" << std::endl;
	std::cout << "SHIFT-B Show/Hide the bind pose mesh" << std::endl;
	std::cout << "P       Show/Hide the current pose skeleton" << std::endl;
	std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl;
	std::cout << "CTRL-Q  Exit\n\n" << std::endl;




	//Setup axes
	LineChunkPtr AxesLineChunk = LineChunk::create();
	beginEditCP(AxesLineChunk);
		AxesLineChunk->setWidth(0.0f);
		AxesLineChunk->setSmooth(true);
	endEditCP(AxesLineChunk);

	//Axes material
	ChunkMaterialPtr AxesMaterial = ChunkMaterial::create();
	beginEditCP(AxesMaterial, ChunkMaterial::ChunksFieldMask);
		AxesMaterial->addChunk(AxesLineChunk);
	endEditCP(AxesMaterial, ChunkMaterial::ChunksFieldMask);

	//Grid material
	ChunkMaterialPtr gridMaterial = ChunkMaterial::create();
	beginEditCP(gridMaterial, ChunkMaterial::ChunksFieldMask);
		gridMaterial->addChunk(AxesLineChunk);
	endEditCP(gridMaterial, ChunkMaterial::ChunksFieldMask);

	//Axes should render as lines
	GeoPTypesPtr axesType = GeoPTypesUI8::create();        
    beginEditCP(axesType, GeoPTypesUI8::GeoPropDataFieldMask);
    {
        axesType->addValue(GL_LINES);
    }
    endEditCP  (axesType, GeoPTypesUI8::GeoPropDataFieldMask);

	//Grid type
	GeoPTypesPtr gridType = GeoPTypesUI8::create();        
    beginEditCP(gridType, GeoPTypesUI8::GeoPropDataFieldMask);
    {
        gridType->addValue(GL_LINES);
    }
    endEditCP  (gridType, GeoPTypesUI8::GeoPropDataFieldMask);

	//Axes lens
	GeoPLengthsPtr axesLens = GeoPLengthsUI32::create();    
    beginEditCP(axesLens, GeoPLengthsUI32::GeoPropDataFieldMask);
    {
        axesLens->addValue(6);
    }
    endEditCP  (axesLens, GeoPLengthsUI32::GeoPropDataFieldMask);

	//Grid lens
	GeoPLengthsPtr gridLens = GeoPLengthsUI32::create();    
    beginEditCP(gridLens, GeoPLengthsUI32::GeoPropDataFieldMask);
    {
        gridLens->addValue(84);
    }
    endEditCP  (gridLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	
	//Axes points
	GeoPositions3fPtr axesPnts = GeoPositions3f::create();
    beginEditCP(axesPnts, GeoPositions3f::GeoPropDataFieldMask);
    {
		// X-Axis
        axesPnts->addValue(Pnt3f(0,  0,  0));
        axesPnts->addValue(Pnt3f(15,  0,  0));
        
		// Y-Axis
		axesPnts->addValue(Pnt3f(0,  0,  0));
        axesPnts->addValue(Pnt3f(0,  15,  0));

		// Z-Axis
        axesPnts->addValue(Pnt3f(0,  0, 0));
        axesPnts->addValue(Pnt3f(0,  0, 15));
    }
    endEditCP  (axesPnts, GeoPositions3f::GeoPropDataFieldMask);

	//Grid points
	GeoPositions3fPtr gridPnts = GeoPositions3f::create();
    beginEditCP(gridPnts, GeoPositions3f::GeoPropDataFieldMask);
    {
		float height = 0;

		gridPnts->addValue(Pnt3f(-10, height, 0));
		if(height == 0)
			gridPnts->addValue(Pnt3f(0, height, 0));
		else
			gridPnts->addValue(Pnt3f(10, height, 0));

		gridPnts->addValue(Pnt3f(-10, height, 1));
		gridPnts->addValue(Pnt3f(10, height, 1));

		gridPnts->addValue(Pnt3f(-10, height, 2));
		gridPnts->addValue(Pnt3f(10, height, 2));

		gridPnts->addValue(Pnt3f(-10, height, 3));
		gridPnts->addValue(Pnt3f(10, height, 3));

		gridPnts->addValue(Pnt3f(-10, height, 4));
		gridPnts->addValue(Pnt3f(10, height, 4));

		gridPnts->addValue(Pnt3f(-10, height, 5));
		gridPnts->addValue(Pnt3f(10, height, 5));

		gridPnts->addValue(Pnt3f(-10, height, 6));
		gridPnts->addValue(Pnt3f(10, height, 6));

		gridPnts->addValue(Pnt3f(-10, height, 7));
		gridPnts->addValue(Pnt3f(10, height, 7));

		gridPnts->addValue(Pnt3f(-10, height, 8));
		gridPnts->addValue(Pnt3f(10, height, 8));

		gridPnts->addValue(Pnt3f(-10, height, 9));
		gridPnts->addValue(Pnt3f(10, height, 9));

		gridPnts->addValue(Pnt3f(-10, height, 10));
		gridPnts->addValue(Pnt3f(10, height, 10));

		gridPnts->addValue(Pnt3f(-10, height, -1));
		gridPnts->addValue(Pnt3f(10, height, -1));

		gridPnts->addValue(Pnt3f(-10, height, -2));
		gridPnts->addValue(Pnt3f(10, height, -2));

		gridPnts->addValue(Pnt3f(-10, height, -3));
		gridPnts->addValue(Pnt3f(10, height, -3));

		gridPnts->addValue(Pnt3f(-10, height, -4));
		gridPnts->addValue(Pnt3f(10, height, -4));

		gridPnts->addValue(Pnt3f(-10, height, -5));
		gridPnts->addValue(Pnt3f(10, height, -5));

		gridPnts->addValue(Pnt3f(-10, height, -6));
		gridPnts->addValue(Pnt3f(10, height, -6));

		gridPnts->addValue(Pnt3f(-10, height, -7));
		gridPnts->addValue(Pnt3f(10, height, -7));

		gridPnts->addValue(Pnt3f(-10, height, -8));
		gridPnts->addValue(Pnt3f(10, height, -8));

		gridPnts->addValue(Pnt3f(-10, height, -9));
		gridPnts->addValue(Pnt3f(10, height, -9));

		gridPnts->addValue(Pnt3f(-10, height, -10));
		gridPnts->addValue(Pnt3f(10, height, -10));


		gridPnts->addValue(Pnt3f(0, height, -10));
		if(height == 0)
			gridPnts->addValue(Pnt3f(0, height, 0));
		else
			gridPnts->addValue(Pnt3f(0, height, 10));
		
		gridPnts->addValue(Pnt3f(1, height, -10));
		gridPnts->addValue(Pnt3f(1, height, 10));

		gridPnts->addValue(Pnt3f(2, height, -10));
		gridPnts->addValue(Pnt3f(2, height, 10));

		gridPnts->addValue(Pnt3f(3, height, -10));
		gridPnts->addValue(Pnt3f(3, height, 10));

		gridPnts->addValue(Pnt3f(4, height, -10));
		gridPnts->addValue(Pnt3f(4, height, 10));

		gridPnts->addValue(Pnt3f(5, height, -10));
		gridPnts->addValue(Pnt3f(5, height, 10));

		gridPnts->addValue(Pnt3f(6, height, -10));
		gridPnts->addValue(Pnt3f(6, height, 10));

		gridPnts->addValue(Pnt3f(7, height, -10));
		gridPnts->addValue(Pnt3f(7, height, 10));

		gridPnts->addValue(Pnt3f(8, height, -10));
		gridPnts->addValue(Pnt3f(8, height, 10));

		gridPnts->addValue(Pnt3f(9, height, -10));
		gridPnts->addValue(Pnt3f(9, height, 10));

		gridPnts->addValue(Pnt3f(10, height, -10));
		gridPnts->addValue(Pnt3f(10, height, 10));

		gridPnts->addValue(Pnt3f(-1, height, -10));
		gridPnts->addValue(Pnt3f(-1, height, 10));

		gridPnts->addValue(Pnt3f(-2, height, -10));
		gridPnts->addValue(Pnt3f(-2, height, 10));

		gridPnts->addValue(Pnt3f(-3, height, -10));
		gridPnts->addValue(Pnt3f(-3, height, 10));

		gridPnts->addValue(Pnt3f(-4, height, -10));
		gridPnts->addValue(Pnt3f(-4, height, 10));

		gridPnts->addValue(Pnt3f(-5, height, -10));
		gridPnts->addValue(Pnt3f(-5, height, 10));

		gridPnts->addValue(Pnt3f(-6, height, -10));
		gridPnts->addValue(Pnt3f(-6, height, 10));

		gridPnts->addValue(Pnt3f(-7, height, -10));
		gridPnts->addValue(Pnt3f(-7, height, 10));

		gridPnts->addValue(Pnt3f(-8, height, -10));
		gridPnts->addValue(Pnt3f(-8, height, 10));

		gridPnts->addValue(Pnt3f(-9, height, -10));
		gridPnts->addValue(Pnt3f(-9, height, 10));

		gridPnts->addValue(Pnt3f(-10, height, -10));
		gridPnts->addValue(Pnt3f(-10, height, 10));

		
    }
    endEditCP  (gridPnts, GeoPositions3f::GeoPropDataFieldMask);
    
    //Axes normals
	GeoNormals3fPtr axesNorms = GeoNormals3f::create();
    beginEditCP(axesNorms, GeoNormals3f::GeoPropDataFieldMask);
        axesNorms->addValue(Vec3f( 0.0,0.0,1.0));
        axesNorms->addValue(Vec3f( 0.0,0.0,1.0));
        
		axesNorms->addValue(Vec3f( 0.0,0.0,1.0));
        axesNorms->addValue(Vec3f( 0.0,0.0,1.0));

        axesNorms->addValue(Vec3f( 1.0,0.0,0.0));
        axesNorms->addValue(Vec3f( 1.0,0.0,0.0));
    endEditCP(axesNorms, GeoNormals3f::GeoPropDataFieldMask);

	//Grid normals
	GeoNormals3fPtr gridNorms = GeoNormals3f::create();
    beginEditCP(gridNorms, GeoNormals3f::GeoPropDataFieldMask);
		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));

		gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
        gridNorms->addValue(Vec3f( 0.0,0.0,1.0));
    endEditCP(gridNorms, GeoNormals3f::GeoPropDataFieldMask);

	//Axes colors
	GeoColors3fPtr axesColors = GeoColors3f::create();
    beginEditCP(axesColors, GeoColors3f::GeoPropDataFieldMask);
        //X-Axis = Red
	 	  axesColors->addValue(Color3f( 1.0,0.0,0.0));
        axesColors->addValue(Color3f( 1.0,0.0,0.0));
        
		  //Y-Axis = Green
		axesColors->addValue(Color3f( 0.0,1.0,0.0));
        axesColors->addValue(Color3f( 0.0,1.0,0.0));

		  //Z-Axis = Blue
        axesColors->addValue(Color3f( 0.0,0.0,1.0));
        axesColors->addValue(Color3f( 0.0,0.0,1.0));
    endEditCP(axesColors, GeoColors3f::GeoPropDataFieldMask);

	//Grid gridColors
	GeoColors3fPtr gridColors = GeoColors3f::create();
    beginEditCP(gridColors, GeoColors3f::GeoPropDataFieldMask);
		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));

		gridColors->addValue(Color3f( 0.5,0.5,0.5));
        gridColors->addValue(Color3f( 0.5,0.5,0.5));
    endEditCP(gridColors, GeoColors3f::GeoPropDataFieldMask);

	//Create axes geometry
	GeometryPtr axesGeo = Geometry::create();
    beginEditCP(axesGeo, Geometry::TypesFieldMask     |
                     Geometry::LengthsFieldMask   |
                     Geometry::PositionsFieldMask |
                     Geometry::NormalsFieldMask |
                     Geometry::MaterialFieldMask |
					 Geometry::ColorsFieldMask);
    {
        axesGeo->setTypes    (axesType);
        axesGeo->setLengths  (axesLens);
        axesGeo->setPositions(axesPnts);
        axesGeo->setNormals(axesNorms);
        axesGeo->setColors(axesColors);

        // assign a material to the geometry to make it visible. The details
        // of materials are defined later.
        axesGeo->setMaterial(AxesMaterial);   
    }
    endEditCP  (axesGeo, Geometry::TypesFieldMask     |
                     Geometry::LengthsFieldMask   |
                     Geometry::PositionsFieldMask |
                     Geometry::NormalsFieldMask |
                     Geometry::MaterialFieldMask |
					 Geometry::ColorsFieldMask  );

	//Create grid geometry
	GeometryPtr gridGeo = Geometry::create();
    beginEditCP(gridGeo, Geometry::TypesFieldMask     |
                     Geometry::LengthsFieldMask   |
                     Geometry::PositionsFieldMask |
                     Geometry::NormalsFieldMask |
                     Geometry::MaterialFieldMask |
					 Geometry::ColorsFieldMask);
    {
        gridGeo->setTypes    (gridType);
        gridGeo->setLengths  (gridLens);
        gridGeo->setPositions(gridPnts);
        gridGeo->setNormals(gridNorms);
        gridGeo->setColors(gridColors);

        // assign a material to the geometry to make it visible. The details
        // of materials are defined later.
        gridGeo->setMaterial(AxesMaterial);   
    }
    endEditCP  (gridGeo, Geometry::TypesFieldMask     |
                     Geometry::LengthsFieldMask   |
                     Geometry::PositionsFieldMask |
                     Geometry::NormalsFieldMask |
                     Geometry::MaterialFieldMask |
					 Geometry::ColorsFieldMask  );

	//Create unbound geometry Node
	Axes = osg::Node::create();
	beginEditCP(Axes, Node::CoreFieldMask);
		Axes->setCore(axesGeo);
	endEditCP(Axes, Node::CoreFieldMask);

	//Create unbound geometry Node
	Grid = osg::Node::create();
	beginEditCP(Grid, Node::CoreFieldMask);
		Grid->setCore(gridGeo);
	endEditCP(Grid, Node::CoreFieldMask);


	//Import scene from an XML file
	ChunkMaterialPtr ExampleMaterial;
	std::vector<SkeletonPtr> SkeletonPtrs;
	std::vector<SkeletonBlendedGeometryPtr> SkeletonBlendedGeometryPtrs;
	std::vector<GeometryPtr> GeometryPtrs;

	FCFileType::FCPtrStore NewContainers;
	NewContainers = FCFileHandler::the()->read(Path("./Data/21SceneFromMaya.xml"));
	FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
		if( (*Itor)->getType() == (ChunkMaterial::getClassType()))
		{
			//Set ExampleMaterial to the ChunkMaterial we just read in
			ExampleMaterial = (ChunkMaterial::Ptr::dcast(*Itor));
		}
		if( (*Itor)->getType() == (Skeleton::getClassType()))
		{
			//Add the skeleton we just read in to SkeletonPtrs
			SkeletonPtrs.push_back(Skeleton::Ptr::dcast(*Itor));
		}
		if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType()))
		{
			//Add the SkeletonBlendedGeometry we just read in to SkeletonBlendedGeometryPtrs
			SkeletonBlendedGeometryPtrs.push_back(SkeletonBlendedGeometry::Ptr::dcast(*Itor));
		}
		if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType()))
		{
			//Set TheSkeletonAnimation to the Animation we just read in
			TheSkeletonAnimation = (Animation::Ptr::dcast(*Itor));
		}
		if( (*Itor)->getType() == (Geometry::getClassType()))
		{
			//Add the Geometry we just read in to GeometryPtrs
			GeometryPtrs.push_back(Geometry::Ptr::dcast(*Itor));
		}
    }
	
	//Create unbound geometry Node (to show the mesh in its bind pose)
	for (int i(0); i < GeometryPtrs.size(); ++i)
	{
		NodePtr UnboundGeometry = Node::create();
		beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask);
			UnboundGeometry->setCore(GeometryPtrs[i]);
			UnboundGeometry->setTravMask(0);
		endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask);

		UnboundGeometries.push_back(UnboundGeometry);
	}


	//Create skeleton nodes
	for (int i(0); i < SkeletonPtrs.size(); ++i)
	{
		//SkeletonDrawer
		SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create();
		beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask  | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask);
			ExampleSkeletonDrawable->setSkeleton(SkeletonPtrs[i]);
			ExampleSkeletonDrawable->setMaterial(AxesMaterial);
			ExampleSkeletonDrawable->setDrawPose(true);								  //By default we draw the current skeleton
			ExampleSkeletonDrawable->setPoseColor(Color4f(1.0, 0.0, 1.0, 1.0));       //Set color of current skeleton
			ExampleSkeletonDrawable->setDrawBindPose(false);                          //By default we don't draw the bind pose skeleton
			ExampleSkeletonDrawable->setBindPoseColor(Color4f(1.0, 1.0, 0.0, 1.0));   //Set color of bind pose skeleton
		endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask  | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask);
		
		//Skeleton Node
		NodePtr SkeletonNode = osg::Node::create();
		beginEditCP(SkeletonNode, Node::CoreFieldMask);
			SkeletonNode->setCore(ExampleSkeletonDrawable);
		endEditCP(SkeletonNode, Node::CoreFieldMask);

		SkeletonNodes.push_back(SkeletonNode);
	}



	//Create skeleton blended geometry nodes
	for (int i(0); i < SkeletonBlendedGeometryPtrs.size(); ++i)
	{
		NodePtr MeshNode = osg::Node::create();
		beginEditCP(MeshNode, Node::CoreFieldMask);
			MeshNode->setCore(SkeletonBlendedGeometryPtrs[i]);
		endEditCP(MeshNode, Node::CoreFieldMask);

		MeshNodes.push_back(MeshNode);
	}



    //Create Animation Advancer
    TheAnimationAdvancer = osg::ElapsedTimeAnimationAdvancer::create();
    osg::beginEditCP(TheAnimationAdvancer);
    osg::ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 );
    osg::beginEditCP(TheAnimationAdvancer);


    //Add nodes to scene
    NodePtr scene = osg::Node::create();
    beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);
        scene->setCore(osg::Group::create());
		scene->addChild(Axes);
		scene->addChild(Grid);

		//Add all imported skeletons to scene
		for (int i(0); i < SkeletonNodes.size(); ++i)
		{
			scene->addChild(SkeletonNodes[i]);
		}

		//Add all imported geometries to scene
		for (int i(0); i < UnboundGeometries.size(); ++i)
		{
			scene->addChild(UnboundGeometries[i]);
		}

		//Add all imported SkeletonBlendedGeometries to scene
		for (int i(0); i < MeshNodes.size(); ++i)
		{
			scene->addChild(MeshNodes[i]);
		}
    endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask);

    mgr->setRoot(scene);


	//By default the animation is not paused
	animationPaused = false;

    // Show the whole Scene
    mgr->showAll();
    TheAnimationAdvancer->start();

	 //Show window
    Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5);
    TutorialWindowEventProducer->openWindow(WinPos,
                        WinSize,
                                        "21LoadXMLSceneFromMaya");

    //Enter main Loop
    TutorialWindowEventProducer->mainLoop();

    osgExit();

    return 0;
}
Пример #24
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    // put the geometry core into a node
    scene = Node::create();
    GroupPtr groupPtr = Group::create();
    beginEditCP(scene, Node::CoreFieldMask);
    {
        scene->setCore(groupPtr);
    }
    endEditCP(scene, Node::CoreFieldMask);

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin );
    mgr->setRoot  (scene);
    //mgr->getAction()->setFrustumCulling(false);

    // Create the background
    SolidBackgroundPtr bg = SolidBackground::create();
    beginEditCP(bg);
    bg->setColor(Color3f(0.1, 0.1, 0.5));
    endEditCP(bg);

    face = getStatisticsDefaultFont();
    TextureChunkPtr texChunk = getStatisticsDefaultFontTexture();
    MaterialChunkPtr matChunk = MaterialChunk::create();
    beginEditCP(matChunk);
    {
        matChunk->setAmbient(Color4f(1.f, 1.f, 1.f, 1.f));
        matChunk->setDiffuse(Color4f(1.f, 1.f, 1.f, 1.f));
        matChunk->setEmission(Color4f(0.f, 0.f, 0.f, 1.f));
        matChunk->setSpecular(Color4f(0.f, 0.f, 0.f, 1.f));
        matChunk->setShininess(0);
    }
    endEditCP(matChunk);
    BlendChunkPtr blendChunk = BlendChunk::create();
    beginEditCP(blendChunk, BlendChunk::DestFactorFieldMask);
    {
        blendChunk->setSrcFactor(GL_SRC_ALPHA);
        blendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
    }
    endEditCP(blendChunk, BlendChunk::DestFactorFieldMask);
    textMaterial = ChunkMaterial::create();
    beginEditCP(textMaterial);
    {
        textMaterial->addChunk(texChunk);
        textMaterial->addChunk(matChunk);
        textMaterial->addChunk(blendChunk);
    }
    endEditCP(textMaterial);

    updateScene();

    beginEditCP(gwin->getPort(0));
    gwin->getPort(0)->setBackground(bg);
    endEditCP(gwin->getPort(0));

    // GLUT main loop
    glutMainLoop();

    return 0;
}