Tutorial *76*

This is a tutorial on how to fix the negative lighting bug which happens on some cards, after applying the colored lighting tutorial to your engine/source. Thanks to Ender it's fixed now.

Open up gl_rsurf.c and replace the r_blendlightmaps with this function, new parts are in blue.



/*

================

R_BlendLightmaps

================

*/

void R_BlendLightmaps (void)

{

	int			i, j;

	glpoly_t	*p;

	float		*v;

	glRect_t	*theRect;



	if (r_fullbright.value)

		return;

	if (!gl_texsort.value)

		return;



	glDepthMask (0);		// don't bother writing Z



// Ender - Fix negative lighting... with negative lighting. Wee :)

        if (gl_lightmap_format == GL_INTENSITY) {

		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

		glColor4f (0,0,0,1);

		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        } else {

         glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_COLOR);

        }

// Ender - End



	if (!r_lightmap.value)

	{

		glEnable (GL_BLEND);

	}



	for (i=0 ; it,

				BLOCK_WIDTH, theRect->h, gl_lightmap_format, GL_UNSIGNED_BYTE,

				lightmaps+(i* BLOCK_HEIGHT + theRect->t) *BLOCK_WIDTH*lightmap_bytes);

			theRect->l = BLOCK_WIDTH;

			theRect->t = BLOCK_HEIGHT;

			theRect->h = 0;

			theRect->w = 0;

		}

		for ( ; p ; p=p->chain)

		{

			if (p->flags & SURF_UNDERWATER)

				DrawGLWaterPolyLightmap (p);

			else

			{

				glBegin (GL_POLYGON);

				v = p->verts[0];

				for (j=0 ; jnumverts ; j++, v+= VERTEXSIZE)

				{

					glTexCoord2f (v[5], v[6]);

					glVertex3fv (v);

				}

				glEnd ();

			}

		}

	}



	glDisable (GL_BLEND);



// Ender - Fix negative lighting... with negative lighting. Wee :)

        if (gl_lightmap_format == GL_INTENSITY)

	{

		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

		glColor4f (1,1,1,1);

        } else {

          glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        }

// Ender - End



	glDepthMask (1);		// back to normal Z buffering

}

now compile and run, just as usual.



 
Sign up
Login:
Passwd:
[Remember Me]