mirror mtledit
[laserbrain_demo] / src / material.cc
index f893175..26ab63d 100644 (file)
@@ -11,6 +11,9 @@ Material::Material()
        shininess = 0.0f;
        alpha = 1.0f;
        memset(stdtex, 0, sizeof stdtex);
+
+       reflect = 0.0f;
+       flat_mirror = false;
 }
 
 void Material::setup() const
@@ -22,10 +25,17 @@ void Material::setup() const
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ks);
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
 
+       /*
        int ntex = std::min((int)textures.size(), 8);   // TODO: use max texture units
        for(int i=0; i<ntex; i++) {
                bind_texture(textures[i], i);
        }
+       */
+       for(int i=0; i<NUM_MTL_TEXTURES; i++) {
+               if(stdtex[i]) {
+                       bind_texture(stdtex[i], i);
+               }
+       }
 
        if(stdtex[MTL_TEX_LIGHTMAP]) {
                bind_program(stdtex[MTL_TEX_DIFFUSE] ? sdr_ltmap : sdr_ltmap_notex);
@@ -34,13 +44,29 @@ void Material::setup() const
 
 void Material::add_texture(Texture *tex, int type)
 {
-       textures.push_back(tex);
+       if(std::find(textures.begin(), textures.end(), tex) == textures.end()) {
+               textures.push_back(tex);
+       }
 
        if(type != MTL_TEX_UNKNOWN) {
                stdtex[type] = tex;
        }
 }
 
+void Material::remove_texture(Texture *tex)
+{
+       std::vector<Texture*>::iterator it = std::find(textures.begin(), textures.end(), tex);
+       if(it != textures.end()) {
+               textures.erase(it);
+       }
+
+       for(int i=0; i<NUM_MTL_TEXTURES; i++) {
+               if(stdtex[i] == tex) {
+                       stdtex[i] = 0;
+               }
+       }
+}
+
 int mtl_parse_type(const char *str)
 {
        if(strcmp(str, "diffuse") == 0) {