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);
40 if(stdtex[MTL_TEX_LIGHTMAP]) {
41 bind_program(stdtex[MTL_TEX_DIFFUSE] ? sdr_ltmap : sdr_ltmap_notex);
45 void Material::add_texture(Texture *tex, int type)
47 if(std::find(textures.begin(), textures.end(), tex) == textures.end()) {
48 textures.push_back(tex);
51 if(type != MTL_TEX_UNKNOWN) {
56 void Material::remove_texture(Texture *tex)
58 std::vector<Texture*>::iterator it = std::find(textures.begin(), textures.end(), tex);
59 if(it != textures.end()) {
63 for(int i=0; i<NUM_MTL_TEXTURES; i++) {
64 if(stdtex[i] == tex) {
70 int mtl_parse_type(const char *str)
72 if(strcmp(str, "diffuse") == 0) {
73 return MTL_TEX_DIFFUSE;
74 } else if(strcmp(str, "specular") == 0) {
75 return MTL_TEX_SPECULAR;
76 } else if(strcmp(str, "normalmap") == 0) {
77 return MTL_TEX_NORMALMAP;
78 } else if(strcmp(str, "lightmap") == 0) {
79 return MTL_TEX_LIGHTMAP;
80 } else if(strcmp(str, "envmap") == 0) {
81 return MTL_TEX_ENVMAP;
83 return MTL_TEX_UNKNOWN;
86 const char *mtl_type_string(int type)
91 case MTL_TEX_SPECULAR:
93 case MTL_TEX_NORMALMAP:
95 case MTL_TEX_LIGHTMAP: