Sign in to follow this  
davf

Quake 2 Lightmapping Problem

Recommended Posts

Hi all, I am now working on a Quake 2 BSP map renderer on my own. I have been reading some tutorials as well as the quake 2 source (v3.21) as well. Right now I have got the BSP + PVS working but not the lightmapping. Comparing with the map in Quake 2, I can see that mine is almost done, but all the lightmaps look buttonized (bordered). Does anyone have idea on what may be wrong? My renderer: http://davdav.com:114/dav/lightmap-1.gif Wireframe: http://davdav.com:114/dav/lightmap-2.gif Map in Quake 2: http://davdav.com:114/dav/quake2.gif (Sorry for the low quality of GIF but I just want to save bandwidth) Here is how I calculate the width and height of the heightmap of a face (polygon)
	// this formula is copied from the flipcode Quake 2 BSP tutorial
	float w = ceil( u_max / 16 ) - floor( u_min / 16 ) + 1;
	float h = ceil( v_max / 16 ) - floor( v_min / 16 ) + 1;

Here is how I create the lightmap
	GLuint nLightmap;
	glGenTextures( 1, &nLightmap );
	glBindTexture( GL_TEXTURE_2D, nLightmap );
	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
	// m_pLightmapLump stores the complete lightmap here
	// and light_offset stores the offset value of the current face
	glTexImage2D( GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, m_pLightmapLump+pLump->light_offset );
	glBindTexture( GL_TEXTURE_2D, 0 );

Here is how I render the face with multi-texturing
	glActiveTextureARB( GL_TEXTURE0_ARB );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, m_poglTexture[m_pnTextureID[pLump->tex_info]].GetID() );
	glActiveTextureARB( GL_TEXTURE1_ARB );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, nLightmap );

	glBegin( GL_POLYGON );
	glColor3f( 1, 1, 1 );

	for ( every vertex )
	{
		vector3f vt; // current vertex (float [3])
		float uv[2]; // texture coordinate
		float st[2]; // lightmap coordinate

		/*
		 * st calculated using flipcode Quake 2 BSP tutorial's formula
		 */		

		uv[0] = st[0] / ( texture width );
		uv[1] = st[1] / ( texture height );

		glMultiTexCoord2fvARB( GL_TEXTURE0_ARB, uv );
		glMultiTexCoord2fARB( GL_TEXTURE1_ARB, ( st[0]-u_min )/(u_max - u_min), ( st[1]-v_min )/(v_max - v_min) );
		glVertex3fv( vt );
	}

	glEnd();
	glBindTexture( GL_TEXTURE_2D, 0 );
	glActiveTextureARB( GL_TEXTURE0_ARB );
	glBindTexture( GL_TEXTURE_2D, 0 );

Any comment/idea is welcome. Thank you in advance!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this