From 5d4e993e485ae3432eabb45caf4e4d43c9bc54e6 Mon Sep 17 00:00:00 2001 From: Evan Goers Date: Tue, 24 Jan 2012 06:44:19 +0000 Subject: Added a 'specular' material parameter. Defaults to 'color' values. Tweaked lighting a bit. --- src/render/state.cc | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/render/state.cc') diff --git a/src/render/state.cc b/src/render/state.cc index dcf62f3..8d1f3b0 100644 --- a/src/render/state.cc +++ b/src/render/state.cc @@ -207,16 +207,18 @@ void State::set_power(const bool power) void State::use_material(const model::Material * material) { math::Color color; + math::Color specular; reset(); - // material settings + // default specular shininess setting glMateriali(GL_FRONT, GL_SHININESS, 8); - GLfloat specular_reflectance[3]; if (!material) { color.assign(1.0f, 0.0f, 1.0f); + specular.assign(1.0f, 0.0f, 1.0f); gl::color(color); + gl::specular(specular); return; } @@ -233,28 +235,37 @@ void State::use_material(const model::Material * material) { // use current engine color color.assign(state_color_engine); + specular.assign(0.0f); } else if (material->flags() & model::Material::Tertiary) { // use entity colors if ((material->flags() & model::Material::Tertiary) == model::Material::Tertiary) { - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; i++) { color[i] = (state_color_primary[i] + state_color_secondary[i]) / 2; + specular[i] = (state_color_primary[i] + state_color_secondary[i]) / 2; + } } else if ((material->flags() & model::Material::Secondary) == model::Material::Secondary) { color.assign(state_color_secondary); + specular.assign(state_color_secondary); } else if ((material->flags() & model::Material::Primary) == model::Material::Primary) { color.assign(state_color_primary); + specular.assign(state_color_primary); } color.r *= material->color().r; color.g *= material->color().g; color.b *= material->color().b; - + specular.r *= material->specular().r; + specular.g *= material->specular().g; + specular.b *= material->specular().b; + } else { // use material color color.assign(material->color()); + specular.assign(material->specular()); } // lighted or fullbright @@ -298,25 +309,12 @@ void State::use_material(const model::Material * material) { } else { color.assign(0.0f, 0.0f, 0.0f); } - specular_reflectance[0] = 1.0f; - specular_reflectance[1] = 1.0f; - specular_reflectance[2] = 1.0f; - glMateriali(GL_FRONT, GL_SHININESS, 4); - glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance); - - gl::color(color); - return; } } - specular_reflectance[0] = color.r; - specular_reflectance[1] = color.g; - specular_reflectance[2] = color.b; - - glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance); - gl::color(color); + gl::specular(specular); } void State::reset() { -- cgit v1.2.3