diff options
author | Stijn Buys <ingar@osirion.org> | 2014-07-09 19:18:31 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2014-07-09 19:18:31 +0000 |
commit | 1d518a54914531d7a4fab3a6835b75de85bd7bc7 (patch) | |
tree | cabfcb6f735e3c928cddf79169fb84d9b422747f /src/ui | |
parent | 25a7edee2f003f259fc3a97bbfc047d72adaa361 (diff) |
Initial support for multi-layered materials, requires shaders files in the new format.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/paint.cc | 119 |
1 files changed, 52 insertions, 67 deletions
diff --git a/src/ui/paint.cc b/src/ui/paint.cc index cea363c..d33e1a3 100644 --- a/src/ui/paint.cc +++ b/src/ui/paint.cc @@ -76,15 +76,7 @@ void Paint::draw_rectangle_gradient(const math::Vector2f &global_location, const void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture, const float preserve_aspect) { - // find the material - model::Material *material = model::Material::find(texture); - if (!material) { - material = new model::Material(texture); - model::Material::add(material); - material->set_texture(material->name()); - // ui btimaps are fullbright - material->set_flags(model::Material::FlagBright); - } + model::Material *material = model::Material::load(texture, true); math::Vector2f bitmap_location; math::Vector2f bitmap_size(size); @@ -101,39 +93,34 @@ void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vecto render::State::set_color(math::Color()); render::State::set_color_second(math::Color()); - render::State::use_material(material); - gl::begin(gl::Quads); - - glTexCoord2f(0.0f, 0.0f); - gl::vertex(bitmap_location.x(), bitmap_location.y()); + for (model::Material::Layers::const_iterator lit = material->layers().begin(); lit != material->layers().end(); ++lit) { + render::State::use_material_layer(material, *lit); + + gl::begin(gl::Quads); - glTexCoord2f(1.0f, 0.0f); - gl::vertex(bitmap_location.x() + bitmap_size.width(), bitmap_location.y()); + glTexCoord2f(0.0f, 0.0f); + gl::vertex(bitmap_location.x(), bitmap_location.y()); - glTexCoord2f(1.0f, 1.0f); - gl::vertex(bitmap_location.x() + bitmap_size.width(), bitmap_location.y() + bitmap_size.height()); + glTexCoord2f(1.0f, 0.0f); + gl::vertex(bitmap_location.x() + bitmap_size.width(), bitmap_location.y()); - glTexCoord2f(0.0f, 1.0f); - gl::vertex(bitmap_location.x(), bitmap_location.y() + bitmap_size.height()); + glTexCoord2f(1.0f, 1.0f); + gl::vertex(bitmap_location.x() + bitmap_size.width(), bitmap_location.y() + bitmap_size.height()); - gl::end(); + glTexCoord2f(0.0f, 1.0f); + gl::vertex(bitmap_location.x(), bitmap_location.y() + bitmap_size.height()); + gl::end(); + } + render::State::reset(); } // draw a bitmap and override material color void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const math::Color & color, const std::string &texture, const float preserve_aspect) { - // find the material - model::Material *material = model::Material::find(texture); - if (!material) { - material = new model::Material(texture); - model::Material::add(material); - material->set_texture(material->name()); - // ui btimaps are fullbright - material->set_flags(model::Material::FlagBright); - } + model::Material *material = model::Material::load(texture, true); math::Vector2f bitmap_location; math::Vector2f bitmap_size(size); @@ -148,41 +135,36 @@ void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vecto } render::State::set_power(true); - render::State::use_material(material); - // this overrides material color - gl::color(color); - gl::begin(gl::Quads); + for (model::Material::Layers::const_iterator lit = material->layers().begin(); lit != material->layers().end(); ++lit) { + render::State::use_material_layer(material, *lit); + + // this overrides material color + gl::color(color); + + gl::begin(gl::Quads); - glTexCoord2f(0.0f, 0.0f); - gl::vertex(bitmap_location.x(), bitmap_location.y()); + glTexCoord2f(0.0f, 0.0f); + gl::vertex(bitmap_location.x(), bitmap_location.y()); - glTexCoord2f(1.0f, 0.0f); - gl::vertex(bitmap_location.x() + bitmap_size.width(), bitmap_location.y()); + glTexCoord2f(1.0f, 0.0f); + gl::vertex(bitmap_location.x() + bitmap_size.width(), bitmap_location.y()); - glTexCoord2f(1.0f, 1.0f); - gl::vertex(bitmap_location.x() + bitmap_size.width(), bitmap_location.y() + bitmap_size.height()); + glTexCoord2f(1.0f, 1.0f); + gl::vertex(bitmap_location.x() + bitmap_size.width(), bitmap_location.y() + bitmap_size.height()); - glTexCoord2f(0.0f, 1.0f); - gl::vertex(bitmap_location.x(), bitmap_location.y() + bitmap_size.height()); + glTexCoord2f(0.0f, 1.0f); + gl::vertex(bitmap_location.x(), bitmap_location.y() + bitmap_size.height()); - gl::end(); - - render::State::reset(); + gl::end(); + render::State::reset(); + } } void Paint::draw_material(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture) { - // find the material - model::Material *material = model::Material::find(texture); - if (!material) { - material = new model::Material(texture); - model::Material::add(material); - material->set_texture(material->name()); - // ui btimaps are fullbright - material->set_flags(model::Material::FlagBright); - } + model::Material *material = model::Material::load(texture, true); // use global coordinates const float w0 = global_location.x() / material->size().width(); @@ -194,25 +176,28 @@ void Paint::draw_material(const math::Vector2f &global_location, const math::Vec render::State::set_power(true); render::State::set_color(math::Color()); render::State::set_color_second(math::Color()); - render::State::use_material(material); - gl::begin(gl::Quads); - - glTexCoord2f(w0, h0); - gl::vertex(global_location.x(), global_location.y()); + + for (model::Material::Layers::const_iterator lit = material->layers().begin(); lit != material->layers().end(); ++lit) { + render::State::use_material_layer(material, *lit); + + gl::begin(gl::Quads); - glTexCoord2f(w1, h0); - gl::vertex(global_location.x() + size.width(), global_location.y()); + glTexCoord2f(w0, h0); + gl::vertex(global_location.x(), global_location.y()); - glTexCoord2f(w1, h1); - gl::vertex(global_location.x() + size.width(), global_location.y() + size.height()); + glTexCoord2f(w1, h0); + gl::vertex(global_location.x() + size.width(), global_location.y()); - glTexCoord2f(w0, h1); - gl::vertex(global_location.x(), global_location.y() + size.height()); + glTexCoord2f(w1, h1); + gl::vertex(global_location.x() + size.width(), global_location.y() + size.height()); - gl::end(); + glTexCoord2f(w0, h1); + gl::vertex(global_location.x(), global_location.y() + size.height()); - render::State::reset(); + gl::end(); + render::State::reset(); + } } // draw unaligned text |