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
parent5d4e993e485ae3432eabb45caf4e4d43c9bc54e6 (diff)
Renderer now checks and enables lights based on availability instead of using arbitrary GL_LIGHT#s.
-rw-r--r--src/render/draw.cc29
-rwxr-xr-xsrc/ui/modelview.cc29
2 files changed, 38 insertions, 20 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);
}
}
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index 65954d8..c36aa56 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -19,6 +19,8 @@
namespace ui
{
+GLenum modelview_gllight = GL_LIGHT0 + 7;
+
ModelView::ModelView(Widget *parent, const char *modelname) : Widget(parent)
{
set_border(false);
@@ -185,28 +187,33 @@ void ModelView::draw()
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
-
-
+
// we set up the light in camera space
+ for (size_t i = 0; i < (GL_LIGHT0 + 7); i++) {
+ // check if a light is available
+ if (!glIsEnabled(GL_LIGHT0 + i)) {
+ modelview_gllight = GL_LIGHT0 + i;
+ break;
+ }
+ }
+
GLfloat modelview_light[] = { -10.0f * model->radius(), 0, 0, 1.0f };
GLfloat ambient_light[] = { 0.1f, 0.1f, 0.1f, 1.0f };
GLfloat diffuse_light[] = { 0.75f, 0.75f, 0.75f, 1.0f };
GLfloat specular_light[] = { 0.75f, 0.75f, 0.75f, 1.0f };
- glLightfv(GL_LIGHT1, GL_POSITION, modelview_light);
- glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
- glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
- glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light);
+ glLightfv(modelview_gllight, GL_POSITION, modelview_light);
+ glLightfv(modelview_gllight, GL_AMBIENT, ambient_light);
+ glLightfv(modelview_gllight, GL_DIFFUSE, diffuse_light);
+ glLightfv(modelview_gllight, GL_SPECULAR, specular_light);
- glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.75f);
+ glLightf(modelview_gllight, GL_LINEAR_ATTENUATION, 0.05f);
- gl::enable(GL_LIGHT1);
+ gl::enable(modelview_gllight);
// push transformation matrix to stack
gl::push();
-
-
gl::multmatrix(modelview_axis);
gl::scale(modelscale, modelscale, modelscale);
@@ -226,7 +233,7 @@ void ModelView::draw()
gl::pop();
- gl::disable(GL_LIGHT1);
+ gl::disable(modelview_gllight);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);