summaryrefslogtreecommitdiffstats
path: root/src/graphics/opengl/gldevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics/opengl/gldevice.cpp')
-rw-r--r--src/graphics/opengl/gldevice.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index bbad0a7..bffbc3a 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -117,9 +117,6 @@ bool CGLDevice::Create()
// So turn it on permanently
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- // To use separate specular color in drawing primitives
- glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
-
// To avoid problems with scaling & lighting
glEnable(GL_RESCALE_NORMAL);
@@ -136,13 +133,13 @@ bool CGLDevice::Create()
glGetIntegerv(GL_MAX_LIGHTS, &numLights);
m_lights = std::vector<Light>(numLights, Light());
- m_lightsEnabled = std::vector<bool> (numLights, false);
+ m_lightsEnabled = std::vector<bool> (numLights, false);
int maxTextures = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextures);
m_currentTextures = std::vector<Texture> (maxTextures, Texture());
- m_texturesEnabled = std::vector<bool> (maxTextures, false);
+ m_texturesEnabled = std::vector<bool> (maxTextures, false);
m_textureStageParams = std::vector<TextureStageParams>(maxTextures, TextureStageParams());
GetLogger()->Info("CDevice created successfully\n");
@@ -326,33 +323,39 @@ void CGLDevice::UpdateLightPosition(int index)
assert(index >= 0);
assert(index < static_cast<int>( m_lights.size() ));
- if ((! m_lighting) || (! m_lightsEnabled[index]))
- return;
-
glMatrixMode(GL_MODELVIEW);
+
glPushMatrix();
glLoadIdentity();
glScalef(1.0f, 1.0f, -1.0f);
- glMultMatrixf(m_viewMat.Array());
+ Math::Matrix mat = m_viewMat;
+ mat.Set(1, 4, 0.0f);
+ mat.Set(2, 4, 0.0f);
+ mat.Set(3, 4, 0.0f);
+ glMultMatrixf(mat.Array());
+
+ if (m_lights[index].type == LIGHT_SPOT)
+ {
+ GLfloat direction[4] = { -m_lights[index].direction.x, -m_lights[index].direction.y, -m_lights[index].direction.z, 1.0f };
+ glLightfv(GL_LIGHT0 + index, GL_SPOT_DIRECTION, direction);
+ }
if (m_lights[index].type == LIGHT_DIRECTIONAL)
{
- GLfloat position[4] = { m_lights[index].direction.x, m_lights[index].direction.y, m_lights[index].direction.z, 0.0f };
+ GLfloat position[4] = { -m_lights[index].direction.x, -m_lights[index].direction.y, -m_lights[index].direction.z, 0.0f };
glLightfv(GL_LIGHT0 + index, GL_POSITION, position);
}
else
{
+ glLoadIdentity();
+ glScalef(1.0f, 1.0f, -1.0f);
+ glMultMatrixf(m_viewMat.Array());
+
GLfloat position[4] = { m_lights[index].position.x, m_lights[index].position.y, m_lights[index].position.z, 1.0f };
glLightfv(GL_LIGHT0 + index, GL_POSITION, position);
}
- if (m_lights[index].type == LIGHT_SPOT)
- {
- GLfloat direction[4] = { m_lights[index].direction.x, m_lights[index].direction.y, m_lights[index].direction.z, 0.0f };
- glLightfv(GL_LIGHT0 + index, GL_SPOT_DIRECTION, direction);
- }
-
glPopMatrix();
}
@@ -371,7 +374,10 @@ void CGLDevice::SetLightEnabled(int index, bool enabled)
m_lightsEnabled[index] = enabled;
- glEnable(GL_LIGHT0 + index);
+ if (enabled)
+ glEnable(GL_LIGHT0 + index);
+ else
+ glDisable(GL_LIGHT0 + index);
}
bool CGLDevice::GetLightEnabled(int index)