diff options
-rw-r--r-- | src/render/draw.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc index 22ff90f..ac74c9c 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -514,6 +514,29 @@ void draw_pass_default() /* ---- Model Fragments -------------------------------------------- */ +void draw_fragment_normals(const model::Fragment *fragment, bool draw_details) +{ + size_t index = fragment->index(); + size_t vertex_count = fragment->structural_size(); + if (draw_details) + vertex_count += fragment->detail_size(); + + gl::begin(gl::Lines); + + const float s = 0.05f; + for (size_t i = 0; i < vertex_count; i++) { + const float *n = &core::game()->vertexarray()->ptr()[(index+i) * 8 + 2]; + const float *v = &core::game()->vertexarray()->ptr()[(index+i) * 8 + 5]; + + //gl::normal(-n[0], -n[1], -n[2]); + gl::vertex(v[0], v[1], v[2]); + + //gl::normal(n[0], n[1], n[2]); + gl::vertex(v[0] + n[0] * s, v[1] + n[1] * s, v[2] + n[2] * s); + } + gl::end(); +} + void draw_fragment(const model::Fragment *fragment, bool draw_details) { size_t index = fragment->index(); @@ -725,6 +748,31 @@ void draw_model_fragments(model::Model *model, gl::color(color); draw_fragment(fragment, detail); + + if (r_normals->value()) { + // force reset of material settings for the next fragment + material = 0; + if (use_light) { + // disable lighting + gl::disable(GL_LIGHTING); + use_light = false; + } + + if (use_env) { + // disable env mapping + 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; + } + + color.assign(0.75f, 0.0f, 0.0f); + draw_fragment_normals(fragment, detail); + } } if (group->transform()) { |