Jump to content
  • Advertisement
Sign in to follow this  
NeverKnovvsbestt

Transparent Images From File

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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!