Jump to content
  • Advertisement
Sign in to follow this  

DX11 Dynamic texture problem

Recommended Posts

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;

	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)

Edited by lonewolff

Share this post

Link to post
Share on other sites

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 :)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!