• Advertisement
Sign in to follow this  

Texture From GDI Bitmap Object

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

Is there an easy way to create a direct3d texture object from an in-memory gdi+ bitmap? I can't see a D3DX helper function for it. Failing that, is there an easy way to directly set pixels on a direct3d texture? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I found this snippet of code which looks good. Quick question though... does the pitch represent the number of bytes in a row of the returned rectangle?

Thanks


LPDIRECT3DTEXTURE9 texture;
...
...
D3DXCreateTextureFromFileEx(.., 0, D3DFMT_L8, D3DPOOL_SCRATCH, .., &texture );
...
...
D3DLOCKED_RECT data;
HRESULT hr;
hr = texture->LockRect( 0, &data, NULL, D3DLOCK_READONLY );
if (FAILED(hr))
{
// error handling goes here
// (locking something in the scratch pool
// usually shouldn't fail anyway)
}
...
...
// now have access to the raw data in the texture surface.
...
// cast the void pointer to the size of one of our D3DFMT_L8 pixels
// so that the compiler knows the size of an item of data
// this allows us to do pointer arithmetic on the surface
BYTE* bits = (BYTE *)data.pBits;
...
// access the pixel at x=10, y=20:
int offset = ((data.Pitch/sizeof(BYTE)) * 20) + 10;

BYTE pixel = bits[offset];
...
texture->UnlockRect( 0 );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement