From 75fd54748dd65b25f25f84a0bbdc25d6b7d4eb67 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 22 Mar 2012 19:56:35 +0000 Subject: Cleaned up lighting related variable names. --- src/render/draw.cc | 46 ++++++++++++++++++++++++++-------------------- src/render/draw.h | 6 +++--- src/ui/modelview.cc | 27 ++++++++++++--------------- 3 files changed, 41 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/render/draw.cc b/src/render/draw.cc index 71b8631..5d960fe 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -46,8 +46,10 @@ math::Vector3f v6(-1, 1, -1); math::Vector3f v7(-1, -1, -1); core::Zone *zone = 0; -float zone_light[] = { 0.0f, 0.0f, 0.0f, 1.0f }; // location of the zone light -math::Color zone_color; // color of the zone light + +math::Vector3f zone_light_location; // location of the zone light +math::Color zone_light_color; // color of the zone light + bool has_zone_light = false; bool draw_particles = true; @@ -66,14 +68,17 @@ Globes globes_list; /* ---- Prepare the renderer state --------------------------------- */ void pass_reset_lights() -{ +{ // reset light state + has_zone_light = false; + zone_light_color.assign(1.0); + for (size_t i = 0; i < max_lights; i++) gl::disable(GL_LIGHT0 + i); } -// Lights -int add_light(float* location, float attenuation, math::Color color) +// setup an OpenGL light +int add_light(const math::Vector3f & location, float attenuation, const math::Color & color) { int gllight; @@ -135,8 +140,6 @@ void pass_prepare(float seconds) // initialize lights pass_reset_lights(); - has_zone_light = false; - zone_color.assign(1.0); // clear current list of globes globes_list.clear(); @@ -166,14 +169,13 @@ void pass_prepare(float seconds) globes_list[ext_render(globe)->distance()] = globe; } - // add level lights - + // add zone lights if (globe->flag_is_set(core::Entity::Bright)) { for (size_t i = 0; i < 3; i++) { - zone_light[i] = globe->location()[i]; - zone_color[i] = globe->color()[i]; + zone_light_location[i] = globe->location()[i]; + zone_light_color[i] = globe->color()[i]; } - GLenum zone_gllight = add_light(zone_light, 0.00025f, globe->color()); + GLenum zone_gllight = add_light(zone_light_location, 0.00025f, globe->color()); gl::enable(zone_gllight); has_zone_light = true; } @@ -268,7 +270,7 @@ void draw_pass_sky() /* ---- Globes ----------------------------------------------------- */ -void draw_sphere(math::Color const & color, float radius) +void draw_sphere(const math::Color & color, float radius) { gl::scale(radius, radius, radius); gl::color(color); @@ -345,13 +347,14 @@ void draw_pass_globes() gl::depthmask(GL_FALSE); if (has_zone_light) { - // move zone light - float fake_light[4]; + // nudge zone light + // FIXME doesn't work correctly with multiple zone lights + float fake_light_location[4]; for (size_t i = 0; i < 3; i++) { - fake_light[i] = zone_light[i] + location[i] - globe->location()[i]; + fake_light_location[i] = zone_light_location[i] + location[i] - globe->location()[i]; } - fake_light[3] = 1.0f; - glLightfv(zone_gllight, GL_POSITION, fake_light); + fake_light_location[3] = 1.0f; + glLightfv(zone_gllight, GL_POSITION, fake_light_location); } } @@ -398,7 +401,7 @@ void draw_pass_globes() if (has_zone_light) { // restore zone light - glLightfv(zone_gllight, GL_POSITION, zone_light); + glLightfv(zone_gllight, GL_POSITION, zone_light_location.ptr()); } } } @@ -1222,7 +1225,7 @@ void draw(float seconds) draw_pass_spacegrid(); // draw the blue spacegrid if (!core::localplayer()->view()) { - Dust::draw(zone_color); // draw spacedust + Dust::draw(zone_light_color); // draw spacedust } // draw entity lights, flares and particles @@ -1282,6 +1285,9 @@ void draw(float seconds) // GL_BLEND and GL_COLOR_MATERIAL must be enabled for the GUI //gl::disable(GL_COLOR_MATERIAL); // disable color tracking + + // reset light state + pass_reset_lights(); } // draw HUD target world space geometry, like dock indicators diff --git a/src/render/draw.h b/src/render/draw.h index 59a5b4a..f814168 100644 --- a/src/render/draw.h +++ b/src/render/draw.h @@ -26,11 +26,11 @@ void draw_target(const core::Entity *entity); /// reset void reset(); -/// create light -int add_light(float* location, float attenuation, math::Color color); +/// add a zone light +int add_light(const math::Vector3f & location, float attenuation, const math::Color & color); /// draw a sphere -void draw_sphere(math::Color const & color, float radius); +void draw_sphere(const math::Color & color, float radius); /// draw a corona void draw_globe_corona(const math::Vector3f location, const math::Color & color, const float radius, const size_t corona_id); diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc index 303f8e2..813fddb 100755 --- a/src/ui/modelview.cc +++ b/src/ui/modelview.cc @@ -19,9 +19,8 @@ namespace ui { -GLenum modelview_gllight = GL_LIGHT0; -float modelview_light_distance = -10.0f; -float modelview_light_attenuation = 0.05f; +const float LIGHT_DISTANCE = -10.0f; +const float LIGHT_ATTENUATION = 0.05f; ModelView::ModelView(Widget *parent) : Widget(parent) { @@ -206,12 +205,11 @@ void ModelView::draw_globe() glEnableClientState(GL_NORMAL_ARRAY); // we set up the light in camera space - float modelview_light_location[] = {modelview_light_distance * reference_radius, 0, 0}; - math::Color modelview_light_color; - modelview_light_color.assign(1.0); - modelview_gllight = render::add_light(modelview_light_location, modelview_light_attenuation, modelview_light_color); + const math::Vector3f light_location(LIGHT_DISTANCE * reference_radius, 0, 0); + const math::Color light_color(1.0f, 1.0f, 1.0f); + GLenum gllight = render::add_light(light_location, LIGHT_ATTENUATION, light_color); - gl::enable(modelview_gllight); + gl::enable(gllight); render::State::set_normalize(true); @@ -240,7 +238,7 @@ void ModelView::draw_globe() gl::pop(); render::State::set_normalize(false); - gl::disable(modelview_gllight); + gl::disable(gllight); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); @@ -306,12 +304,11 @@ void ModelView::draw_model() glEnableClientState(GL_NORMAL_ARRAY); // we set up the light in camera space - float modelview_light_location[] = {modelview_light_distance * reference_radius, 0, 0}; - math::Color modelview_light_color; - modelview_light_color.assign(1.0); - modelview_gllight = render::add_light(modelview_light_location, modelview_light_attenuation, modelview_light_color); + const math::Vector3f light_location(LIGHT_DISTANCE * reference_radius, 0, 0); + const math::Color light_color(1.0f, 1.0f, 1.0f); + GLenum gllight = render::add_light(light_location, LIGHT_ATTENUATION, light_color); - gl::enable(modelview_gllight); + gl::enable(gllight); // push transformation matrix to stack gl::push(); @@ -335,7 +332,7 @@ void ModelView::draw_model() gl::pop(); - gl::disable(modelview_gllight); + gl::disable(gllight); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); -- cgit v1.2.3