[Scummvm-cvs-logs] SF.net SVN: scummvm:[33100] residual/trunk/engine/backend/sdl

aquadran at users.sourceforge.net aquadran at users.sourceforge.net
Fri Jul 18 22:43:47 CEST 2008


Revision: 33100
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33100&view=rev
Author:   aquadran
Date:     2008-07-18 20:43:47 +0000 (Fri, 18 Jul 2008)

Log Message:
-----------
implemented shadows for opengl renderer

Modified Paths:
--------------
    residual/trunk/engine/backend/sdl/driver_gl.cpp
    residual/trunk/engine/backend/sdl/driver_tinygl.cpp

Modified: residual/trunk/engine/backend/sdl/driver_gl.cpp
===================================================================
--- residual/trunk/engine/backend/sdl/driver_gl.cpp	2008-07-18 20:40:48 UTC (rev 33099)
+++ residual/trunk/engine/backend/sdl/driver_gl.cpp	2008-07-18 20:43:47 UTC (rev 33100)
@@ -50,6 +50,9 @@
 	_screenHeight = screenH;
 	_screenBPP = screenBPP;
 	_isFullscreen = fullscreen;
+	int depth;
+	SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth);
+	warning("ZBuffer Depth bits: %d", depth);
 
 	sprintf(GLDriver, "Residual: %s/%s", glGetString(GL_VENDOR), glGetString(GL_RENDERER));
 	SDL_WM_SetCaption(GLDriver, "Residual");
@@ -61,7 +64,9 @@
 	memset(_storedDisplay, 0, _screenWidth * _screenHeight * 4);
 	_smushNumTex = 0;
 
-	_currentShadowArray = 0;
+	_currentShadowArray = NULL;
+
+	glPolygonOffset(-6.0, -6.0);
 }
 
 DriverGL::~DriverGL() {
@@ -107,7 +112,7 @@
 }
 
 void DriverGL::clearScreen() {
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 }
 
 void DriverGL::flipBuffer() {
@@ -164,7 +169,7 @@
 	mat[11] = nz;
 	mat[15] = -d;
 
-	glMultMatrixf(mat);
+	glMultMatrixf((GLfloat *)mat);
 }
 
 void DriverGL::startActorDraw(Vector3d pos, float yaw, float pitch, float roll) {
@@ -177,6 +182,7 @@
 		glEnable(GL_POLYGON_OFFSET_FILL);
 		glDisable(GL_LIGHTING);
 		glDisable(GL_TEXTURE_2D);
+		//glColor3f(0.0f, 1.0f, 0.0f);
 		glColor3f(_shadowColorR / 255.0, _shadowColorG / 255.0, _shadowColorB / 255.0);
 		glShadowProjection(_currentShadowArray->pos, shadowSector->getVertices()[0], shadowSector->getNormal(), _currentShadowArray->dontNegate);
 	}
@@ -187,13 +193,13 @@
 }
 
 void DriverGL::finishActorDraw() {
+	glPopMatrix();
+	glDisable(GL_TEXTURE_2D);
 	if (_currentShadowArray) {
 		glEnable(GL_LIGHTING);
+		glColor3f(1.0, 1.0, 1.0);
 		glDisable(GL_POLYGON_OFFSET_FILL);
-		glColor3f(1.0, 1.0, 1.0);
 	}
-	glPopMatrix();
-	glDisable(GL_TEXTURE_2D);
 }
 
 void DriverGL::setShadow(Shadow *shadow) {
@@ -201,12 +207,46 @@
 }
 
 void DriverGL::drawShadowPlanes() {
+/*	glColor3f(1.0f, 1.0f, 1.0f);
+	_currentShadowArray->planeList.begin();
+	for (SectorListType::iterator i = _currentShadowArray->planeList.begin(); i != _currentShadowArray->planeList.end(); i++) {
+		Sector *shadowSector = *i;
+		glBegin(GL_POLYGON);
+		for (int k = 0; k < shadowSector->getNumVertices(); k++) {
+			glVertex3f(shadowSector->getVertices()[k].x(), shadowSector->getVertices()[k].y(), shadowSector->getVertices()[k].z());
+		}
+		glEnd();
+	}
+*/
+	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+	glClearStencil(1);
+	glClear(GL_STENCIL_BUFFER_BIT);
+
+	glEnable(GL_STENCIL_TEST);
+	glStencilFunc(GL_ALWAYS, 1, 1);
+	glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
+	glDisable(GL_LIGHTING);
+	glDisable(GL_TEXTURE);
+	_currentShadowArray->planeList.begin();
+	for (SectorListType::iterator i = _currentShadowArray->planeList.begin(); i != _currentShadowArray->planeList.end(); i++) {
+		Sector *shadowSector = *i;
+		glBegin(GL_POLYGON);
+		for (int k = 0; k < shadowSector->getNumVertices(); k++) {
+			glVertex3f(shadowSector->getVertices()[k].x(), shadowSector->getVertices()[k].y(), shadowSector->getVertices()[k].z());
+		}
+		glEnd();
+	}
+	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+	glStencilFunc(GL_EQUAL, 1, 1);
+	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
 }
 
 void DriverGL::setShadowMode() {
 }
 
 void DriverGL::clearShadowMode() {
+	glDisable(GL_STENCIL_TEST);
 }
 
 void DriverGL::setShadowColor(byte r, byte g, byte b) {
@@ -430,7 +470,7 @@
 				uint16 *ptr1 = zbufPtr + y * bitmap->_width;
 				uint16 *ptr2 = zbufPtr + (bitmap->_height - 1 - y) * bitmap->_width;
 				for (int x = 0; x < bitmap->_width; x++, ptr1++, ptr2++) {
-					uint16 tmp = *ptr1;
+					uint32 tmp = *ptr1;
 					*ptr1 = *ptr2;
 					*ptr2 = tmp;
 				}

Modified: residual/trunk/engine/backend/sdl/driver_tinygl.cpp
===================================================================
--- residual/trunk/engine/backend/sdl/driver_tinygl.cpp	2008-07-18 20:40:48 UTC (rev 33099)
+++ residual/trunk/engine/backend/sdl/driver_tinygl.cpp	2008-07-18 20:43:47 UTC (rev 33100)
@@ -123,7 +123,7 @@
 	_storedDisplay = new byte[640 * 480 * 2];
 	memset(_storedDisplay, 0, 640 * 480 * 2);
 
-	_currentShadowArray = 0;
+	_currentShadowArray = NULL;
 }
 
 DriverTinyGL::~DriverTinyGL() {
@@ -242,6 +242,7 @@
 	tglPushMatrix();
 	if (_currentShadowArray) {
 		assert(_currentShadowArray->shadowMask);
+		//tglSetShadowColor(255, 255, 255);
 		tglSetShadowColor(_shadowColorR, _shadowColorG, _shadowColorB);
 		tglSetShadowMaskBuf(_currentShadowArray->shadowMask);
 		SectorListType::iterator i = _currentShadowArray->planeList.begin();


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