Solved

How do I write RGB vals to texture in D3D11?

Posted on 2011-03-18
7
1,430 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

760 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

18 Experts available now in Live!

Get 1:1 Help Now