Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-05-01 20:46:58 +0000
committerStijn Buys <ingar@osirion.org>2012-05-01 20:46:58 +0000
commit6eddb531d70d5dad5fb2f037072b9ec4f4e4b5e5 (patch)
tree2abffd85b46e82fdb6d2d4fff1d1e2aa18fc8549 /src/ui
parent26b1401d6cfdfd35afe275e287dc7d205902e55e (diff)
Use light environment classes in the model viewer and the main rendering routine.
Diffstat (limited to 'src/ui')
-rwxr-xr-xsrc/ui/modelview.cc62
1 files changed, 34 insertions, 28 deletions
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index d1c5c96..b13b642 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -12,6 +12,8 @@
#include "sys/sys.h"
#include "render/camera.h"
#include "render/draw.h"
+#include "render/light.h"
+#include "render/lightenvironment.h"
#include "render/render.h"
#include <sstream>
#include <iomanip>
@@ -20,7 +22,7 @@ namespace ui
{
const float LIGHT_DISTANCE = -10.0f;
-const float LIGHT_ATTENUATION = 0.1f;
+const float LIGHT_ATTENUATION = 2.0f;
ModelView::ModelView(Widget *parent) : Widget(parent)
{
@@ -183,9 +185,19 @@ void ModelView::draw_globe()
// gl 3d mode
render::Camera::frustum_default(modelview_zoom, center.x(), center.y());
- // reset lighting
- render::pass_reset_lights();
+ // set up light environment
+ render::Light *light = new render::Light(
+ math::Vector3f(LIGHT_DISTANCE * reference_radius, 0, 0),
+ math::Color(1.0f, 1.0f, 1.0f)
+ );
+ light->set_attenuation(0.0f, 1.0f, 0.0f);
+ render::LightEnvironment lightenv;
+ lightenv.add(light);
+
+ lightenv.enable();
+ lightenv.draw();
+
// enable lighting
gl::enable(GL_LIGHTING);
@@ -204,13 +216,6 @@ void ModelView::draw_globe()
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
- // we set up the light in camera space
- 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(gllight);
-
render::State::set_normalize(true);
// push transformation matrix to stack
@@ -238,7 +243,7 @@ void ModelView::draw_globe()
gl::pop();
render::State::set_normalize(false);
- gl::disable(gllight);
+ lightenv.disable();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
@@ -251,11 +256,9 @@ void ModelView::draw_globe()
gl::depthmask(GL_FALSE); // enable depth buffer writing
gl::disable(GL_DEPTH_TEST); // disable depth buffer testing
gl::disable(GL_LIGHTING);
-
- // gl 2d mode
- render::Camera::ortho();
-
+ // gl 2d mode
+ render::Camera::ortho();
}
void ModelView::draw_model()
@@ -282,8 +285,18 @@ void ModelView::draw_model()
// gl 3d mode
render::Camera::frustum_default(modelview_zoom, center.x(), center.y());
- // reset lighting
- render::pass_reset_lights();
+ // set up light environment
+ render::Light *light = new render::Light(
+ math::Vector3f(LIGHT_DISTANCE * reference_radius, 0, 0),
+ math::Color(1.0f, 1.0f, 1.0f)
+ );
+ light->set_attenuation(0.0f, 1.0f, 0.0f);
+
+ render::LightEnvironment lightenv;
+ lightenv.add(light);
+
+ lightenv.enable();
+ lightenv.draw();
// enable lighting
gl::enable(GL_LIGHTING);
@@ -303,13 +316,6 @@ void ModelView::draw_model()
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
- // we set up the light in camera space
- 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(gllight);
-
// push transformation matrix to stack
gl::push();
@@ -332,7 +338,7 @@ void ModelView::draw_model()
gl::pop();
- gl::disable(gllight);
+ lightenv.disable();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
@@ -363,13 +369,13 @@ void ModelView::draw_model()
}
render::draw_model_lights(model, modelscale, math::Vector3f(), modelview_axis, core::localplayer()->color(), thrust, 0.0f);
-
+
gl::disable(GL_TEXTURE_2D);
gl::disable(GL_COLOR_MATERIAL); // disable color tracking
gl::disable(GL_CULL_FACE); // disable culling
gl::depthmask(GL_FALSE); // enable depth buffer writing
- gl::disable(GL_DEPTH_TEST); // disable depth buffer testing
-
+ gl::disable(GL_DEPTH_TEST); // disable depth buffer testing
+
// gl 2d mode
render::Camera::ortho();
}