How to use Ogre::TerrainLayerBlendMap::loadImage

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
flogo
Gnoblar
Posts: 2
Joined: Sun Oct 04, 2015 12:18 pm

How to use Ogre::TerrainLayerBlendMap::loadImage

Post by flogo »

Hi there,

I've finished the basic and intermediates tutorials and I'm coming back on the Basic Tutorial 3 : Terrain, Sky, and Fog.

I want to change the " Texture bound to terrain height " behavior to have the texture I want where I want.

I noticed the following function:

Code: Select all

void Ogre::TerrainLayerBlendMap::loadImage ( const Image &img) 	
Load an image into this blend layer.
However I cannot make it works, I tried to load different images, such as my heighMap.png (greyScale) or a full colored image (8 or 32 bits PNG) but each time, my texture is completely invisible (transparent).

initBlendMaps function

Code: Select all

 Ogre::Image img;
img.load("test.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
terrain->getLayerBlendMap(1)->loadImage(img);
Is it the correct procedure?

Thanks,
florgo
flogo
Gnoblar
Posts: 2
Joined: Sun Oct 04, 2015 12:18 pm

Re: How to use Ogre::TerrainLayerBlendMap::loadImage

Post by flogo »

So, I finally ended up with a method I coded myself.

It takes the alpha parameter of an image and map it with the blendmap :

Code: Select all

  void Terrain::loadImage(Ogre::Terrain *terrain, Ogre::TerrainLayerBlendMap *blendMap, const Ogre::String &filename)
  {
    Ogre::Image img;
    img.load(filename, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    const Ogre::uint16 layerBlendMapSize = terrain->getLayerBlendMapSize();

    /* Or you can rescale the image */
    if (img.getHeight() != layerBlendMapSize || img.getWidth() != layerBlendMapSize)
      throw Ogre::Exception(Ogre::Exception::ExceptionCodes::ERR_INVALIDPARAMS
			    , "Layer BlendMap size ("
			    + Ogre::StringConverter::toString(layerBlendMapSize)
			    +") is different from image size: "
			    + Ogre::StringConverter::toString(img.getHeight())
			    + ", "
			    + Ogre::StringConverter::toString(img.getWidth())
			    , __FUNCTION__
			    );
    
    float* pBlend0 = blendMap->getBlendPointer();
    for (Ogre::uint16 y = 0; y < layerBlendMapSize; ++y)
      {
    	for (Ogre::uint16 x = 0; x < layerBlendMapSize; ++x)
    	  {
	    float colour = img.getColourAt(x, y, 0).a;
	    
  	    blendMap->setBlendValue(x, y, colour);
    	  }
      }
  }

Please let me know if you have advice on this function or an answer for my first question.