daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Dec 14th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Windows.Forms;
  2.  
  3. using SlimDX;
  4. using SlimDX.Direct3D11;
  5. using SlimDX.DXGI;
  6. using SlimDX.Windows;
  7. //using SlimDX.Direct2D;
  8.  
  9. using Device = SlimDX.Direct3D11.Device;
  10. using Resource = SlimDX.Direct3D11.Resource;
  11.  
  12. namespace SlimDXTest
  13. {
  14.     public class MyGame
  15.     {
  16.         public static void Main(string[] args)
  17.         {
  18.             var form = new RenderForm("SlimDX Test");
  19.             var description = new SwapChainDescription()
  20.             {
  21.                 BufferCount = 1,
  22.                 Usage = Usage.RenderTargetOutput,
  23.                 OutputHandle = form.Handle,
  24.                 IsWindowed = true,
  25.                 ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
  26.                 SampleDescription = new SampleDescription(1, 0),
  27.                 Flags = SwapChainFlags.AllowModeSwitch,
  28.                 SwapEffect = SwapEffect.Discard
  29.             };
  30.  
  31.             Device device;
  32.             SwapChain swapChain;
  33.             Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out device, out swapChain);
  34.  
  35.             RenderTargetView renderTarget;
  36.  
  37.             using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
  38.             {
  39.                 renderTarget = new RenderTargetView(device, resource);
  40.             }
  41.  
  42.             var context = device.ImmediateContext;
  43.             var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
  44.             context.OutputMerger.SetTargets(renderTarget);
  45.             context.Rasterizer.SetViewports(viewport);
  46.  
  47.             using (var factory = swapChain.GetParent<SlimDX.DXGI.Factory>())
  48.             {
  49.                 factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAltEnter);
  50.             }
  51.  
  52.             form.KeyDown += (o, e) =>
  53.             {
  54.                 if (e.Alt && e.KeyCode == Keys.Enter)
  55.                 {
  56.                     swapChain.IsFullScreen = !swapChain.IsFullScreen;
  57.                 }
  58.                 else if (e.KeyCode == Keys.Escape)
  59.                 {
  60.                     form.Close();
  61.                 }
  62.             };
  63.  
  64.             //RenderTarget renderTarget2D = renderTarget.
  65.  
  66.             MessagePump.Run(form, () =>
  67.             {
  68.                 context.ClearRenderTargetView(renderTarget, new Color4(0.2509804f, 0.2509804f, 0.2509804f));
  69.  
  70.                 //SolidColorBrush b = new SolidColorBrush(renderTarget, new Color4(1f, 1f, 1f), new BrushProperties());
  71.                 //device.beg
  72.  
  73.                 swapChain.Present(0, PresentFlags.None);
  74.             });
  75.  
  76.             renderTarget.Dispose();
  77.             swapChain.Dispose();
  78.             device.Dispose();
  79.         }
  80.     }
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top