nuclear@12: #include nuclear@11: #include nuclear@11: #include nuclear@11: #include "opengl.h" nuclear@11: #include "material.h" nuclear@11: 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@11: if(val > 127) { nuclear@12: fprintf(stderr, "Warning: shininess %f... setting to 127\n", val); nuclear@11: val = 127; nuclear@11: } nuclear@11: shin = 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@11: unsigned int asstypes[] = { nuclear@11: aiTextureType_DIFFUSE, nuclear@11: aiTextureType_NORMALS, nuclear@11: aiTextureType_SPECULAR nuclear@11: }; nuclear@11: nuclear@11: for(int i=0; iget_texture(tex_name.data); nuclear@11: } else { nuclear@11: tex[i] = 0; 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: }