• Advertisement

Archived

This topic is now archived and is closed to further replies.

Reading IDirect3DTexture

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

I was wondering how could i read the image data from the IDirect3DTexture struct for generating terrains using heightmaps. Or is there a better way? Thanks

Share this post


Link to post
Share on other sites
Advertisement
That''s the way I do it
Check out LPDIRECT3DTEXTURE->Lock (). It gets you a void pointer to the buffer and the pitch (the number of bytes across the screen). It''s something like this (for X8R8G8B8 format):

texture->Lock (blah);

BYTE *ptr = (BYTE *)blah.ptr;

for (int y = 0; y < HEIGHT; y++)
{
for (int x = 0; x < WIDTH; x++)
{
DWORD value = (ptr[0]) << 16 | (ptr[1] << 8 | (ptr[2]);
heightmap[y*blah.pitch+x] = value * normalizingfactor;
ptr += 3;
}
}

texture->Unlock ();


Not sure if the syntax is all correct but it should be something like that.

Share this post


Link to post
Share on other sites

  • Advertisement