rate up
2
rate down
DirectX11 tutorial texture
Hi, Looking at adding a texture to my cube but using WIC texture loader and DirectXTK. Can anyone help me out please? Thanks, Andy
Chosen Answer
rate up
1
rate down
The easiest way to do it is to copy these files from the toolkit into your project: pch.h DirectXHelpers.h PlatformHelpers.h WICTextureLoader.h WICTextureLoader.cpp Then in the class you want to load the image from, include *WICTextureLoader.h* You can either load images from files or from memory. To load images from memory call this function: HRESULT DirectX::CreateWICTextureFromMemory( ID3D11Device* d3dDevice, const uint8_t* wicData, size_t wicDataSize, ID3D11Resource** texture, ID3D11ShaderResourceView** textureView, size_t maxsize ) And to load from a file call this function: HRESULT DirectX::CreateWICTextureFromFile( ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dContext, const wchar_t* fileName, ID3D11Resource** texture, ID3D11ShaderResourceView** textureView, size_t maxsize ) I'll assume you want to load from a file, so i'll explain that function. The CreateWICTextureFromFile() function loads in an image file, decodes it to get rgba values, then creates a ID3D11Texture2D resource and a shader resource view (ID3D11ShaderResourceView). Once you have added the files mentioned above into your project and included WICTextureLoader.h, you can get your texture resource and shader resource view something like this: ID3D11Device* device; ID3D11DeviceContext* devContext; ID3D11Resource* texture; ID3D11ShaderResourceView* srv; using namespace DirectX; int main() { // create device and device context HRESULT hr = CreateWICTextureFromFile(device, devContext, "texture.png", &texture, &srv); if(FAILED(hr)) return 1; // now go ahead and use the srv to texture your object return 0; } feel free to comment if you find something isn't working or i've said something wrong here. This is a common question and i will update this answer if anybody finds anything wrong with it
Comments
Hey iedoc, thanks for the quick response :). Really helpful.
on Apr 16 `16
andydeveloper27@gmail.com
Sign in to answer!