Sign in to follow this  
NeverKnovvsbestt

Transparent Images From File

Recommended Posts

Whenever I load an image from file that has sections that are transparent they show up as white. I was wondering if there is a different function for loading transparent images or if I am just doin it wrong. Here is my code: IDirect3DSurface9* DirectXManager::createSurface(int width, int height) { if(NULL == lpd3dDevice) { MessageBox(NULL, "Cannot create surface: lpd3dDevice is NULL", "ERROR", 0); return NULL; } HRESULT hResult; IDirect3DSurface9 *surface; hResult = lpd3dDevice->CreateOffscreenPlainSurface( width, height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL); if(FAILED(hResult)) return NULL; return surface; } . . . IDirect3DSurface9* DirectXManager::loadSurfaceFromFile(char* filePath) { HRESULT hResult; IDirect3DSurface9 *surface; D3DXIMAGE_INFO d3dxImageInfo; hResult = D3DXGetImageInfoFromFile(filePath, &d3dxImageInfo); if(FAILED(hResult)) return NULL; surface = createSurface(d3dxImageInfo.Width, d3dxImageInfo.Height); hResult = D3DXLoadSurfaceFromFile( surface, NULL, NULL, filePath, NULL, D3DX_DEFAULT, 0, NULL); if(FAILED(hResult)) return NULL; return surface; } . . . bool DirectXManager::drawImage( IDirect3DSurface9 *surface, RECT *srcRect, RECT *destRect) { if(NULL == lpd3dDevice) { MessageBox(NULL, "Cannot draw image", "ERROR", 0); return false; } HRESULT hResult = lpd3dDevice->StretchRect( surface, srcRect, getBackBuffer(), destRect, D3DTEXF_NONE); return !FAILED(hResult); }

Share this post


Link to post
Share on other sites
Hey bud,

I have had no problems with this. I just created the alpha channel texture and the RGB textures and used the Texture Tool that comes with the SDK and created a DDS like that. You open the individual textures on to the alpha and regualr surfaces of the DDS.

Then load it with D3DXCreateTextureFromFile().

Hope that helps,

Dave

Share this post


Link to post
Share on other sites
Note that StretchRect doesn't even attempt to actually blend the colors to the framebuffer - it just copies the image data from one surface to another with the alpha channel included.

If you do want to alpha-blend something, you must use a texture with an alpha channel, and use either a quad (two triangles) or a sprite instance to draw it to the frame buffer. In addition, you must set the alpha-blending renderstates as appropriate.

Share this post


Link to post
Share on other sites
Quote:
Original post by NeverKnovvsbestt
so i should be using loadTextureFromFile() not loadSurfaceFromFile()?


Yes, and you should also transfer the image to the screen a little bit differently.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this