Jump to content
  • Advertisement
Sign in to follow this  
harph

OpenGL Terrain multitexturing

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

hi :] I'm creating a 3D "engine" in OpenGL that's based on data from an existing game (KalOnline but that doesn't matter). I have encountered problems with adding multitextures, so I'll first explain what I have: I have 3 types of 'maps': 1. terrain map 257x257 2B - elevations, generates the terrain itself (no problems here) 2. color map 256x256 3B (RGB) - colors the vertices as I'm rendering the terrain 3. texture map 256x256 1B - here I have a problem. A single map sector contains the terrain map, the color map and 1-7 of these texture maps. This is probably used for adding more textures to 1 cell of the terrain. What is my problem: I looked in numerous tutorials and couldn't find how can you create a unique mixture of texures for every "cell" of the terrain... Because some places have grass+rocks, other places have only dirt, etc etc. I can only manage to bind multitextures outside of the rendering procedure (outside the for cycle)... so I would like to do something like this:
for (int y = 0; y < 256; y++ )						
	for (int x = 0; x < 256; x++)
	{		
          	// here I want to set up the 1-7 textures for multitexturing, based on the data from the texture maps (I believe the value is alpha)... but if I try it, it just doesn't work (only the last texture gets binded and only like a normal texture		
		for (int i = 0; i < map->texturesNum; i++)
		{					
                        glActiveTextureARB(GL_TEXTURE0_ARB+i);		
			glPixelTransferf(GL_ALPHA_SCALE, (float)((float)(map->textureMaps->map[x][y])/255.0f));
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, textures[map->textures-1]);				
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
			glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);				
		}

		for (i = 0; i < map->texturesNum; i++)
			glMultiTexCoord2fARB(GL_TEXTURE0_ARB+i, 0.0, 0.0);		
        	glColor3b(texcolormap->map[x][y][0], texcolormap->map[x][y][1],     texcolormap->map[x][y][2]);
		glVertex3f(255-x, (float)surfacemap->map[x][y] * (float)scaleValue, y);

		for (i = 0; i < map->texturesNum; i++)
			glMultiTexCoord2fARB(GL_TEXTURE0_ARB+i, 0.0, 1.0);		
		glColor3b(texcolormap->map[x][y+1][0], texcolormap->map[x][y+1][1], texcolormap->map[x][y+1][2]);
		glVertex3f(255-x, (float)surfacemap->map[x][y+1] * (float)scaleValue, y+1);

		for (i = 0; i < map->texturesNum; i++)
			glMultiTexCoord2fARB(GL_TEXTURE0_ARB+i, 1.0, 1.0);		
		glColor3b(texcolormap->map[x+1][y+1][0], texcolormap->map[x+1][y+1][1], texcolormap->map[x+1][y+1][2]);
		glVertex3f(255-(x+1), (float)surfacemap->map[x+1][y+1] * (float)scaleValue, y+1);

		for (i = 0; i < map->texturesNum; i++)
			glMultiTexCoord2fARB(GL_TEXTURE0_ARB+i, 1.0, 0.0);		
		glColor3b(texcolormap->map[x+1][y][0], texcolormap->map[x+1][y][1], texcolormap->map[x+1][y][2]);
		glVertex3f(255-(x+1), (float)surfacemap->map[x+1][y] * (float)scaleValue, y);					

        }

maybe it's a little mixed up and confusing, but I'm a lot confused atm ^^

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!