Sign in to follow this  
Inasnum

SlimDX Setup Process

Recommended Posts

This is my first time trying to use SlimDX or DirectX at all, so I apologize in advance for the ignorance that I'm sure to display. I'm using DirectX 10 (a somewhat arbitrary choice) and C#. I'm following the example of a simple tutorial I found that brings up a Form and draws a textured quad. My ultimate goal for now is to draw a square in a 3D space. However, I can't seem to get it to run. using System.Drawing; using System.Collections.Generic; using System.Windows.Forms;
// Step 1: Include the SlimDx namespace and alias nested namespaces
using SlimDX;
using SlimDX.DXGI;
using SlimDX.Direct3D10;

// resolve conflict - DXGI.Device & Direct3D10.Device
using Device = SlimDX.Direct3D10.Device;

.
.
.

            // Create a description of the swap chain or front and back buffers
            SwapChainDescription swapDesc = new SwapChainDescription();
            swapDesc.ModeDescription = modeDesc;        // link the ModeDescription
            swapDesc.SampleDescription = sampleDesc;    // link the SampleDescription
            swapDesc.BufferCount = 1;                   // Number of buffers (including the front buffer)
            swapDesc.Flags = SwapChainFlags.None;
            swapDesc.IsWindowed = true;
            swapDesc.OutputHandle = renderForm.Handle;  // The output window (the windows being rendered to)
            swapDesc.SwapEffect = SwapEffect.Discard;   // Scrap the contents of the buffer every frame
            swapDesc.Usage = Usage.RenderTargetOutput;  // Indicate that this SwapChain is going to be a render target

            // Create the DirectX 10 Device
            // Device = SlimDX.DirectX10.Buffer, see using declarations for resolution if there is a conflict
            Device device = new Device(DeviceCreationFlags.None);

            // Create the actual swap chain
            SwapChain swapChain = new SwapChain(factory, device, swapDesc);

            // Create and set the render target - the surface that we're actually going to draw on
            RenderTargetView renderTarget = new RenderTargetView(device, swapChain.GetBuffer<Texture2D>(0));
The application will not compile, and it appears that swapChain.GetBuffer() doesn't actually, contrary to what everyone else seems to be doing. Why don't I have access to the same methods as other developers? Has SlimDX been updated to go about this another way, and if so, what am I expected to do?

Share this post


Link to post
Share on other sites
I came across a similar problem when converting my barely started SlimDX D3D10 code to D3D11 - the solution for me was:

using (var resource = D3D11.Resource.FromSwapChain<D3D11.Texture2D>(swapChain,0))
{
    renderTarget = new D3D11.RenderTargetView(device, resource);
}

The Resource class also exists in the D3D10 namespace with the same function so I'm guessing its the same way for what you need.

Cheers

Share this post


Link to post
Share on other sites
SlimDX gets updated every few months, and sometimes stuff gets revised. We dropped the SwapChain.GetBuffer method in favor of something like what hornet1990 showed. It doesn't seem quite as nice, granted, but it's much more flexible.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this