I'm pulling out my hair here trying to understand what I am doing wrong but I am having issues in loading and rendering pngs using D3DXLoadSurfaceFromFile() using the D3D9 API. They load but not correctly because they seem to be corrupt after rendering when the files are OK. A good example is from the files attached. The one on the top is loaded into a surface and being rendered using StrechRect(). However as you can see from the original on the bottom, its not doing it correctly and that not to mention that the alpha channel is being used. Therefore, I should only be seeing the cleared back buffer and the silhouette of the heli but I'm not. I don't know if there is anything I'm not doing but here is my initialisation and render code from the sprite class I used to render:
[source lang="cpp"]void MySprite::Initialise(wstring fileName){HRESULT hResult;if( m_bitmap == nullptr){ D3DXIMAGE_INFO imgInfo; hResult = D3DXGetImageInfoFromFile( fileName.c_str(), &imgInfo); m_bitmapSize.X = imgInfo.Width; m_bitmapSize.Y = imgInfo.Height; hResult = Graphics::GetInstance()->getDevice()->CreateOffscreenPlainSurface( m_bitmapSize.X, m_bitmapSize.Y, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_bitmap, NULL); if( FAILED( hResult ) ) { MessageBox(NULL, L"Unable to create Offscreen surface", L"ERROR", MB_OK); return; } if( fileName != L"" ) { hResult = D3DXLoadSurfaceFromFile( m_bitmap, NULL, NULL, fileName.c_str(), NULL, D3DX_DEFAULT, 0, NULL ); if( FAILED( hResult ) ) { MessageBox(NULL, L"Unable to load image into memory", L"ERROR", MB_OK); return; } }}.if( m_backBuffer == nullptr){ hResult = Graphics::GetInstance()->getDevice()->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &m_backBuffer); if( FAILED( hResult ) ) { MessageBox(NULL, L"Unable to Unable to obtain BackBuffer", L"ERROR", MB_OK); return; }}}void MySprite::Render(const RECT& destRect){if( m_bitmap != nullptr && m_backBuffer != nullptr){ Graphics::GetInstance()->getDevice()->StretchRect( m_bitmap, NULL, m_backBuffer, &destRect, D3DTEXF_NONE);}}[/source]
I don't know if it is the format of the offscreen surface I'm using or what. BTW: the screen is being cleared but that is being called elsewhere. It is being cleared to D3DCOLOR_XRGB(255,100,0). Also bitmaps load fine so that is not an issue. Thing is I'm new to D3D9 and I'm happy something is rendering but its not doing it correctly.
Here are the images I mentioned:







