• Advertisement
Sign in to follow this  

Trying to create DirectX11 texture from memory

This topic is 1910 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'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];

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;

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)
memset(&SRVDesc, 0, sizeof(SRVDesc));
SRVDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
SRVDesc.Texture2D.MipLevels = 1;

hr = pDevice->CreateShaderResourceView( tex, &SRVDesc, &pTextureArray[0]);
if (FAILED(hr))
//return hr;

multitextured = false;

}[/source] Edited by SamiHuutoniemi

Share this post

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

  • Advertisement