diff options
author | Stijn Buys <ingar@osirion.org> | 2012-05-01 20:44:51 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-05-01 20:44:51 +0000 |
commit | 26b1401d6cfdfd35afe275e287dc7d205902e55e (patch) | |
tree | befd04ee2ade7e7e5c1a1a93b42bc4d07252444f /src/render/lightenvironment.cc | |
parent | 486f74a45c8241862f2b94d63e54aeb2bc5d5424 (diff) |
Added light environment classes
Diffstat (limited to 'src/render/lightenvironment.cc')
-rw-r--r-- | src/render/lightenvironment.cc | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/render/lightenvironment.cc b/src/render/lightenvironment.cc new file mode 100644 index 0000000..8c65848 --- /dev/null +++ b/src/render/lightenvironment.cc @@ -0,0 +1,108 @@ +/* + render/lightenvironment.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "render/lightenvironment.h" +#include "render/gl.h" + +namespace render +{ + +LightEnvironment::LightEnvironment() +{ + env_base_id = GL_LIGHT0; + + env_attenuation = 0.0005f; + env_ambient_intensity = 0.1f; + env_diffuse_intensity = 0.75f; + env_specular_intensity = 0.75f; +} + +LightEnvironment::~LightEnvironment() +{ + clear(); +} + +void LightEnvironment::clear() +{ + for (Container::iterator it = env_container.begin(); it != env_container.end(); ++it) { + Light *light = (*it); + delete light; + (*it) = 0; + } + env_container.clear(); +} + +void LightEnvironment::add(Light *light) +{ + env_container.push_back(light); +} + +void LightEnvironment::enable() +{ + int gl_light_id = env_base_id; + for (Container::iterator it = env_container.begin(); it != env_container.end(); ++it) { + //Light *light = (*it); + gl::enable(gl_light_id); + + gl_light_id++; + } +} + +void LightEnvironment::disable() +{ + int gl_light_id = env_base_id; + for (Container::iterator it = env_container.begin(); it != env_container.end(); ++it) { + //Light *light = (*it); + gl::disable(gl_light_id); + gl_light_id++; + } +} + +void LightEnvironment::draw(const math::Vector3f translate) +{ + GLfloat gl_light_location[4]; + GLfloat gl_ambient_light[4]; + GLfloat gl_diffuse_light[4]; + GLfloat gl_specular_light[4]; + + int gl_light_id = env_base_id; + + for (Container::iterator it = env_container.begin(); it != env_container.end(); ++it) { + Light *light = (*it); + + for (size_t i = 0; i < 3; i++) { + gl_light_location[i] = light->location()[i]; + gl_ambient_light[i] = light->color()[i] * env_ambient_intensity; + gl_diffuse_light[i] = light->color()[i] * env_diffuse_intensity; + gl_specular_light[i] = light->color()[i] * env_specular_intensity; + } + + gl_light_location[3] = 1.0f; + gl_ambient_light[3] = 1.0f; + gl_diffuse_light[3] = 1.0f; + gl_specular_light[3] = 1.0f; + + glLightfv(gl_light_id, GL_POSITION, gl_light_location); + glLightfv(gl_light_id, GL_AMBIENT, gl_ambient_light); + glLightfv(gl_light_id, GL_DIFFUSE, gl_diffuse_light); + glLightfv(gl_light_id, GL_SPECULAR, gl_specular_light); + + // attenuation + glLightf(gl_light_id, GL_CONSTANT_ATTENUATION, light->attenuation()[0]); + glLightf(gl_light_id, GL_LINEAR_ATTENUATION, light->attenuation()[1]); + glLightf(gl_light_id, GL_QUADRATIC_ATTENUATION, light->attenuation()[2]); + + + gl_light_id++; + } +} + +void LightEnvironment::draw() +{ + draw(math::Vector3f()); +} + +} // namespace render |