9 : diffuse(1.0f, 1.0f, 1.0f)
13 memset(stdtex, 0, sizeof stdtex);
16 void Material::setup() const
18 float kd[] = {diffuse.x, diffuse.y, diffuse.z, alpha};
19 float ks[] = {specular.x, specular.y, specular.z, 1.0f};
21 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, kd);
22 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ks);
23 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
26 int ntex = std::min((int)textures.size(), 8); // TODO: use max texture units
27 for(int i=0; i<ntex; i++) {
28 bind_texture(textures[i], i);
31 for(int i=0; i<NUM_MTL_TEXTURES; i++) {
33 bind_texture(stdtex[i], i);
37 if(stdtex[MTL_TEX_LIGHTMAP]) {
38 bind_program(stdtex[MTL_TEX_DIFFUSE] ? sdr_ltmap : sdr_ltmap_notex);
42 void Material::add_texture(Texture *tex, int type)
44 if(std::find(textures.begin(), textures.end(), tex) == textures.end()) {
45 textures.push_back(tex);
48 if(type != MTL_TEX_UNKNOWN) {
53 void Material::remove_texture(Texture *tex)
55 std::vector<Texture*>::iterator it = std::find(textures.begin(), textures.end(), tex);
56 if(it != textures.end()) {
60 for(int i=0; i<NUM_MTL_TEXTURES; i++) {
61 if(stdtex[i] == tex) {
67 int mtl_parse_type(const char *str)
69 if(strcmp(str, "diffuse") == 0) {
70 return MTL_TEX_DIFFUSE;
71 } else if(strcmp(str, "specular") == 0) {
72 return MTL_TEX_SPECULAR;
73 } else if(strcmp(str, "normalmap") == 0) {
74 return MTL_TEX_NORMALMAP;
75 } else if(strcmp(str, "lightmap") == 0) {
76 return MTL_TEX_LIGHTMAP;
77 } else if(strcmp(str, "envmap") == 0) {
78 return MTL_TEX_ENVMAP;
80 return MTL_TEX_UNKNOWN;
83 const char *mtl_type_string(int type)
88 case MTL_TEX_SPECULAR:
90 case MTL_TEX_NORMALMAP:
92 case MTL_TEX_LIGHTMAP: