Copying TextureBuffer to UCHAR *

Started by
12 comments, last by webmunkey 22 years, 5 months ago
Another thing, D3DXCreateTextureFromFile generates mip maps and might fudge your file size and pixel depth to fit it to something the card likes. You might want to call IDirect3DTexture8::GetSurfaceLevel to make sure image width and hieght and depth are really what you expect them to be.

Edited by - invective on November 10, 2001 1:46:34 PM
Advertisement
Okay thanks, we''re close now... Almost there, however, we still have a problem. The heightfield looks like noise, but not random noise, it semi-takes on the shape of valleys and hills, so there must just be something wrong with the image information or the memcpy, this is what the function looks like now:
  IDirect3DSurface8 * HeightMapSurface = NULL;// load in height maphRet = D3DXCreateTextureFromFile(pID3DDevice, "heightd2.bmp", &HeightMap);if (hRet != D3D_OK)    InitFail(hWnd, hRet, "Error loading bitmap!");height_map_ptr = new UCHAR[HFIELD_WIDTH * HFIELD_HEIGHT * 3];HeightMap->GetSurfaceLevel(0, &HeightMapSurface);	D3DLOCKED_RECT gSurface;HeightMapSurface->LockRect(&gSurface, NULL, D3DLOCK_READONLY);unsigned char *pBits = (unsigned char *)gSurface.pBits;	for (int i = 0; i < HFIELD_HEIGHT; i++)    memcpy((void *)(height_map_ptr + HFIELD_WIDTH * i), (void *)(pBits + gSurface.Pitch * i), gSurface.Pitch);HeightMapSurface->UnlockRect();  

At first I tried it without the extra surface, and I got the same noise problem. So I changed according to your last post about mipmapping problems, but the problem didn''t change. It''s close, but not quite...
Thanks in advance,
-Jesse
heh, you would think i could get one memcpy right after 2 tries, but it should be

memcpy((void *)(height_map_ptr + HFIELD_WIDTH * i), (void *)(pBits + gSurface.Pitch * i), HFIELD_WIDTH);

Also it looks like you are reading in and RGB image, so what channel are you using for the hieght value, or are you summing all 3? If you are adding all 3 colors it might not look the same as the bitmap, thats why its usually easier to use grayscale, or one channel.
Doh! I am not a smart person. Of course, now instead of indexed colors, the colors come to the height_map_ptr in 4 parts, r, g, b and a. So for uses in a heightmap, all I have to do is make the bitmap greyscale and then use the blue value (since they''ll all be the same anyway). The blue value can be found by multiplying the height_map_ptr[x] by 4. Thanks for your help,
Cheers,
-Jesse

This topic is closed to new replies.

Advertisement