2017-04-01 100 views
1

我嘗試啓動C#的DirectX編程本教程: http://www.riemers.net/eng/Tutorials/DirectX/Csharp/Series1/tut2.php 我使用Visual Studion社區2015年,我的代碼是這樣的:簡單的C#的DirectX例如

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using Microsoft.DirectX; 
using Microsoft.DirectX.Direct3D; 

namespace DirecxTest01 
{ 
    public partial class Form1 : Form 
    { 
     private Device device; 
     public Form1() 
     { 
      InitializeComponent(); 
      InitializeDevice(); 
     } 
     private void InitializeDevice() 
     { 
      PresentParameters presentParams = new PresentParameters(); 
      presentParams.Windowed = true; 
      presentParams.SwapEffect = SwapEffect.Discard; 
      device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); 
     } 
     private void Form1_Paint(object sender, PaintEventArgs e) 
     { 
      device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0); 
      device.Present(); 
     } 
    } 
} 

我也addesd引用的所有DirectX的DLL。當我運行程序時什麼都沒有發生,甚至沒有窗口窗口。沒有錯誤信息,只是沒有。我試圖逐行評論DirectX Stuff。即使有這樣的代碼PROGRAMM掛斷:

private void InitializeDevice() 
    { 
     PresentParameters presentParams = new PresentParameters(); 
     //presentParams.Windowed = true; 
     //presentParams.SwapEffect = SwapEffect.Discard; 
     //device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); 
     } 

當我出去評論

//PresentParameters presentParams = new PresentParameters();

來,至少Windowas形式apperears。

我的代碼有什麼問題?

回答

0

您正在使用的教程適用於不贊成使用的Managed DirectX 1.1程序集。它們是爲.NET 1.1編寫的,並且與.NET 4.0或更高版本不兼容 - 儘管有一些黑客試圖使它們工作。

  • 因爲由託管DirectX 1.1支持D3DX9的最後一個版本是2006年4月,它利用的HLSL編譯器的一個非常過時的版本。
  • Managed DirectX 1.1程序集僅32位,因此您無法從x64本機.NET應用程序(Windows x64系統上的/platform:anycpu)使用它們。您必須使用/platform:x86構建並保持在32位應用程序的2 GB內存空間範圍內。
  • 的組件只支持舊的DirectX API集,與Direct3D9Ex,Direct3D的10.x中,Direct3D的11的Direct2D,DirectWrite的,DXGI,D3DX10,D3DX11,XAUDIO2,XACT,XINPUT不支持等
  • 由於管理DirectX 2.0從未以生產形式發佈,Managed DirectX 1.1程序集仍然反映了.NET 1.1設計原則,不支持或不使用.NET 2.0構造。
  • 與.NET 2.0(以及2.0運行時的.NET 3.0和.NET 3.5擴展)兼容的託管DirectX 1.1與.NET 4.0不兼容
  • 受管DirectX 1.1程序集僅由舊版DirectSetup和舊版DirectX SDK。

總之:不要使用它們。使用像SharpDX,SlimDX或Unity3D這樣更現代的東西。

請參閱DirectX and .NETWhere is the DirectX SDK?