9 : diffuse(1.0f, 1.0f, 1.0f)
13 memset(stdtex, 0, sizeof stdtex);
19 void Material::setup() const
21 float kd[] = {diffuse.x, diffuse.y, diffuse.z, alpha};
22 float ks[] = {specular.x, specular.y, specular.z, 1.0f};
24 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, kd);
25 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ks);
26 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
29 int ntex = std::min((int)textures.size(), 8); // TODO: use max texture units
30 for(int i=0; i<ntex; i++) {
31 bind_texture(textures[i], i);
34 for(int i=0; i<NUM_MTL_TEXTURES; i++) {
36 bind_texture(stdtex[i], i);
41 if(stdtex[MTL_TEX_LIGHTMAP]) {
42 bind_program(stdtex[MTL_TEX_DIFFUSE] ? sdr_ltmap : sdr_ltmap_notex);
47 void Material::add_texture(Texture *tex, int type)
49 if(std::find(textures.begin(), textures.end(), tex) == textures.end()) {
50 textures.push_back(tex);
53 if(type != MTL_TEX_UNKNOWN) {
58 void Material::remove_texture(Texture *tex)
60 std::vector<Texture*>::iterator it = std::find(textures.begin(), textures.end(), tex);
61 if(it != textures.end()) {
65 for(int i=0; i<NUM_MTL_TEXTURES; i++) {
66 if(stdtex[i] == tex) {
72 int mtl_parse_type(const char *str)
74 if(strcmp(str, "diffuse") == 0) {
75 return MTL_TEX_DIFFUSE;
76 } else if(strcmp(str, "specular") == 0) {
77 return MTL_TEX_SPECULAR;
78 } else if(strcmp(str, "normalmap") == 0) {
79 return MTL_TEX_NORMALMAP;
80 } else if(strcmp(str, "lightmap") == 0) {
81 return MTL_TEX_LIGHTMAP;
82 } else if(strcmp(str, "envmap") == 0) {
83 return MTL_TEX_REFLECT;
85 return MTL_TEX_UNKNOWN;
88 const char *mtl_type_string(int type)
93 case MTL_TEX_SPECULAR:
95 case MTL_TEX_NORMALMAP:
97 case MTL_TEX_LIGHTMAP: