Solved

How do I write RGB vals to texture in D3D11?

Posted on 2011-03-18
7
1,455 Views
Last Modified: 2012-05-11
Hi experts,

Can anyone possibly point me to an example (or provide one) of how to write an array of RGBA values to a texure in DX11?  I know how to create from a file and display, but can't seem to work out how I can create from an array of RGBA vals (and subsequently update without recreating from scratch when the RGB vals change).

Very grateful for any help you can give! (using win32 vc++)

Thanks,
Chris
0
Comment
Question by:chrispauljarram
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:SunnyDark
ID: 35169735
Basically you create the texture , call "Map" on the texture, that provides you with the pointer to the data, then fill the data , then call "UnMap"
Here is a good example:
http://www.gamedev.net/topic/571522-d3d11how-shouldcan-i-take-the-renderized-backbuffer-to-a-texture-buffer/
0
 

Author Comment

by:chrispauljarram
ID: 35172655
Thanks SunnyDark..

From the other examples I've seen you can use  UpdateSubresource too which I'm trying, however I still have problems - my texture (and the poly its on) is invisible.  When I load a texture from a file and display it it's fine however (so its definately something to do with the way I'm initializing).  Can you see anything wrong with the attached code (undoubtedly there is something I'm missing)?

Once again very grateful for the help!  I've been tearing my hair out most of the day with this one :(

Thanks in advance,
Chris.
ID3D11Texture2D* pTexture = NULL;
ID3D11ShaderResourceView *texv;

// initializing texv with this works fine (texture is displayed when I render my object, so coords and rendering code are correct - I've not included them because I know its doing what it should)...

D3DX11CreateShaderResourceViewFromFile(pDevice,            
                                       "Wood.png",    
                                       NULL,           
                                       NULL,           
                                       &texv,      
                                       NULL);   


// Using this instead (creating a mutable texture and writing all white to it) doesn't, my object is invisible...

	D3D11_TEXTURE2D_DESC texd;
	ZeroMemory(&texd, sizeof(texd));
	texd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	texd.Usage = D3D11_USAGE_DEFAULT;
	texd.Width = 256;
	texd.Height = 256;
	texd.ArraySize = 1;

	UINT32 *textureData = new UINT32[texd.Width * texd.Height];

	for(int i = 0; i < (texd.Width * texd.Height); i++)
	     textureData[i] = 0xFF0000FF;

	pDevice->CreateTexture2D( &texd, NULL, &pTexture );
			
	m_pD3D11DeviceContext->UpdateSubresource(pTexture, 0,  NULL, textureData, texd.Width*4, texd.Width*texd.Height*4);

 	pDevice->CreateShaderResourceView(pTexture,NULL,&texv);

Open in new window

0
 
LVL 8

Expert Comment

by:SunnyDark
ID: 35173592
At first sight I dont see a problem with the code...
Please check the following: Create the d3d device with DEBUG option and see if directX prints anything on the output window when executing UpdateSubresource.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:chrispauljarram
ID: 35174765
Thanks Sunny, unfortunately I can't create the d3d device with the debug option as I don't own it (it's being hooked in a 3rd party app via an injected dll - this is an overlay renderer).

I'm sure it must be something to do with the switches / flags I'm using as everything else works fine :-/  Can you suggest anything else?

Cheers,

Chris
0
 
LVL 8

Accepted Solution

by:
SunnyDark earned 500 total points
ID: 35174780
Ok then you can force directx to use the debug version in the directx control panel. You have it if you installed the sdk.
0
 

Author Comment

by:chrispauljarram
ID: 35192688
Not to worry, working now - thanks for the help.
0
 

Author Closing Comment

by:chrispauljarram
ID: 35192691
.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now