Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Goers <mega@osirion.org>2012-03-21 11:57:11 +0000
committerEvan Goers <mega@osirion.org>2012-03-21 11:57:11 +0000
commit980b47266c5fba9a7e7fabfa7a6d77167a47cb60 (patch)
tree40a165fbf3e5c7daacea51de887f01301b823145 /src/render/draw.cc
parentc4cd091c43ade80033f41c1ceda5c9f51979dcbc (diff)
Functionize light creation.
Diffstat (limited to 'src/render/draw.cc')
-rw-r--r--src/render/draw.cc84
1 files changed, 52 insertions, 32 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 2efa411..3b7acad 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -46,14 +46,15 @@ math::Vector3f v6(-1, 1, -1);
math::Vector3f v7(-1, -1, -1);
core::Zone *zone = 0;
-float zone_light[4]; // locaton of the zone light
+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
bool has_zone_light = false;
bool draw_particles = true;
bool draw_lights = true;
+size_t max_lights = 8;
-GLenum zone_gllight = GL_LIGHT0 + 6; //FIXME super magic number bros
+GLenum zone_gllight = GL_LIGHT0;
typedef std::map<float, core::EntityGlobe *> Globes;
Globes globes_list;
@@ -63,10 +64,56 @@ Globes globes_list;
void pass_reset_lights()
{
// reset light state
- for (size_t i = 0; i < 8; i++)
+ for (size_t i = 0; i < max_lights; i++)
gl::disable(GL_LIGHT0 + i);
}
+// Lights
+int create_light(float* location, float attenuation, math::Color color)
+{
+ int gllight;
+
+ // check if a light is available
+ for (size_t i = 0; i < max_lights; i++) {
+ if (!glIsEnabled(GL_LIGHT0 + i)) {
+ gllight = GL_LIGHT0 + i;
+ break;
+ }
+ else {
+ gllight = GL_LIGHT0;
+ return gllight;
+ }
+ }
+
+ // set up color and location
+ GLfloat gllight_location[4];
+ GLfloat diffuse_light[4];
+ GLfloat ambient_light[4];
+ GLfloat specular_light[4];
+
+ for (size_t i = 0; i < 3; i++) {
+ gllight_location[i] = location[i];
+ ambient_light[i] = color[i] * 0.1;
+ diffuse_light[i] = color[i] * 0.75;
+ specular_light[i] = color[i] * 0.75;
+ }
+ gllight_location[3] = 1.0f;
+ ambient_light[3] = 1.0f;
+ diffuse_light[3] = 1.0f;
+ specular_light[3] = 1.0f;
+
+ // set up the light
+ // we use a simple averaging of the color times the specified attenuation value(such as 0.00025f).
+ // FIXME: use a more standardized and realistic way of doing this.
+ glLightf(gllight, GL_LINEAR_ATTENUATION, ((color[0] + color[1] + color[2]) / 3.0f) * attenuation);
+
+ glLightfv(gllight, GL_POSITION, gllight_location);
+ glLightfv(gllight, GL_AMBIENT, ambient_light);
+ glLightfv(gllight, GL_DIFFUSE, diffuse_light);
+ glLightfv(gllight, GL_SPECULAR, specular_light);
+ return gllight;
+}
+
void pass_prepare(float seconds)
{
using namespace model;
@@ -116,41 +163,14 @@ void pass_prepare(float seconds)
}
// add level lights
+
if (globe->flag_is_set(core::Entity::Bright)) {
- for (size_t i = 0; i < 8; i++) {
- // check if a light is available
- if (!glIsEnabled(GL_LIGHT0 + i)) {
- zone_gllight = GL_LIGHT0 + i;
- break;
- }
- }
-
- // bright globes set level light
- GLfloat diffuse_light[4];
- GLfloat ambient_light[4];
- GLfloat specular_light[4];
-
for (size_t i = 0; i < 3; i++) {
zone_light[i] = globe->location()[i];
zone_color[i] = globe->color()[i];
- ambient_light[i] = globe->color()[i] * 0.1;
- diffuse_light[i] = globe->color()[i] * 0.75;
- specular_light[i] = globe->color()[i] * 0.75;
}
- zone_light[3] = 1.0f;
- ambient_light[3] = 1.0f;
- diffuse_light[3] = 1.0f;
- specular_light[3] = 1.0f;
-
- glLightf(zone_gllight, GL_LINEAR_ATTENUATION, ((globe->color()[0] + globe->color()[1] + globe->color()[2]) / 3.0f) * 0.00025f);
-
- glLightfv(zone_gllight, GL_POSITION, zone_light);
- glLightfv(zone_gllight, GL_AMBIENT, ambient_light);
- glLightfv(zone_gllight, GL_DIFFUSE, diffuse_light);
- glLightfv(zone_gllight, GL_SPECULAR, specular_light);
-
+ GLenum zone_gllight = create_light(zone_light, 0.00025f, globe->color());
gl::enable(zone_gllight);
-
has_zone_light = true;
}