From Geof Michel, bug fix to handling of Materials

This commit is contained in:
Robert Osfield
2004-03-07 14:19:48 +00:00
parent 68f462983f
commit bd80dee903
2 changed files with 7 additions and 4 deletions

View File

@@ -158,9 +158,10 @@ static std::vector<osg::Material*> palette; // change to dynamic array
static int startmatindex = 0;
osg::Material*ac_palette_get_material(int id)
osg::Material*ac_palette_get_material(const unsigned int id)
{
return(palette[id]);
if (id<palette.size()) return(palette[id]);
else return NULL;
}
@@ -651,8 +652,9 @@ osg::Group *ac_load_object(FILE *f,const ACObject *parent)
{
geom->setTexCoordArray(0,tgeom); // share same set of TexCoords
}
osg::Material*mat=ac_palette_get_material(asurf.mat);
osg::StateSet *dstate = new osg::StateSet;
osg::Material*mat=ac_palette_get_material(asurf.mat);
if (mat) {
dstate->setMode( GL_LIGHTING, osg::StateAttribute::ON );
dstate->setAttribute(mat);
const osg::Vec4 cdiff =mat->getDiffuse(osg::Material::FRONT_AND_BACK);
@@ -665,6 +667,7 @@ osg::Group *ac_load_object(FILE *f,const ACObject *parent)
{
dstate->setMode(GL_BLEND,osg::StateAttribute::OFF);
}
}
if (ob.texture.valid()) dstate->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OFF);
if (ob.texture.valid())
{

View File

@@ -65,7 +65,7 @@ typedef struct ACObject_t
Prototype osg::Group *ac_load_ac3d(const char *filename);
Prototype osg::Material *ac_palette_get_material(int index);
Prototype osg::Material *ac_palette_get_material(const unsigned int index);