Loading PNG files

Started by
10 comments, last by viper110110 11 years, 1 month ago

If you're feeling like doing it yourself, you can have a look at the PNG format specification.It'll probably take some time to familiarize yourself with it, but the documentation appears exhaustive.

Advertisement

I have now loaded the png file using stb_image.c but the image is not showing.


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, &subres, &texture2D);
	if (FAILED(result))
	{
		DebugConsole::writeLine("Failed to create Texture2D");
	}

	result = device->CreateShaderResourceView(texture2D, NULL, &m_texture);
	if (FAILED(result))
	{
		DebugConsole::writeLine("Failed to create resource view");
	}

I have checked the HRESULT of both calls and they are both S_OK. I have also checked the filename and it is correct. If I change the extension to .dds (I have both files in the directory) then it works using the dds loading code (it checks for the .dds extension). Have I made a small mistake or am I going at it all wrong?


This topic is closed to new replies.

Advertisement