1
\$\begingroup\$

I am trying to load a texture into my 3d graphics application. I am having trouble with my sampler state specifically. There are no errors generated just my little popup window saying, "Texture failed to load". I did a bit of debugging and couldn't find why my sampler is having trouble loading. All of the HRESULTs return S_OK and yet it throws a popup at me.

resourceManager.h

#pragma once

#include "renderer.h"
#include <d3dx11tex.h>

class ResourceManager
{
private:
    ComPtr<ID3D11SamplerState> m_Sampler;
    ComPtr<ID3D11ShaderResourceView> m_Texture;

    Renderer m_Renderer;
public:
    ResourceManager(Renderer& renderer);

    inline ComPtr<ID3D11SamplerState> GetSampler() const { return m_Sampler; }
    inline ComPtr<ID3D11ShaderResourceView> GetTexture() const { return m_Texture; }

    bool CreateTexture(LPCWSTR file_name);
};

resourceManager.cpp

#include "resourceManager.h"

ResourceManager::ResourceManager(Renderer& renderer)
    : m_Renderer(renderer)
{

}

bool ResourceManager::CreateTexture(LPCWSTR file_name)
{
    auto handlerR = D3DX11CreateShaderResourceViewFromFile(m_Renderer.GetDevice().Get(), file_name, nullptr, nullptr, m_Texture.GetAddressOf(), nullptr);
    if (FAILED(handlerR)) return false;

    D3D11_SAMPLER_DESC sampDesc;
    ZeroMemory(&sampDesc, sizeof(sampDesc));
    sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
    sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    sampDesc.MinLOD = 0;
    sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
    auto handlerS = m_Renderer.GetDevice()->CreateSamplerState(&sampDesc, m_Sampler.GetAddressOf());
    if (FAILED(handlerS)) return false;

    return true;
}
\$\endgroup\$
3
  • \$\begingroup\$ First thing to do is to make sure you have initialized the device with D3D11_DEBUG_DEVICE. This logs any errors to the output window. Secondly, which call is failing and what's the HRESULT value? \$\endgroup\$
    – Syntac_
    Commented Mar 31, 2016 at 9:05
  • \$\begingroup\$ You should go to this page and have your accounts merged. \$\endgroup\$
    – Vaillancourt
    Commented Mar 31, 2016 at 14:18
  • \$\begingroup\$ You should really consider not using legacy D3DX11. Take a look at one of the many replacements. \$\endgroup\$ Commented Apr 11, 2016 at 20:56

1 Answer 1

1
\$\begingroup\$

I figured it out lol. When I was checking to see if the function returned false, I forgot to negate the if statement using "!".

if (!resourceManager.CreateTexture(L"Resources/container.png"))
\$\endgroup\$
1
  • \$\begingroup\$ Can you accept the answer so it stops showing up in the feed as unanswered. \$\endgroup\$ Commented Apr 22, 2017 at 2:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .