Horde3D
http://horde3d.org/forums/

Trying to create dynamic heightmaps
http://horde3d.org/forums/viewtopic.php?f=2&t=369
Page 1 of 1

Author:  Dark_Kilauea [ 11.06.2008, 19:30 ]
Post subject:  Trying to create dynamic heightmaps

I'm trying to dynamically create heightmaps for the terrain scene node but am having problems with the whole texture creation bit. This is what I'm trying to do:

Code:
ResHandle TerrainTool::createNoisyHeightmap(const char* name)
{
    srand( time(NULL) );
   ResHandle tex = Horde3D::createTexture2D(name, ResourceFlags::NoTexRepeat|ResourceFlags::NoTexCompression|ResourceFlags::NoTexMipmaps|ResourceFlags::NoTexFiltering, 512, 512, false);

    unsigned char* data = new unsigned char[512*4*512];

    for( unsigned int x=3; x<512*4; x++)
        for( unsigned int y=0; y<512; y++)
        {
            data[y*(512*4)+x] = (unsigned char)rand();
        }

    if(!Horde3D::updateResourceData(tex, TextureResParams::PixelData, data, sizeof(data)))
    {
        std::cout << "Problem generating heightmap! \n";
        loaded = false;
    }
    else
        loaded = true;

    delete data;

    return tex;
}


What kind of noobish mistakes am I making? Thanks :)

Author:  swiftcoder [ 11.06.2008, 21:05 ]
Post subject:  Re: Trying to create dynamic heightmaps

Unfortunately, the engine doesn't accept straight pixel data, so you need to format the image data as a real image format. There are several suggestions floating around, but either TGA or BMP might be your best bet, just attach a minimal header to your image data.
Never mind - see Marciano's explanation, below.

Author:  marciano [ 11.06.2008, 21:31 ]
Post subject:  Re: Trying to create dynamic heightmaps

In contrast to loadResource, the updateResourceData takes raw data (the size of the texture is already known when the update function is called, so this is possible here).

The problem is that sizeof( data ) returns the size of the pointer, hence 4 on 32 bit systems. The engine expects 512*512*4. A general tip: don't be scared to use the debugger in order to jump into Horde. The engine code is not very cryptic and especially in this case you see immediately why the engine returns false. :)

Author:  Dark_Kilauea [ 12.06.2008, 01:01 ]
Post subject:  Re: Trying to create dynamic heightmaps

thanks guys, I got it working now :)

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/