Jump to content
  • Advertisement
Sign in to follow this  

Quake 2 Lightmapping Problem

This topic is 5067 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 );
	// 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 );

	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
GL_CLAMP would cause the same problem most probably, because it will cause sampling from the texture border. It's better to use GL_CLAMP_TO_EDGE.

Share this post

Link to post
Share on other sites
Thanks mikeman!!!!

I really could not believe it's that easy!
After using GL_CLAMP_TO_EDGE, the lightmap looks good now!

Thanks again!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!