diff options
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/draw.cc | 109 |
1 files changed, 61 insertions, 48 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc index 1c8dd31..75c488b 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -551,7 +551,7 @@ void draw_model_fragments(core::Entity *entity) return; // default material, lighted and geometry color - unsigned int material = Material::None; + const model::Material *material = 0; bool use_color_array = true; // glEnableClientState(GL_COLOR_ARRAY) is set bool use_light = true; // gl::disable(GL_LIGHTING) is set @@ -595,60 +595,73 @@ void draw_model_fragments(core::Entity *entity) if (fragment->material() != material) { material = fragment->material(); - if (material & Material::Engine) { - - if (use_color_array) { - glDisableClientState(GL_COLOR_ARRAY); - use_color_array = false; - } - - gl::color(model->enginecolor() * thrust); - - } else if (material & Material::Tertiary) { - if (use_color_array) { - use_color_array = false; - glDisableClientState(GL_COLOR_ARRAY); + if (material) { + if (material->flags() & Material::Engine) { + + if (use_color_array) { + glDisableClientState(GL_COLOR_ARRAY); + use_color_array = false; + } + + gl::color(model->enginecolor() * thrust); + + } else if (material->flags() & Material::Tertiary) { + if (use_color_array) { + use_color_array = false; + glDisableClientState(GL_COLOR_ARRAY); + } + + math::Color color; + + if ((material->flags() & Material::Tertiary) == Material::Tertiary) { + for (size_t i = 0; i < 3; i++) + color[i] = (entity->color()[i] + entity->color_second()[i]) / 2; + + } else if ((material->flags() & Material::Secondary) == Material::Secondary) { + color.assign(entity->color_second()); + + } if ((material->flags() & Material::Primary) == Material::Primary) { + color.assign(entity->color()); + } + + color.r *= material->color().r; + color.g *= material->color().g; + color.b *= material->color().b; + + gl::color(color); + + } else { + if (!use_color_array) { + glEnableClientState(GL_COLOR_ARRAY); + use_color_array = true; + } } - - math::Color color; - - if ((material & Material::Tertiary) == Material::Tertiary) { - for (size_t i = 0; i < 3; i++) - color[i] = (entity->color()[i] + entity->color_second()[i]) / 2; - - } else if ((material & Material::Secondary) == Material::Secondary) { - color.assign(entity->color_second()); - - } if ((material & Material::Primary) == Material::Primary) { - color.assign(entity->color()); + + if (power && (material->flags() & Material::Bright)) { + if (use_light) { + gl::disable(GL_LIGHTING); + use_light = false; + } + } else if (power && (material->flags() & Material::Engine)) { + if (use_light) { + gl::disable(GL_LIGHTING); + use_light = false; + } + } else { + if (!use_light) { + gl::enable(GL_LIGHTING); + use_light = true; + } } - - if (material & Material::Dark) - color *= 0.5f; - - gl::color(color); - } else { - if (!use_color_array) { - glEnableClientState(GL_COLOR_ARRAY); - use_color_array = true; - } - } - - if (power && (material & Material::Light)) { - if (use_light) { - gl::disable(GL_LIGHTING); - use_light = false; - } - } else if (power && (material & Material::Engine)) { + /// material not found if (use_light) { gl::disable(GL_LIGHTING); use_light = false; } - } else { - if (!use_light) { - gl::enable(GL_LIGHTING); - use_light = true; + if (!use_color_array) { + glEnableClientState(GL_COLOR_ARRAY); + use_color_array = true; } } } |