3

Here is my unsuccessful try :

IDirect3DSurface9 *renderTargetSurface;
BITMAP bmp;
HBITMAP hBMP = ( HBITMAP ) LoadImage ( 0, "D:\\DATA\\FLAG_B24.BMP", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
int bytes = GetObject ( hBMP, sizeof( BITMAP ), &bmp ); //bytes = 24
HRESULT res = m_pd3dDevice->CreateOffscreenPlainSurface ( bmp.bmWidth, bmp.bmHeight, D3DFMT_X8R8G8B8, 
                                                          D3DPOOL_SYSTEMMEM, &renderTargetSurface, NULL ); //res = S_OK
RECT r = { 0, 0, bmp.bmWidth, bmp.bmHeight };
res = D3DXLoadSurfaceFromMemory ( renderTargetSurface, NULL, NULL, bmp.bmBits, D3DFMT_X8R8G8B8,
                                  bmp.bmWidthBytes, NULL, &r, D3DX_FILTER_NONE, 0 ); //res = D3DERR_INVALIDCALL

As you can see D3DXLoadSurfaceFromMemory returns D3DERR_INVALIDCALL.

Here is some debugging info :

renderTargetSurface properties :

Name = 0x00000000 <NULL>, Width = 22,
Height = 1, Usage = 205520896 ,Format = 2, Pool = D3DPOOL_DEFAULT (0),
MultiSampleType = D3DMULTISAMPLE_NONE (0), MultiSampleQuality = 124,
Priority = 124, LockCount = 2, DCCount = 22, CreationCallStack = 0x00000000 <NULL>

bmp properties :

bmType = 0, bmWidth = 124, bmHeight = 124,
bmWidthBytes = 496, bmPlanes = 1, bmBitsPixel = 32, bmBits = 0x00000000

What I'm doing wrong here?

HMD
  • 2,202
  • 6
  • 24
  • 37
  • 1
    Keep in mind that Direct3D 9 is legacy, that ``D3DX`` for DX9, DX10, and DX11 are all deprecated, and that both the DirectX SDK and DirectSetup (required to deploy ``D3DX``) is end-of-life. See [MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/ee663275.aspx). You should probably be using DirectX 11 instead. See [Living without D3DX](https://blogs.msdn.microsoft.com/chuckw/2013/08/20/living-without-d3dx/) – Chuck Walbourn Sep 25 '17 at 18:25

1 Answers1

2

bmp.bmBits is null. You need to pass LR_CREATEDIBSECTION flag into LoadImage, otherwise it will create a compatible bitmap and raw data won't be available.

const char * psz_file_path("D:\\DATA\\FLAG_B24.BMP");
const ::UINT flags(LR_LOADFROMFILE | LR_CREATEDIBSECTION);
HBITMAP hBMP(reinterpret_cast<::HBITMAP>(::LoadImage(0, psz_file_path, IMAGE_BITMAP, 0, 0, flags)));
user7860670
  • 35,849
  • 4
  • 58
  • 84