How does "DXUTGetGlobalResourceCache().CreateTextureFromFile" correctly?

Started by
4 comments, last by lucaswrk 9 years, 4 months ago
Hi @ all,
i am started with directX programming in C++. I use the book "Spieleprogrammierung mit directX 11 und c++"
from "Susanne Wigard". Now i have a problem which i cant find a solution:
I tried to load a texture from a file, like in the book, with the following code.:
HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
[...]
DXUTFindDXSDKMediaFileCch(str, MAX_PATH, L"Wood.jpg");
DXUTGetGlobalResourceCache().CreateTextureFromFile( pd3dDevice, str, &g_pRV );
[...]
}
Information to the parameters:
ID3D11ShaderResourceView* g_pRV = NULL;
ID3D11Device* pd3dDevice
WCHAR str[MAX_PATH];
Between "DXUTGetGlobalResourceCache()" und the function "CreateTextureFromFile( pd3dDevice, str, &g_pRV );"
is the point underlined in red. The error message is:
"No instance of overloaded function "CreateTextureFromFile" matches the argument list"
I tried the change the arguments but i dont have enough skill.
The help of the IDE show the parameter as follow:
DXUTGetGlobalResourceCache().CreateTextureFromFile(pd3dDevice,ID3D11DeviceContext *pContext, LPCSTR pSrcFile, ID3D11ShaderresourceView **ppOutputRV, bool bSRGB = false);
But i dont have similar variables in my function.
Sombody know the correct handling of this method. A example will be nice!
Thank you very much!
Greets Meho .
Advertisement

Hello Meho, maybe the ID3D11DeviceContext *pContext parameter is missing on the call? Also, I recommend you to use DirectX Tool Kit for a more "modern" texture loading, you can get more info here and here is the source (you can copy the .h and .cpp files to your project, there is no need to use the entire DirectXTK library).

This Toolkit is a bit complex solution, it is possible to use DDSTextureLoader, which is a part of the new DXUT also.

This Toolkit is a bit complex solution, it is possible to use DDSTextureLoader, which is a part of the new DXUT also.

Actually, DirectXTK has DDSTextureLoader and WICTextureLoader. Again, it is possible to rip these files to your own project.

Hi,

thank you all for repley!

Yes it is possible to use a other method to handle texturs!

In the DXUT folder of my project in Visual Studio 12, i cant find DDSTextureLoader and WICTextureLoader. So i loaded from

your link and copyed&pasted WICTextureLoader.h und WICTextureLoader.cpp in my projektfolder. After that i included WICTextureLoader.h

and tried the example from: https://directxtk.codeplex.com/wikipage?title=WICTextureLoader&referringTitle=Home

Now i have two variant:

1:

hr = CreateWICTextureFromFile( pd3dDevice, L"Holz.jpg", nullptr, &g_pRV, 0 );
Here the compiler returns three error, from "c:\program files (x86)\windows kits\8.0\include\shared\dxgi1_2.h(1274)".
I think the errors are in my code and not in dxgi1_2.h !!
2:
ComPtr<ID3D11ShaderResourceView> srv;
hr = CreateWICTextureFromFile( pd3dDevice, immContext.Get(), L"Holz.jpg", nullptr, srv.GetAddressOf() );
Here i have trouble with immContext, because i dont know what variable it is!?
Have somebody a idea?
Thanks again!
Meho
p.s.: I dont have permission to upload a fil, so i uploaded it here: https://mega.co.nz/#!sMMw0ZYA!RuoDX6uDX0ULm2302h28wF21FDlS97EdaQT54aAN-Ik

Hi,

thank you all for repley!

Yes it is possible to use a other method to handle texturs!

In the DXUT folder of my project in Visual Studio 12, i cant find DDSTextureLoader and WICTextureLoader. So i loaded from

your link and copyed&pasted WICTextureLoader.h und WICTextureLoader.cpp in my projektfolder. After that i included WICTextureLoader.h

and tried the example from: https://directxtk.codeplex.com/wikipage?title=WICTextureLoader&referringTitle=Home

Now i have two variant:

1:

hr = CreateWICTextureFromFile( pd3dDevice, L"Holz.jpg", nullptr, &g_pRV, 0 );
Here the compiler returns three error, from "c:\program files (x86)\windows kits\8.0\include\shared\dxgi1_2.h(1274)".
I think the errors are in my code and not in dxgi1_2.h !!
2:
ComPtr<ID3D11ShaderResourceView> srv;
hr = CreateWICTextureFromFile( pd3dDevice, immContext.Get(), L"Holz.jpg", nullptr, srv.GetAddressOf() );
Here i have trouble with immContext, because i dont know what variable it is!?
Have somebody a idea?
Thanks again!
Meho
p.s.: I dont have permission to upload a fil, so i uploaded it here: https://mega.co.nz/#!sMMw0ZYA!RuoDX6uDX0ULm2302h28wF21FDlS97EdaQT54aAN-Ik

Make sure you are calling CreateWICTextureFromFile from the WICTextureLoader.h you have just created. I can't read your code right now, so here is an simplified example of how I call this function (note the DirectX namespace; TextureMgr is my class that holds this function; md3dDevice is a raw pointer to a ID3D11Device):


#include "WICTextureLoader.h"

ID3D11ShaderResourceView* TextureMgr::CreateTexture(std::wstring filename)
{
	ID3D11ShaderResourceView* srv = 0;

	DirectX::CreateWICTextureFromFile(md3dDevice, filename.c_str(), nullptr, &srv);

	return srv;
}

This topic is closed to new replies.

Advertisement