views:

93

answers:

1

I've been trying to figure out how to parse textures in directx for two reasons: to write my own texture format and to manipulate data in existing IDirect3DTexture9 type textures.

I've been looking at the IDirect3DTexture9::LockRect() function but I'm unsure how it works, are the void* pBits I get out of it in D3DLOCKED_RECT the data in the texture? Does that mean I can read it in by converting it to D3DXCOLOR or something?

I just want to be able to read in the rgba values and write to them if I want to...

Really not sure where to go, any help would be appreciated!

+1  A: 

The pBits value is a pointer to the actual texture data. The format of the data is specified by you when you create the texture.

The Pitch is the nuymber of bytes in one row. This is not necessarily (though usually is) the width of the texture multiplied by the number of bytes per pixel.

So if you have created a D3DFMT_A32B32G32R32F texture than you can INDEED cast the pBits pointer to a D3DXCOLOR pointer and access the colour components like an array (ie colour[count].r etc).

However if its a 32-bit then you'll need a structure something like the following (I'm not sure if i have my components the right way round but you can easily figure out what the right order is)

struct ARGB
{
    unsigned char a;
    unsigned char r;
    unsigned char g;
    unsigned char b;
};

Then you can cast pBits to an ARGB pointer and access it in the same way.

Things get a LOT more complicated when you bring compressed textures into it but thats the basics.

Goz