Jump to content

  • Log In with Google      Sign In   
  • Create Account


Trying to create DirectX11 texture from memory


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 SamiHuutoniemi   Members   -  Reputation: 259

Like
0Likes
Like

Posted 31 October 2012 - 08:12 AM

Hello! I'm trying to create a 2d texture from memory data. The data is in the form of 200*200 XMFLOAT4's. I would think that this should work, but all I get is black. PIX shows that the sprite would be rendered in the right place though. Dont mind that the code has a texture array. I only use the first (and only) element. The last three parameters have the values 200, 200, 800.

Any thoughts?

NEVER MIND. The last parameter shouldnt be 800, but 800*4... facedesk.

[source lang="cpp"]Texture::Texture(ID3D11Device* pDevice, void* data, int width, int height, int rowPitch) { pTextureArray = new ID3D11ShaderResourceView*[2]; D3D11_TEXTURE2D_DESC desc; desc.Width = width; desc.Height = height; desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; 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 initData; initData.pSysMem = data; initData.SysMemPitch = static_cast<UINT>(rowPitch); initData.SysMemSlicePitch = width*height*4; ID3D11Texture2D* tex = 0; HRESULT hr = pDevice->CreateTexture2D(&desc, &initData, &tex); if (SUCCEEDED(hr) && tex != 0) { if (pTextureArray[0] != 0) { D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc; memset(&SRVDesc, 0, sizeof(SRVDesc)); SRVDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; SRVDesc.Texture2D.MipLevels = 1; hr = pDevice->CreateShaderResourceView( tex, &SRVDesc, &pTextureArray[0]); if (FAILED(hr)) { tex->Release(); //return hr; } } } multitextured = false;}[/source]

Edited by SamiHuutoniemi, 31 October 2012 - 08:18 AM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS