Dynamic texture problem

Started by
2 comments, last by DividedByZero 6 years, 7 months ago

Hi Guys,

I am having a bit of a problem with a dynamic texture.

It is creating without error and I am attempting to initialize the first pixel to white to make sure I am mapping correctly. But when I draw the texture to the quad it displays the whole quad white (instead of just one pixel).

This is how I am creating, mapping, and setting the first pixel to white. But as mentioned, when I draw the quad, the entire quad is white.

 


	// Create dynamic texture
	D3D11_TEXTURE2D_DESC textureDesc = { 0 };
	textureDesc.Width = 2048;
	textureDesc.Height = 2048;
	textureDesc.MipLevels = 1;
	textureDesc.ArraySize = 1;
	textureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	textureDesc.SampleDesc.Count = 1;
	textureDesc.Usage = D3D11_USAGE_DYNAMIC;
	textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	textureDesc.MiscFlags = 0;

	HRESULT result = d3dDevice->CreateTexture2D(&textureDesc, NULL, &textureDynamic);
	if (FAILED(result))
		return -1;

	result = d3dDevice->CreateShaderResourceView(textureDynamic, 0, &textureRV);
	if (FAILED(result))
		return -2;

	D3D11_MAPPED_SUBRESOURCE resource;
	if (FAILED(d3dContext->Map(textureDynamic, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource)))
		return -1;
	memset(resource.pData, 255, 4);
	d3dContext->Unmap(textureDynamic, 0);

 

Hopefully I have just made an oversight somewhere.

Any assistance would be greatly appreciated :)

(If I change the 255 value to 128 the quad then turns grey, so the mapping is definitely doing something. Just can't work out why it is colouring the whole quad and not the first pixel)

Advertisement

Are the UVs on the quad invalid, causing one pixel to stretch over the whole surface? 

Thanks Hodgman,

I knew the UV's were ok, but you jogged my memory. I hadn't updated the input description code and only had vertex position.

I have now updated it to use the texcoords as well and all is now good.

Thanks again :)

This topic is closed to new replies.

Advertisement