From bd142a328328cdf0cbfbb59e4e0aa99dd51184b8 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 10 Aug 2009 22:32:36 +0000 Subject: initial texture support for ase models --- src/render/draw.cc | 56 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'src/render/draw.cc') diff --git a/src/render/draw.cc b/src/render/draw.cc index 4392f87..c4c18c3 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -564,8 +564,9 @@ void draw_model_fragments(model::Model *model, { // default material, lighted and geometry color const model::Material *material = 0; - math::Color color(1.0f, 0.0f, 1.0f); // current drawing color + math::Color color(1.0f, 1.0f, 1.0f); // current drawing color bool use_light = true; // gl::disable(GL_LIGHTING) is set + bool use_texture = false; // texturing bool use_env = false; // environment mapping //bool use_color_array = true; // glEnableClientState(GL_COLOR_ARRAY) is set @@ -601,7 +602,7 @@ void draw_model_fragments(model::Model *model, use_color_array = false; }*/ - gl::color(model->enginecolor() * thrust); + color.assign(model->enginecolor() * thrust); } else if (material->flags() & model::Material::Tertiary) { /* if (use_color_array) { @@ -648,26 +649,55 @@ void draw_model_fragments(model::Model *model, } } + if (material->flags() & model::Material::Texture) { + + Textures::bind(material->texture()); + + if (!use_texture) { + gl::enable(GL_TEXTURE_2D); + use_texture = true; + } + + } + if (material->flags() & model::Material::Environment) { - if (!use_env && core::localplayer()->zone()->sky_texture()) { - Textures::bind(core::localplayer()->zone()->sky_texture()); + + if (!(material->flags() & model::Material::Texture)) { + // use sky as envmap if the material defines no texture + if (core::localplayer()->zone()->sky_texture()) { + Textures::bind(core::localplayer()->zone()->sky_texture()); + gl::enable(GL_TEXTURE_2D); + use_texture = true; + } else if (use_texture) { + gl::disable(GL_TEXTURE_2D); + use_texture = false; + } + } + if (!use_env) { // enable env mapping - gl::enable(GL_TEXTURE_2D); gl::enable(GL_TEXTURE_GEN_S); gl::enable(GL_TEXTURE_GEN_T); use_env = true; } + } else { + if (use_env) { // disable env mapping gl::disable(GL_TEXTURE_GEN_S); gl::disable(GL_TEXTURE_GEN_T); - gl::disable(GL_TEXTURE_2D); use_env = false; } } + if (!(material->flags() & (model::Material::Texture + model::Material::Environment))) { + if (use_texture) { + gl::disable(GL_TEXTURE_2D); + use_texture = false; + } + } + } else { // material not found @@ -681,9 +711,14 @@ void draw_model_fragments(model::Model *model, // disable env mapping gl::disable(GL_TEXTURE_GEN_S); gl::disable(GL_TEXTURE_GEN_T); - gl::disable(GL_TEXTURE_2D); use_env = false; } + + if (use_texture) { + gl::disable(GL_TEXTURE_2D); + use_texture = false; + } + /* if (!use_color_array) { glEnableClientState(GL_COLOR_ARRAY); use_color_array = true; @@ -707,13 +742,16 @@ void draw_model_fragments(model::Model *model, if (use_env) { // disable env mapping - gl::disable(GL_TEXTURE_2D); gl::disable(GL_TEXTURE_GEN_S); gl::disable(GL_TEXTURE_GEN_T); - use_env = false; } + if (use_texture) { + gl::disable(GL_TEXTURE_2D); + use_texture = false; + } + /* if (!use_color_array) { glEnableClientState(GL_COLOR_ARRAY); }*/ -- cgit v1.2.3