Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I write RGB vals to texture in D3D11?

Posted on 2011-03-18
7
Medium Priority
?
1,664 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
Technology Partners: 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 1500 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
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 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.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

715 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