Hello Ted,

sorry, for my incorrect guess. I just looked into SimpleMaterial its ctor for 
default values.

But, what I do different from your code is that I always return OpenSG objects, 
which I have created in functions by the respective
TransitPtr. For instance, I have the following function working

OSG::ChunkMaterialTransitPtr createChunkMaterial(const SolidMaterial& rMat)
{
    using namespace OSG;

    ChunkMaterialUnrecPtr chunkMaterial = ChunkMaterial::create();

    MaterialChunkUnrecPtr mat = MaterialChunk::create();

    updateMaterialChunk(mat, rMat);

    chunkMaterial->addChunk(mat);

    PolygonChunkUnrecPtr chunkPolygonModel = PolygonChunk::create();
    chunkPolygonModel->setFrontMode(GL_FILL);
    chunkPolygonModel->setBackMode(GL_FILL);
    chunkPolygonModel->setOffsetFactor(1.f);
    chunkPolygonModel->setOffsetBias(1.f);
    chunkPolygonModel->setOffsetFill(true);
    chunkPolygonModel->setCullFace(GL_NONE);

    TwoSidedLightingChunkUnrecPtr chunkTwoSidedLighting = 
TwoSidedLightingChunk::create();
    chunkTwoSidedLighting->setIgnore(false); 

    chunkMaterial->addChunk(chunkPolygonModel);
    chunkMaterial->addChunk(chunkTwoSidedLighting);

    return ChunkMaterialTransitPtr(chunkMaterial);
}

void updateMaterialChunk(osg::MaterialChunk* chunk, const SolidMaterial& rMat)
{
    using namespace osg;

    float colEmissive[4], colAmbient[4], colDiffuse[4], colSpecular[4];

    if (rMat.getGlobalColored()) {
        Color colGlobal = rMat.getColor(SolidMaterial::GLOBAL); colDiffuse[3] = 
1.f - rMat.getTransparency();

        colGlobal.getRgb(colDiffuse);

        XWORD2 w2Hue, w2Saturation, w2Value;
        colGlobal.HsvGet(&w2Hue, &w2Saturation, &w2Value);

        w2Value /= 3;
        colGlobal.HsvSet(w2Hue, w2Saturation, w2Value);
        colGlobal.getRgb(colAmbient);

        for (int i = 0; i < 3; ++i) {
            colEmissive[i] = 0.f;
            colSpecular[i] = 0.f;
        }
        colEmissive[3] = 1.f;
        colAmbient [3] = 1.f;
        colSpecular[3] = 1.f;

    } else {
        rMat.getColor(SolidMaterial::EMISSIVE).getRgb(colEmissive); 
colEmissive[3] = 1.f;
        rMat.getColor(SolidMaterial::AMBIENT) .getRgb(colAmbient);  
colAmbient[3]  = 1.0;
        rMat.getColor(SolidMaterial::DIFFUSE) .getRgb(colDiffuse);  
colDiffuse[3]  = 1.f - rMat.getTransparency();
        rMat.getColor(SolidMaterial::SPECULAR).getRgb(colSpecular); 
colSpecular[3] = 1.f;
    }

    chunk->setAmbient      (Color4f(colAmbient[0],  colAmbient[1],  
colAmbient[2],  colAmbient[3]));
    chunk->setDiffuse      (Color4f(colDiffuse[0],  colDiffuse[1],  
colDiffuse[2],  colDiffuse[3]));
    chunk->setEmission     (Color4f(colEmissive[0], colEmissive[1], 
colEmissive[2], colEmissive[3]));
    chunk->setSpecular     (Color4f(colSpecular[0], colSpecular[1], 
colSpecular[2], colSpecular[3]));
    chunk->setShininess    (rMat.getShininess());
}

Hope, that this is a proper guess, otherwise I will try to compile your example.

Best,
Johannes

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to