I am getting raw data from stb_image.c for an image I want to load. I am then trying to turn it into a drawable texture. I haven't been able to find any tutorials on how to load an image from raw data. I have assembled some code from what I could gather from the documentation. The image drawing code works because I use different code to set the same resource view with a dds texture and it works. All the results are S_OK.
int x, y, n;
unsigned char *data = stbi_load(charFilename, &x, &y, &n, 0);
D3D11_TEXTURE2D_DESC desc;
desc.Width = x;
desc.Height = y;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
/*D3D11_SUBRESOURCE_DATA subres;
subres.pSysMem = data;
subres.SysMemPitch = x * n;
subres.SysMemSlicePitch = 0;*/
ID3D11Texture2D *texture2D = 0;
HRESULT result = device->CreateTexture2D(&desc, NULL, &texture2D);
if (FAILED(result))
{
DebugConsole::writeLine("Failed to create Texture2D");
}
D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
resourceViewDesc.Format = desc.Format;
resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
resourceViewDesc.Texture2D.MostDetailedMip = 0;
resourceViewDesc.Texture2D.MipLevels = 1;
result = device->CreateShaderResourceView(texture2D, &resourceViewDesc, &m_texture);
if (FAILED(result))
{
DebugConsole::writeLine("Failed to create resource view");
}