我尝试使用本教程开始c#DirectX编程:http : //www.riemers.net/eng/Tutorials/DirectX/Csharp/Series1/tut2.php我正在使用visual Studion Community 2015,我的代码是这样的:
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还添加了对所有DirectX dll的引用。当我运行程序时,什么都没发生,甚至窗体窗口也没有。没有错误信息,什么也没有。我试图逐行注释掉DirectX Stuff。即使使用此代码,程序也会挂断:
private void InitializeDevice()
{
PresentParameters presentParams = new PresentParameters();
//presentParams.Windowed = true;
//presentParams.SwapEffect = SwapEffect.Discard;
//device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
}
Run Code Online (Sandbox Code Playgroud)
当我发表评论时
//PresentParameters presentParams = new PresentParameters();
至少要出现Windowas表格。
我的代码有什么问题?
您正在使用的教程适用于已弃用的Managed DirectX 1.1程序集。它们是为.NET 1.1编写的,并且与.NET 4.0或更高版本不兼容-尽管那里有一些骇客试图使其正常工作。
/platform:anycpu在Windows x64系统上)使用它们。您必须使用/platform:x8632位应用程序的2 GB内存空间并在此范围之内。简而言之:不要使用它们。使用更现代的工具,例如SharpDX,SlimDX或Unity3D。
请参阅DirectX和.NET,DirectX SDK在哪里?
| 归档时间: |
|
| 查看次数: |
6697 次 |
| 最近记录: |