Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multitexturing with Tiled Textures

Started by The Bag Apr 25, 2004 at 5:09 PM 0 replies 900+ views
Original Post
The Bag
The Bag
I working on a small terrain demo which uses tiled textures. Currently I'm doing 3 passes over the terrain using blending. A base texture, then two textures blended on top. Since the textures are tiled the alpha values for the blending are not part of the texture or an alphamap, but kept at each vertex. That is the alpha information for each texture is stored at each individual vertex. As I mentioned at the moment I doing three passes over the terrain to texture. In addition to this I'm doing one pass for the water - I've also now added stencil relfections, so I'm up to 8 passes per frame. My question is, is there a way to blend the textures as described (an alpha value stored at each vertex) using multitexturing. My current terrain rendering step (with its 3 passes):
	glEnable(GL_BLEND);

	glBindTexture(GL_TEXTURE_2D, texture[texFilter]);
	glBlendFunc(GL_ONE, GL_ZERO);
	glBegin(GL_QUADS);
	z= TERR_DEPTH-1;
	while (z-- > 0)
	{
		x= TERR_WIDTH-1;
		while (x-- > 0)
		{
			glColor4f(1.0f, 1.0f , 1.0f, 0.0f);

			glTexCoord2f(0.0f, 0.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x][z]));
			glVertex3f(x, pTB->h.s[x][z], z);

			glTexCoord2f(0.0f, 1.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x][z+1]));
			glVertex3f(x, pTB->h.s[x][z+1], z+1);

			glTexCoord2f(1.0f, 1.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x+1][z+1]));
			glVertex3f(x+1, pTB->h.s[x+1][z+1], z+1);

			glTexCoord2f(1.0f, 0.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x+1][z]));
			glVertex3f(x+1, pTB->h.s[x+1][z], z);
			
				
		}
	}
glEnd();

	glEnable(GL_ALPHA_TEST);

	glDepthFunc(GL_LEQUAL);

	glBindTexture(GL_TEXTURE_2D, texture[rockTex]);
	glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
	
	glBegin(GL_QUADS);

	z= TERR_DEPTH-1;
	while (z-- > 0)
	{
		x= TERR_WIDTH-1;
		while (x-- > 0)
		{
			
			glColor4f(1.0f, 1.0f , 1.0f, rockMap[x][z]);
			glTexCoord2f(0.0f, 0.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x][z]));
			glVertex3f(x, pTB->h.s[x][z], z);

			glColor4f(1.0f, 1.0f , 1.0f, rockMap[x][z+1]);
			glTexCoord2f(0.0f, 1.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x][z+1]));
			glVertex3f(x, pTB->h.s[x][z+1], z+1);

			glColor4f(1.0f, 1.0f , 1.0f, rockMap[x+1][z+1]);
			glTexCoord2f(1.0f, 1.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x+1][z+1]));
			glVertex3f(x+1, pTB->h.s[x+1][z+1], z+1);

			glColor4f(1.0f, 1.0f , 1.0f, rockMap[x+1][z]);
			glTexCoord2f(1.0f, 0.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x+1][z]));
			glVertex3f(x+1, pTB->h.s[x+1][z], z);
		}
	}
	glEnd();


	glBindTexture(GL_TEXTURE_2D, texture[sandTex]);
	glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
	
	glBegin(GL_QUADS);

	z= TERR_DEPTH-1;
	while (z-- > 0)
	{
		x= TERR_WIDTH-1;
		while (x-- > 0)
		{
			
			glColor4f(1.0f, 1.0f , 1.0f, sandMap[x][z]);
			glTexCoord2f(0.0f, 0.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x][z]));
			glVertex3f(x, pTB->h.s[x][z], z);

			glColor4f(1.0f, 1.0f , 1.0f, sandMap[x][z+1]);
			glTexCoord2f(0.0f, 1.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x][z+1]));
			glVertex3f(x, pTB->h.s[x][z+1], z+1);

			glColor4f(1.0f, 1.0f , 1.0f, sandMap[x+1][z+1]);
			glTexCoord2f(1.0f, 1.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x+1][z+1]));
			glVertex3f(x+1, pTB->h.s[x+1][z+1], z+1);

			glColor4f(1.0f, 1.0f , 1.0f, sandMap[x+1][z]);
			glTexCoord2f(1.0f, 0.0f);
			glNormal3fv((GLfloat*)&(pTB->n[x+1][z]));
			glVertex3f(x+1, pTB->h.s[x+1][z], z);
		}
	}
	glEnd(); 
[edited by - The Bag on April 25, 2004 6:10:28 PM]
The Bag
The Bag
Anyone? Even if the answer is "no, that''s impossible wtf were you thinking"

Topic Locked

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

Sign in to reply to this topic.