Solved

How do I write RGB vals to texture in D3D11?

Posted on 2011-03-18
7
1,500 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 Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
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…

790 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