Advertisement Jump to content
Sign in to follow this  
kolarz3

DX11 Problem with creating "blanc" ID3D11Texture2D

This topic is 1795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i try to generate texture progrmically. Everything looks good, but when I save texture to file I'm disappointed. I expected red texture but i got this: 

qrer.png

 

Code:

bool ModelData::createDefaultMaterial()
{
	struct Pix
	{
		float r,g,b,a;
	};
	Pix* img;
	img=new Pix[256*256];

	for(int y=0;y<128;y++)for(int x=0;x<256;x++){img[y*256+x].r=1.0;img[y*256+x].g=0.0;img[y*256+x].b=0.0;img[y*256+x].a=1.0;}
	D3D11_TEXTURE2D_DESC desc; 
	ZeroMemory( &desc, sizeof(desc)); 
	desc.Width = 256; 
	desc.Height = 256; 
	desc.MipLevels = desc.ArraySize = 1; 
	desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 
	desc.SampleDesc.Count = 1; 
	desc.Usage = D3D11_USAGE_DYNAMIC; 
	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 

	ID3D11Texture2D *pTexture = NULL; 
	engine.d3d11Device->CreateTexture2D( &desc, NULL, &pTexture ); 

	D3D11_MAPPED_SUBRESOURCE mapResource;
	engine.d3d11DevCon->Map(pTexture,0,D3D11_MAP_WRITE_DISCARD,0,&mapResource);
	BYTE* mappedData = reinterpret_cast<BYTE*>(mapResource.pData);
	memcpy(mappedData, img, 256*256*4);
	engine.d3d11DevCon->Unmap(pTexture, 0);
	D3DX11SaveTextureToFile(engine.d3d11DevCon,pTexture,D3DX11_IFF_PNG,L"nazwaa.png");
	return TRUE;
}

Share this post


Link to post
Share on other sites
Advertisement
bool ModelData::createDefaultMaterial()
{
	struct Pix
	{
		float r,g,b,a;
	};
	Pix* img;
	img=new Pix[256*256];

	for(int y=0;y<256;y++)for(int x=0;x<256;x++){img[y*256+x].r=1.0;img[y*256+x].g=0.0;img[y*256+x].b=0.0;img[y*256+x].a=1.0;}
	D3D11_TEXTURE2D_DESC desc; 
	ZeroMemory( &desc, sizeof(desc)); 
	desc.Width = 256; 
	desc.Height = 256; 
	desc.MipLevels = desc.ArraySize = 1; 
	desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; 
	desc.SampleDesc.Count = 1; 
	desc.Usage = D3D11_USAGE_DYNAMIC; 
	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 

	ID3D11Texture2D *pTexture = NULL; 
	engine.d3d11Device->CreateTexture2D( &desc, NULL, &pTexture ); 

	D3D11_MAPPED_SUBRESOURCE mapResource;
	engine.d3d11DevCon->Map(pTexture,0,D3D11_MAP_WRITE_DISCARD,0,&mapResource);
	BYTE* mappedData = reinterpret_cast<BYTE*>(mapResource.pData);
	memcpy(mappedData, img, 256*256*4*sizeof(float));
	engine.d3d11DevCon->Unmap(pTexture, 0);
	D3DX11SaveTextureToFile(engine.d3d11DevCon,pTexture,D3DX11_IFF_PNG,L"nazwaa.png");
	return TRUE;
}

Problem is solved. I must change Format to DXGI_FORMAT_R32G32B32A32_FLOAT

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!