๊นํ๋ธ์ ๊ณต๊ฐ๋ ์์ค๋ฅผ ๋ค์ด ๋ฐ์ ์ด์ฉํ๋ค
github.com/microsoft/directxtex ์ ์ํ์ฌ ์ฝ๋ํ์ผ์ ZIP์ผ๋ก ๋ค์ด๋ก๋ ํ๋ค.
์์ถ์ ํ๊ณ DirectXTex_Desktop_2022.sln ์๋ฃจ์
ํ์ผ์ ๋น์ฃผ์ผ ์คํ๋์ค๋ก ์ด๊ณ ๋น๋๋ฅผ ํด์ค๋ค.
๋น๋๊ฐ ์ ๋๋๋ฉด ์์ ํด๋์์ DirectXTex.lib ํ์ผ์ ์ด์ฉ์ ํ ๊ฑด๋ฐ..
ํค๋ ํ์ผ์ ๋ณต์ฌํด์..
Include ํด๋๋ฅผ ๋ง๋ค์ด์ ๋ณต์ฌํด ์ฃผ์๋ค
์์ง ์์ฑ์์ DLL๊ณผ LIB ํ์ผ์ ๋ถ์ด์ฌ ํ์ผ์ ์ค์ ํด์ฃผ๊ณ ..
ํด๋ ๊ฒฝ๋ก ์ค์ ๋ ํด์ค๋ค
์์ฑ์์ C/C++์ ํค๋ ํ์ผ์ ์ฐ๊ฒฐ, ํฌํจํด์ค ๋๋ ํฐ๋ฆฌ๋ฅผ ์ค์ ํด ์ค๋ค
C/C++ ์ค์ ์ ํค๋ํ์ผ, ๋ง์ปค๋ dll. lib ์ฐ๊ฒฐ ์ค์ .
ํ
์ค์ณ ํ์ผ์ ์ด์ฉํ๊ธฐ ์ํ ID3D11ShaderResourceView ์ด์ฉ์ ํ ์ ์๋ค.
์ฝ๋ ์์ .
//by JSHong CodeBlock//
#include "Core.h"#include "TextureLoader.h"#include <DirectXTex.h>#include <Utility/STLException.h>
namespace STL{ std::unordered_map<std::wstring, ID3D11ShaderResourceView*> TextureLoader::textureMap;
ID3D11ShaderResourceView* TextureLoader::CreateShaderResourceView(ID3D11Device* device, const std::wstring& filename) { auto search = textureMap.find(filename); if (search != textureMap.end()) { return search->second; }
std::wstring extension = filename.substr(filename.find_last_of(TEXT(".")) + 1); std::transform(extension.begin(), extension.end(), extension.begin(), tolower);
static auto basePath = std::filesystem::current_path().parent_path();
auto finalPath = basePath; finalPath /= "Content\\Textures"; finalPath /= filename;
DirectX::ScratchImage image; HRESULT hr = E_FAIL; if (extension == TEXT("tga") || extension == TEXT("targa")) { hr = DirectX::LoadFromTGAFile( finalPath.c_str(), nullptr, image ); } else { hr = DirectX::LoadFromWICFile( finalPath.c_str(), DirectX::WIC_FLAGS_NONE, nullptr, image ); }
ThrowIfFailed(hr, "Failed to load scratch image.");
ID3D11Texture2D* texture = nullptr; hr = DirectX::CreateTexture( device, image.GetImages(), image.GetImageCount(), image.GetMetadata(), reinterpret_cast<ID3D11Resource**>(&texture) );
ThrowIfFailed(hr, "Failed to create texture.");
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; memset(&srvDesc, 0, sizeof(srvDesc)); srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MipLevels = 1; srvDesc.Format = image.GetMetadata().format;
ID3D11ShaderResourceView* shaderResourceView = nullptr; hr = device->CreateShaderResourceView( texture, &srvDesc, &shaderResourceView );
SafeRelease(texture); ThrowIfFailed(hr, "Failed to shader resource view.");
textureMap.insert({ filename, shaderResourceView });
return shaderResourceView; }
void TextureLoader::Release() { for (auto pair : textureMap) { SafeRelease(pair.second); } }}
# ์
ฐ์ด๋ ํ๋ก๊ทธ๋๋ฐ ์
๋ฌธ ์ฑ
(http://www.yes24.com/Product/Goods/7366949)















0 comments:
๋๊ธ ์ฐ๊ธฐ