Hello! I'm currently working on a project and I'm having a bit of an issue with Direct3D 11 and textures. They're not showing up.
Now I don't know if my texture creation code is incorrect since I'm currently learning Direct3D 11.
Here's the texture creation code:
int width, height;
int channels;
stbi_uc* data = stbi_load(m_Filepath.c_str(), &width, &height, &channels, 4);
COFFEE_ASSERT(data, "Failed to load texture!");
m_Width = width;
m_Height = height;
D3D11_TEXTURE2D_DESC textureDesc;
ZeroMemory(&textureDesc, sizeof(textureDesc));
textureDesc.Width = m_Width;
textureDesc.Height = m_Height;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.Usage = D3D11_USAGE_DYNAMIC;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
D3D11_SUBRESOURCE_DATA initData;
initData.pSysMem = data;
initData.SysMemPitch = m_Width * 3;
initData.SysMemSlicePitch = m_Width * m_Height * 3;
HRESULT result = DX11Context::GetDevice().CreateTexture2D(&textureDesc, &initData, &m_Texture);
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
ZeroMemory(&srvDesc, sizeof(srvDesc));
srvDesc.Format = textureDesc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = textureDesc.MipLevels;
result = DX11Context::GetDevice().CreateShaderResourceView(m_Texture, &srvDesc, &m_TextureView);
//DX11Context::GetDeviceContext().GenerateMips(m_TextureView);
D3D11_SAMPLER_DESC samplerDesc;
ZeroMemory(&samplerDesc, sizeof(samplerDesc));
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
result = DX11Context::GetDevice().CreateSamplerState(&samplerDesc, &m_SamplerState);
stbi_image_free(data);
I don't know if the issue is the actual creation of the texture, or if it's something else. If anyone has any suggestions please tell me.