Solved

How do I write RGB vals to texture in D3D11?

Posted on 2011-03-18
7
1,582 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

630 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