Sign in to follow this  
CodeZero

Texturing terrain using alpha maps

Recommended Posts

CodeZero    138
So I have a chunk of terrain I want to render with an alpha map pre-generated for each texture on that chunk. I'm trying to fiddle around with blending to get it all to render now, but I can't seem to get the calls right. Do I make 2 separate rendering passes, one drawing the alpha map and the other drawing the texture on top? My background right now is grey (the same color as my fog) so I get my texture showing up faintly in areas it isn't supposed to. Can anybody help? This is clunky test code, but it shows what I'm getting at, hopefully:
glEnable(GL_BLEND);
for (int j = 0; j < terrain->textureNum; j++) {
	glBlendFunc(GL_DST_COLOR, GL_ZERO);
	glInterleavedArrays(GL_T2F_N3F_V3F, 0, terrain->alphaVertices);
	glBindTexture(GL_TEXTURE_2D, textureManager->textures[terrain->terrainChunks[i]->alphaIndices[j]]);
	glDrawElements(GL_TRIANGLES, terrain->mipMaps[i]->triangleVertexNum, GL_UNSIGNED_INT, terrain->mipMaps[i]->triangleIndices);

	glBlendFunc(GL_ONE, GL_ONE);
	glInterleavedArrays(GL_T2F_N3F_V3F, 0, terrain->vertices);
	glBindTexture(GL_TEXTURE_2D, textureManager->textures[terrain->textureIndices[j]]);
	glDrawElements(GL_TRIANGLES, terrain->mipMaps[i]->triangleVertexNum, GL_UNSIGNED_INT, terrain->mipMaps[i]->triangleIndices);
} // for j
glDisable(GL_BLEND);

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