# DX11 [SlimDX][DX11] New RenderTarget Will Not Accept Texture2D From SwapChain

This topic is 2887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Good day to all, I have just started learning how to program with DirectX, so I believe I have made an error here. I am not new to programming, just DirectX, and I cannot seem to solve the following issue:

I am following the basic setup tutorials for SlimDX (http://slimdx.org/tu...iceCreation.php) and everything works nicely up until it is time to set the render target to the back buffer. According to the tutorial, the back buffer must be specified as a Texture2D from the swap chain. This makes perfect sense, but I cannot make it work. SlimDX includes a special Resource.FromSwapChain generic to acquire anything that derives from Resource. The tutorial specifies this line of code to do so:
using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0)) renderTarget = new RenderTargetView(device, resource);
I have tried making code that follows this exact format with different variable names, but it will not compile saying there is an invalid parameter (for the second parameter of the RenderTargetView constructor). I have tried arranging my code in many different ways and this is what I currently have:
Texture2D BackBufferTexture; BackBufferTexture=Resource.FromSwapChain<Texture2D>(VSwapChain,0); VRenderTarget=new RenderTargetView(VDevice,BackBufferTexture);

One thing I noticed is that the Texture2D being sent to the render target needs to have certain BindFlags set in its description object. Upon debugging, I noticed that no flags were set for BackBufferTexture even after getting it from the swap chain. Unfortunately (or probably very fortunately), the description object in a Texture2D is read only and I cannot set the flags afterward. What am I missing here?

Any help is greatly appreciated, thank you.

##### Share on other sites
The code you have there should work. There must be something else wrong in your program.

Note that there are two Resource classes, one in the Direct3D11 namespace and one in the DXGI namespace. If you have using statements for both namespaces, the names will clash and you should get an error for that first line.

##### Share on other sites
Thank you for the reply. Well, I followed the tutorial to the letter on building the rest of the functionality, with the exception of one thing. All of this code is contained in my own static renderer class, of which every member and method is also static. The MessagePump is still being called from Main(), but it references RenderFrame() through my static renderer class. I did not think that would be a problem, but perhaps it is? I will be able to post my code as soon as I have access to my own desktop again.

By the way, I am using SlimDX for .NET4 and compiling for only x64 with Visual Studio 2010. My machine has a fully featured DX11 card.

##### Share on other sites
Well it turns out I had completely overlooked a single line of code in the SwapChainDescription: SCDescription.Usage=Usage.RenderTargetOutput;

Anyway, it appears to have solved all of my problems.

Thanks again.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 23
• 42
• 75