Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

StormbringerCSP

Dynamic lighting in multitexturing environment

This topic is 5566 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

I've got a problem with a multitexture renderer using dynamic lighting: Only the first texture is being lit, all the others are not. Here's the rendering code:
    
	// dynamic lighting

	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_diffuse);

	glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
	glLightfv(GL_LIGHT0, GL_AMBIENT, col_ambient);
	
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	
	glEnable(GL_LIGHTING);
	glEnable(GL_COLOR_MATERIAL);
	glLightfv(GL_LIGHT0, GL_POSITION, m_pTerrainData->m_faLightPos);
	glEnable(GL_RESCALE_NORMAL);

	glNormalPointer(GL_FLOAT, 0, m_pTerrainData->m_paNormals);
	glVertexPointer(3, GL_FLOAT, 0, m_pTerrainData->m_paVertices);

	if(m_pTerrainData->m_bEcosystemMode == ECOSYSTEM_MODE_SHARP)
		glColorPointer(4, GL_FLOAT, 0, pcColArraySharp);
	else
		glColorPointer(4, GL_FLOAT, 0, pcColArraySmooth);
	
	// Pass 1: LERP(C0.RGB, T1, T2)

	// the amount of coverage of tex1 and tex2 is stored as the RGB

	// value in the vertex color array (R == G == B == coverage)

	// texture0 and texture1 are blended in this pass

	glDisable(GL_BLEND);

	// texture 1

	glActiveTextureARB(GL_TEXTURE1_ARB);
	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glTexCoordPointer(2, GL_FLOAT, 0, m_pTerrainData->m_paTextureCoords);	

	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, pTextures[1].iGLTexHandle);

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);

	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);

	// texture 0 

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glClientActiveTextureARB(GL_TEXTURE0_ARB);
	glTexCoordPointer(2, GL_FLOAT, 0, m_pTerrainData->m_paTextureCoords);
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, pTextures[0].iGLTexHandle);
	
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	for(y=0; y<m_pTerrainData->m_iMeshWidth-1;y++)
	{
		// the triangle strip to draw the terrain mesh

		glBegin(GL_TRIANGLE_STRIP);
		for(x=0; x<m_pTerrainData->m_iMeshWidth-1; x++)
		{
			glArrayElement(y*m_pTerrainData->m_iMeshWidth+x);
			glArrayElement((y+1)*m_pTerrainData->m_iMeshWidth+x);
			vertcount += 2;
		}
		tricount += m_pTerrainData->m_iMeshWidth*2;
		glEnd();
	}

	// Pass 2: LERP(C0.A, T3, FB)

	// texture3 blended with the result of the previous rendering pass

	// blending map is stored as alpha in the vertex color array



	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glActiveTextureARB(GL_TEXTURE1_ARB);
	glDisable(GL_TEXTURE_2D);

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glBindTexture(GL_TEXTURE_2D, pTextures[2].iGLTexHandle);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);

	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_ONE_MINUS_SRC_ALPHA);

	
	for(y=0; y<m_pTerrainData->m_iMeshWidth-1;y++)
	{
		// the triangle strip to draw the terrain mesh

		glBegin(GL_TRIANGLE_STRIP);
		for(x=0; x<m_pTerrainData->m_iMeshWidth-1; x++)
		{
			glArrayElement(y*m_pTerrainData->m_iMeshWidth+x);
			glArrayElement((y+1)*m_pTerrainData->m_iMeshWidth+x);
			vertcount += 2;
		}
		tricount += m_pTerrainData->m_iMeshWidth*2;
		glEnd();
	}
    
Thanx for your help! Regards, Stormbringer [edited by - StormbringerCSP on March 30, 2003 1:04:45 PM]

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!