Skip to main content
gamedev.net
🔒 Locked

Multi texturing isn't working

Started by Etus 1 reply 200+ views
Original Post
Etus
Etus
Hi, I''ve been searching for a long time for a bug in my program. I''m trying to render a terrain using a regular texture map and a detail map. Though it worked before, after I moved to vertex arrays it stopped working. I narrowed the problem and it seems that the textures aren''t blended together. Here''s my rendering code:
  
void HeightMapTerrain :: RenderHeightMap() {

	if(!pHeightMap) return;	

	int currentMultiTex = pTextureManager->GetMultiTexture();

	if(multiTexture == true) {
		
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);	    
		
		for(int i=0; i < NumOfTextures; i++) {
			
			glClientActiveTextureARB(GL_TEXTURE0_ARB + i + (currentMultiTex - NumOfTextures));
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, pTextureManager->g_Texture[TexturesRef[i]]);
			glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
			
			if(i != 0) {
				
				glMatrixMode(GL_TEXTURE);
				
				glPushMatrix();

				glLoadIdentity();
				glScalef((float)g_DetailScale, (float)g_DetailScale, 1.0f);
				
			}			
			
		}
		
		glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);

	}
	else {

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, pTextureManager->g_Texture[TexturesRef[0]]);

	}

	glMatrixMode(GL_MODELVIEW);

	glVertexPointer(3, GL_FLOAT, sizeof(CVector3), &terrainVertices[0].x);
	glNormalPointer(GL_FLOAT, 0, &vertex_normals[0].x);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);	

	if(multiTexture == true) {	

		for(int i=0; i < NumOfTextures; i++) {

			glClientActiveTextureARB(GL_TEXTURE0_ARB + i + (currentMultiTex - NumOfTextures));
			glTexCoordPointer(2, GL_FLOAT, sizeof(CVector2), &terrainTextureCoords[0].x);
			glEnableClientState(GL_TEXTURE_COORD_ARRAY);	        

		}

	}
	
	glDrawElements(GL_TRIANGLES, NumOfIndices, GL_UNSIGNED_SHORT, &Indices[0].x);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);	
	
	if(multiTexture == true) {

		for(int i = NumOfTextures - 1; i >= 0; i--) {	
			
			glClientActiveTextureARB(GL_TEXTURE0_ARB + i + (currentMultiTex - NumOfTextures));

			if(i == NumOfTextures - 1) {				    

				glMatrixMode(GL_TEXTURE);				
			    glPopMatrix();

			}

			glDisable(GL_TEXTURE_2D);
			glDisableClientState(GL_TEXTURE_COORD_ARRAY);
			
		}

	}

	glMatrixMode(GL_MODELVIEW);

}
  
What am I doing wrong? Thanks, Yuval
Brother Bob
Brother Bob
You''re calling glClientActiveTexture before glBindTexture. Sure you don''t want to call glActiveTexture instead? glBindTexture binds the texture to the, on the server side, active texture unit, so selecting the client side texture unit is not what you want to do.
Etus
Etus
It doesn''t matter - even if I do what you said it''s still not working.

- Yuval

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.