[Scummvm-cvs-logs] SF.net SVN: scummvm: [33066] residual/trunk/engine
aquadran at users.sourceforge.net
aquadran at users.sourceforge.net
Tue Jul 15 00:33:36 CEST 2008
Revision: 33066
http://scummvm.svn.sourceforge.net/scummvm/?rev=33066&view=rev
Author: aquadran
Date: 2008-07-14 15:33:36 -0700 (Mon, 14 Jul 2008)
Log Message:
-----------
first step to implement shadows for opengl renderer
Modified Paths:
--------------
residual/trunk/engine/actor.cpp
residual/trunk/engine/backend/sdl/driver_gl.cpp
residual/trunk/engine/backend/sdl/driver_tinygl.cpp
Modified: residual/trunk/engine/actor.cpp
===================================================================
--- residual/trunk/engine/actor.cpp 2008-07-14 22:10:04 UTC (rev 33065)
+++ residual/trunk/engine/actor.cpp 2008-07-14 22:33:36 UTC (rev 33066)
@@ -625,6 +625,16 @@
g_driver->setShadow(NULL);
g_driver->clearShadowMode();
}
+ } else {
+ for (int l = 0; l < 5; l++) {
+ if (!_shadowArray[l].active)
+ continue;
+ g_driver->setShadow(&_shadowArray[l]);
+ g_driver->startActorDraw(_pos, _yaw, _pitch, _roll);
+ costume->draw();
+ g_driver->finishActorDraw();
+ g_driver->setShadow(NULL);
+ }
}
// normal draw actor
Modified: residual/trunk/engine/backend/sdl/driver_gl.cpp
===================================================================
--- residual/trunk/engine/backend/sdl/driver_gl.cpp 2008-07-14 22:10:04 UTC (rev 33065)
+++ residual/trunk/engine/backend/sdl/driver_gl.cpp 2008-07-14 22:33:36 UTC (rev 33066)
@@ -105,7 +105,7 @@
}
void DriverGL::clearScreen() {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
void DriverGL::flipBuffer() {
@@ -116,10 +116,67 @@
return true;
}
+static void glShadowProjection(Vector3d light, Vector3d plane, Vector3d normal, bool dontNegate) {
+ // Based on GPL shadow projection example by
+ // (c) 2002-2003 Phaetos <phaetos at gaffga.de>
+ float d, c;
+ float mat[16];
+ float nx, ny, nz, lx, ly, lz, px, py, pz;
+
+ // for some unknown for me reason normal need negation
+ nx = -normal.x();
+ ny = -normal.y();
+ nz = -normal.z();
+ if (dontNegate) {
+ nx = -nx;
+ ny = -ny;
+ nz = -nz;
+ }
+ lx = light.x();
+ ly = light.y();
+ lz = light.z();
+ px = plane.x();
+ py = plane.y();
+ pz = plane.z();
+
+ d = nx * lx + ny * ly + nz * lz;
+ c = px * nx + py * ny + pz * nz - d;
+
+ mat[0] = lx * nx + c;
+ mat[4] = ny * lx;
+ mat[8] = nz * lx;
+ mat[12] = -lx * c - lx * d;
+
+ mat[1] = nx * ly;
+ mat[5] = ly * ny + c;
+ mat[9] = nz * ly;
+ mat[13] = -ly * c - ly * d;
+
+ mat[2] = nx * lz;
+ mat[6] = ny * lz;
+ mat[10] = lz * nz + c;
+ mat[14] = -lz * c - lz * d;
+
+ mat[3] = nx;
+ mat[7] = ny;
+ mat[11] = nz;
+ mat[15] = -d;
+
+ glMultMatrixf(mat);
+}
+
void DriverGL::startActorDraw(Vector3d pos, float yaw, float pitch, float roll) {
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
+ if (_currentShadowArray) {
+ SectorListType::iterator i = _currentShadowArray->planeList.begin();
+ Sector *shadowSector = *i;
+ glEnable(GL_POLYGON_OFFSET_FILL);
+ glDisable(GL_LIGHTING);
+ glColor3i(_shadowColorR, _shadowColorG, _shadowColorB);
+ glShadowProjection(_currentShadowArray->pos, shadowSector->getVertices()[0], shadowSector->getNormal(), _currentShadowArray->dontNegate);
+ }
glTranslatef(pos.x(), pos.y(), pos.z());
glRotatef(yaw, 0, 0, 1);
glRotatef(pitch, 1, 0, 0);
@@ -127,11 +184,16 @@
}
void DriverGL::finishActorDraw() {
+ if (_currentShadowArray) {
+ glEnable(GL_LIGHTING);
+ glDisable(GL_POLYGON_OFFSET_FILL);
+ }
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
void DriverGL::setShadow(Shadow *shadow) {
+ _currentShadowArray = shadow;
}
void DriverGL::drawShadowPlanes() {
@@ -144,6 +206,9 @@
}
void DriverGL::setShadowColor(byte r, byte g, byte b) {
+ _shadowColorR = r;
+ _shadowColorG = g;
+ _shadowColorB = b;
}
void DriverGL::set3DMode() {
Modified: residual/trunk/engine/backend/sdl/driver_tinygl.cpp
===================================================================
--- residual/trunk/engine/backend/sdl/driver_tinygl.cpp 2008-07-14 22:10:04 UTC (rev 33065)
+++ residual/trunk/engine/backend/sdl/driver_tinygl.cpp 2008-07-14 22:33:36 UTC (rev 33066)
@@ -185,7 +185,7 @@
return false;
}
-void tglShadowProjection(Vector3d light, Vector3d plane, Vector3d normal, bool dontNegate) {
+static void tglShadowProjection(Vector3d light, Vector3d plane, Vector3d normal, bool dontNegate) {
// Based on GPL shadow projection example by
// (c) 2002-2003 Phaetos <phaetos at gaffga.de>
float d, c;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list