Terrain Texture and Size Problems

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
tomhancocks
Posts: 15
Joined: Fri Jan 02, 2009 1:25 pm
Location: Around
Contact:

Terrain Texture and Size Problems

Post by tomhancocks »

Hi,

I've recently begun implementing a more flexible terrain system for my game, one that will use an array of tiles in such a way that I can keep a high level of detail in the texture. I want to avoid scaling textures if at all possible.

So far everything has been going pretty well except for when I apply a texture to a tile the bottom and left of the texture are being trimmed, by about 15 pixels. The same is true of the height map, and thus is preventing each time for meeting up accurately.

I've done a small test with a screen shot and example textures to illustrate this.

Example Texture
Image
Runtime
Image

The code that is producing my tiled terrain is

Code: Select all

// Map Loader ///////////////////////////////////////////////////////////////////////////////////////
	int x = 0;
	int y = 0;
	int i = 0;
#define _W 2
#define _H 2
	
	scene::ITerrainSceneNode *terrain[_W*_H];
	for (y = 0; y < _H; y++) {
		for (x = 0; x < _W; x++) {
			char mapTile[256];
			char tex[256];
			sprintf(mapTile, "Game.app/Contents/Resources/map%d%d.png", y, x);
			sprintf(tex, "Game.app/Contents/Resources/tex%d%d.png", y, x);
			printf("%d %d\n", x, y);
			terrain[i] = smgr->addTerrainSceneNode(mapTile, 0, -1, 
												   core::vector3df(x*256, -200, y*256), 
												   core::vector3df(0, 0, 0),
												   core::vector3df(1, 1, 1), 
												   video::SColor(255, 255, 255, 255), 
												   5, 
												   scene::ETPS_17, 
												   4, true);
			terrain[i]->setMaterialFlag(video::EMF_LIGHTING, false);
			terrain[i]->setMaterialTexture(0, driver->getTexture(tex));
			terrain[i]->setMaterialType(video::EMT_DETAIL_MAP);
			i++;
		}
	}
If anyone can provide any insight as to what is causing this I'd be very grateful.

Cheers, Tom[/code]
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

terrain scene node requires 2^n+1 pixels in each dimension. So using 256x256 will lead to cut-off borders. Please note that 1.5 will handle 257x257 heightmaps, but this requires support for 32bit indices on the machines you use that code.
Post Reply