nuclear@12: #include nuclear@11: #include nuclear@11: #include nuclear@11: #include "opengl.h" nuclear@11: #include "material.h" nuclear@11: nuclear@31: extern bool ass_obj_hack; nuclear@31: nuclear@11: Material::Material() nuclear@11: : kd(1.0, 1.0, 1.0), ks(0.0, 0.0, 0.0) nuclear@11: { nuclear@11: shin = 1.0; nuclear@11: memset(tex, 0, sizeof tex); nuclear@11: } nuclear@11: nuclear@11: void Material::load(const aiMaterial *assmat, TextureSet *texset) nuclear@11: { nuclear@11: aiColor4D col; nuclear@11: float val; nuclear@11: nuclear@11: aiGetMaterialColor(assmat, AI_MATKEY_COLOR_DIFFUSE, &col); nuclear@11: kd = Color(col[0], col[1], col[2]); nuclear@11: aiGetMaterialColor(assmat, AI_MATKEY_COLOR_SPECULAR, &col); nuclear@11: ks = Color(col[0], col[1], col[2]); nuclear@11: nuclear@11: unsigned int sz = 1; nuclear@11: val = 60.0; nuclear@11: aiGetMaterialFloatArray(assmat, AI_MATKEY_SHININESS, &val, &sz); nuclear@31: if(ass_obj_hack) { nuclear@31: val /= 4.0; nuclear@11: } nuclear@31: shin = val > 127 ? 127 : val; nuclear@11: nuclear@11: sz = 1; nuclear@11: val = 1.0; nuclear@11: aiGetMaterialFloatArray(assmat, AI_MATKEY_SHININESS_STRENGTH, &val, &sz); nuclear@11: ks *= val; nuclear@11: nuclear@11: // must match TEXTYPE enum in material.h nuclear@14: unsigned int asstypes[][2] = { nuclear@14: {aiTextureType_DIFFUSE, 0}, nuclear@14: {aiTextureType_NORMALS, aiTextureType_HEIGHT}, nuclear@14: {aiTextureType_SPECULAR, 0} nuclear@11: }; nuclear@11: nuclear@11: for(int i=0; i 0 && aiGetMaterialString(assmat, AI_MATKEY_TEXTURE(asstypes[i][j], 0), &tex_name) == 0) { nuclear@14: tex[i] = texset->get_texture(tex_name.data); nuclear@14: break; nuclear@14: } else { nuclear@14: tex[i] = 0; nuclear@14: } nuclear@11: } nuclear@11: } nuclear@11: } nuclear@11: nuclear@11: void Material::setup() const nuclear@11: { nuclear@11: float dcol[] = {kd.x, kd.y, kd.z, 1.0}; nuclear@11: float scol[] = {ks.x, ks.y, ks.z, 1.0}; nuclear@11: nuclear@11: glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dcol); nuclear@11: glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, scol); nuclear@11: glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shin); nuclear@11: nuclear@11: if(tex[TEXTYPE_DIFFUSE]) { nuclear@11: glActiveTextureARB(GL_TEXTURE0); nuclear@11: glBindTexture(GL_TEXTURE_2D, tex[TEXTYPE_DIFFUSE]); nuclear@11: glEnable(GL_TEXTURE_2D); nuclear@11: } else { nuclear@11: glDisable(GL_TEXTURE_2D); nuclear@11: } nuclear@11: glActiveTextureARB(GL_TEXTURE0); nuclear@11: }