Horde3D

Next-Generation Graphics Engine
It is currently 17.04.2025, 09:53

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: 11.06.2008, 19:30 
Offline

Joined: 20.01.2008, 07:16
Posts: 15
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 :)


Top
 Profile  
Reply with quote  
PostPosted: 11.06.2008, 21:05 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
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.

_________________
Tristam MacDonald - [swiftcoding]


Last edited by swiftcoder on 11.06.2008, 21:37, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: 11.06.2008, 21:31 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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. :)


Top
 Profile  
Reply with quote  
PostPosted: 12.06.2008, 01:01 
Offline

Joined: 20.01.2008, 07:16
Posts: 15
thanks guys, I got it working now :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group