Jump to content
  • Advertisement
Sign in to follow this  
Sujal

DX11 D3DX11CreateShaderResourceViewFromFile and 32 bit .bmp files

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

When I read a bmp file with a alpha channel(32 bit .bmp file) using D3DX11CreateShaderResourceViewFromFile, I am not getting the alpha values at all. It works fine if I use .dds file instead of bmp. Any suggestions??



Here is my image reading code-

HRESULT hr = D3DX11CreateShaderResourceViewFromFile(device,fileName, NULL, NULL, textureShaderResourceView, NULL);
if( FAILED( hr ) )
return false;
return true;


Thanks

Share this post


Link to post
Share on other sites
Advertisement
I wonder how you create ".bmp" files with 4 channels. I suggest you stick with DDS or PNG, they work fine.

Edit: OK, I guess photoshop can do that. Maybe DirectX loaders can't.

Maybe try passing in a filled load info struct (3rd param)? Set the load info format to DXGI_FORMAT_R8G8B8A8_UNORM or a 16-bit RGBA (just for a test) a see if that helps.

Share this post


Link to post
Share on other sites
Thanks pcmaster for replying. Yea, I used photoshop to put alpha channel in the bmp file. I am gonna try passing in the 3rd param (D3DX11_IMAGE_LOAD_INFO) once I get home. Lets see what happens.

Share this post


Link to post
Share on other sites
It seems like neither D3DX11CreateShaderResourceViewFromFile nor D3DX11CreateTextureFromFile can read 32bit .bmp file correctly. Other formats like PNG and DDS with alpha channel works perfectly. I tried two methods but both failed to load alpha channel of 32bit bitmap correctly.

/////////////////////////////////////////////
//First method
/////////////////////////////////////////////

ID3D11Texture2D * pTexture2D = NULL;
ID3D11ShaderResourceView *pSRView = NULL;
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
D3D11_TEXTURE2D_DESC desc;

// Load the texture and initialize an ID3D11Texture2D object.
D3DX11CreateTextureFromFile(pDevice,szFileName, NULL, NULL, (ID3D11Resource**)(&pTexture2D), NULL );

// Get a texture description to determine the texture
// format of the loaded texture.
pTexture2D->GetDesc( &desc );

// Fill in the D3D11_SHADER_RESOURCE_VIEW_DESC structure.
srvDesc.Format = desc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = desc.MipLevels;

// Create the shader resource view.
HRESULT hr = pDevice->CreateShaderResourceView( pTexture2D, &srvDesc, &srvData);

////////////////////////////////////////////////////


////////////////////////////////////////////////////
//second method
////////////////////////////////////////////////////
D3DX11_IMAGE_LOAD_INFO imageLoadInfo;
imageLoadInfo.Width = D3DX11_DEFAULT;
imageLoadInfo.Height = D3DX11_DEFAULT;
imageLoadInfo.Depth = D3DX11_DEFAULT;
imageLoadInfo.FirstMipLevel = D3DX11_DEFAULT;
imageLoadInfo.MipLevels = D3DX11_DEFAULT;
imageLoadInfo.Usage = (D3D11_USAGE) D3DX11_DEFAULT;
imageLoadInfo.BindFlags = D3DX11_DEFAULT;
imageLoadInfo.CpuAccessFlags = D3DX11_DEFAULT;
imageLoadInfo.MiscFlags = D3DX11_DEFAULT;
imageLoadInfo.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
imageLoadInfo.Filter = D3DX11_DEFAULT;
imageLoadInfo.MipFilter = D3DX11_DEFAULT;
imageLoadInfo.pSrcInfo = NULL;

//Load the resource
HRESULT hr = D3DX11CreateShaderResourceViewFromFile(pDevice,szFileName, &imageLoadInfo, NULL, &srvData, NULL);
////////////////////////////////////////////////////

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!