- GLenum shade_model = GL_SMOOTH;
-
- state = new ssgSimpleState();
- state->ref();
-
- // Set up the textured state
- state->setShadeModel( shade_model );
- state->enable( GL_LIGHTING );
- state->enable ( GL_CULL_FACE ) ;
- state->enable( GL_TEXTURE_2D );
- state->disable( GL_BLEND );
- state->disable( GL_ALPHA_TEST );
- if ( !defer_tex_load ) {
- SG_LOG(SG_INPUT, SG_INFO, " " << texture_path );
- state->setTexture( (char *)texture_path.c_str(), wrapu, wrapv );
- texture_loaded = true;
- } else {
- texture_loaded = false;
+ for (unsigned int i = 0; i < _status.size(); i++)
+ {
+ osg::StateSet *stateSet = new osg::StateSet;
+ stateSet->setUserData(new SGMaterialUserData(this));
+
+ // Set up the textured state
+ osg::ShadeModel* shadeModel = new osg::ShadeModel;
+ shadeModel->setMode(osg::ShadeModel::SMOOTH);
+ stateSet->setAttribute(shadeModel);
+
+ osg::CullFace* cullFace = new osg::CullFace;
+ cullFace->setMode(osg::CullFace::BACK);
+ stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
+ stateSet->setAttribute(cullFace);
+
+ stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
+
+ _status[i].texture_loaded = false;
+
+ osg::Material* material = new osg::Material;
+ material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
+ material->setAmbient(osg::Material::FRONT_AND_BACK, ambient.osg());
+ material->setDiffuse(osg::Material::FRONT_AND_BACK, diffuse.osg());
+ material->setSpecular(osg::Material::FRONT_AND_BACK, specular.osg());
+ material->setEmission(osg::Material::FRONT_AND_BACK, emission.osg());
+ material->setShininess(osg::Material::FRONT_AND_BACK, shininess );
+ stateSet->setAttribute(material);
+
+ if (ambient[3] < 1 || diffuse[3] < 1 ||
+ specular[3] < 1 || emission[3] < 1) {
+ stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
+ stateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
+ stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
+ } else {
+ stateSet->setRenderingHint(osg::StateSet::OPAQUE_BIN);
+ stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF);
+ stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
+ }
+
+ _status[i].state = stateSet;