Jump to content
  • Advertisement
Sign in to follow this  

Texturing terrain using alpha maps

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

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:
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->alphaIndices[j]]);
	glDrawElements(GL_TRIANGLES, terrain->mipMaps->triangleVertexNum, GL_UNSIGNED_INT, terrain->mipMaps->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->triangleVertexNum, GL_UNSIGNED_INT, terrain->mipMaps->triangleIndices);
} // for j

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.

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

Sign me up!