textures, lightmaps, hardcoded texture hack for testing
[laserbrain_demo] / src / material.cc
index 962b10c..ac8c112 100644 (file)
@@ -1,3 +1,5 @@
+#include <algorithm>
+#include <string.h>
 #include "opengl.h"
 #include "material.h"
 
@@ -6,6 +8,7 @@ Material::Material()
 {
        shininess = 0.0f;
        alpha = 1.0f;
+       memset(stdtex, 0, sizeof stdtex);
 }
 
 void Material::setup() const
@@ -16,4 +19,18 @@ void Material::setup() const
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, kd);
        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);
+       }
+}
+
+void Material::add_texture(Texture *tex, int type)
+{
+       textures.push_back(tex);
+
+       if(type != MTL_TEX_UNKNOWN) {
+               stdtex[type] = tex;
+       }
 }