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-01-24 08:13:28 +0000
committerEvan Goers <mega@osirion.org>2012-01-24 08:13:28 +0000
commit656c8b2fc03164d13352c067780037e87b98b9f2 (patch)
tree81b5b81c33b7d3a00fd5957438b404dcbfa7e7ec /src/render/draw.cc
parent5d4e993e485ae3432eabb45caf4e4d43c9bc54e6 (diff)
Renderer now checks and enables lights based on availability instead of using arbitrary GL_LIGHT#s.
Diffstat (limited to 'src/render/draw.cc')
-rw-r--r--src/render/draw.cc29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc
index ec4f386..5e3a3de 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -53,6 +53,8 @@ bool has_zone_light = false;
bool draw_particles = true;
bool draw_lights = true;
+GLenum zone_gllight = GL_LIGHT0 + 6; //FIXME super magic number bros
+
typedef std::map<float, core::EntityGlobe *> Globes;
Globes globes_list;
@@ -61,7 +63,8 @@ Globes globes_list;
void pass_reset_lights()
{
// reset light state
- gl::disable(GL_LIGHT0);
+ for (size_t i = 0; i < (GL_LIGHT0 + 7); i++)
+ gl::disable(GL_LIGHT0 + i);
}
void pass_prepare(float seconds)
@@ -114,6 +117,13 @@ void pass_prepare(float seconds)
// add level lights
if (globe->flag_is_set(core::Entity::Bright)) {
+ for (size_t i = 0; i < (GL_LIGHT0 + 7); 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];
@@ -132,14 +142,15 @@ void pass_prepare(float seconds)
diffuse_light[3] = 1.0f;
specular_light[3] = 1.0f;
- glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, ((globe->color()[0] + globe->color()[1] + globe->color()[2]) / 3.0f) * 0.00025f);
+ 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);
- glLightfv(GL_LIGHT0, GL_POSITION, zone_light);
- glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
- glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light);
+ gl::enable(zone_gllight);
- gl::enable(GL_LIGHT0);
has_zone_light = true;
}
@@ -280,7 +291,7 @@ void draw_globe(const core::EntityGlobe* globe)
fake_light[i] = zone_light[i] + location[i] - globe->location()[i];
}
fake_light[3] = 1.0f;
- glLightfv(GL_LIGHT0, GL_POSITION, fake_light);
+ glLightfv(zone_gllight, GL_POSITION, fake_light);
}
}
@@ -346,7 +357,7 @@ void draw_globe(const core::EntityGlobe* globe)
if (has_zone_light) {
// restore zone light
- glLightfv(GL_LIGHT0, GL_POSITION, zone_light);
+ glLightfv(zone_gllight, GL_POSITION, zone_light);
}
}