• Advertisement
Sign in to follow this  

Reading texture data

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

Hello all,

I have troubles understanding how to read data from a locked texture. What im trying todo is to parse through an image of b/w texels to retrieve some informations. For testing that i created a 3x1 bmp file containing 2 black and 1 white (b,b,w) texel.(RGB, 8bit channels, 24bit depth)

So what i'm doing here is to create a texture out of that file and lock it. For my tests i directly access the pBits area of the locked rect. Yet they are not as expected.
As far as i know each texel will be represented by 4 bytes (b,g,r,a) on the locked memory area.

By that I would have expected a result like this:

First two black:
pbits[0] = 0
pbits[1] = 0
pbits[2] = 0
pbits[3] = 255
pbits[4] = 0
pbits[5] = 0
pbits[6] = 0
pbits[7] = 255

Last white:
pbits[8] = 255
pbits[9] = 255
pbits[10] = 255
pbits[11] = 255

Yet i receive something like this:
pbits[0] = 43
pbits[1] = 43
pbits[2] = 43
pbits[3] = 0
pbits[4] = 0
pbits[5] = 0
pbits[6] = 0
pbits[7] = 0
pbits[8] = 96
pbits[9] = 96
pbits[10] = 96
pbits[11] = 0

When i have only two pixel using black and white it does work however. Can someone help me finding out what i'm doing wrong here ? The pitch should not be important here as i only test the first 3 pixels, right ?!

Here a code snipped without all the checking stuff around:

IDirect3DTexture9* tex;
D3DXCreateTextureFromFile(g_device, "pixelTest.bmp", &tex);
ZeroMemory(&lRect, sizeof(D3DLOCKED_RECT));

tex->LockRect(0, &lRect, NULL, NULL);
int iPitch = lRect.Pitch;
BYTE* pPBits = static_cast<BYTE*>(lRect.pBits);

Any help would be highly appreciated - this thing costs me some hours already :unsure:

Thanks alot,

Share this post

Link to post
Share on other sites
ok, it does work when using D3DXCreateTextureFromFileEx. Even with a very default'ish one...


The default Filter parameter D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER was the reason for the color adjustments during the load.

Thanks anyway!

Share this post

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

  • Advertisement