[英]Simple c# directX example
I try to start c# directX programming with this tutorial: http://www.riemers.net/eng/Tutorials/DirectX/Csharp/Series1/tut2.php I'm using visual Studion Community 2015, my code is like this:我尝试使用本教程开始 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();
}
}
}
I also addesd References to all the DirectX dll's.我还添加了对所有 DirectX dll 的引用。 Whe I run the Programm nothing happened, not even the Form Window appers.
当我运行程序时什么也没发生,甚至窗体窗口也没有。 No error message, just nothing.
没有错误消息,只是什么都没有。 I tried to comment out the DirectX Stuff line by line.
我试图逐行注释掉 DirectX Stuff。 Even with this code the Programm hangs up:
即使使用此代码,程序也会挂断:
private void InitializeDevice()
{
PresentParameters presentParams = new PresentParameters();
//presentParams.Windowed = true;
//presentParams.SwapEffect = SwapEffect.Discard;
//device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
}
When I out comment当我发表评论
//PresentParameters presentParams = new PresentParameters();
to, at least the Windowas Form apperears.到,至少 Windowas 窗体出现了。
Whats wrong with my code?我的代码有什么问题?
The tutorial you are using is for the deprecated Managed DirectX 1.1 assemblies.您正在使用的教程适用于已弃用的托管 DirectX 1.1 程序集。 They were written for .NET 1.1, and are not compatible with .NET 4.0 or later--although there are some hacks out there to try to make them work.
它们是为 .NET 1.1 编写的,与 .NET 4.0 或更高版本不兼容——尽管有一些黑客试图让它们工作。
/platform:anycpu
on a Windows x64 system)./platform:anycpu
)中使用它们。 You must build with /platform:x86
and stay within the limits of the 2 GB memory space of 32-bit applications./platform:x86
构建并保持在 32 位应用程序的 2 GB 内存空间的限制内。 In short: Don't use them.简而言之:不要使用它们。 Use something more modern like SharpDX, SlimDX, or Unity3D.
使用更现代的东西,比如 SharpDX、SlimDX 或 Unity3D。
See DirectX and .NET and Where is the DirectX SDK?请参阅DirectX 和 .NET以及DirectX SDK 在哪里?
I know this is an old thread but I ran into the exact problem and the solution of "don't use DirectX" is not an option because I am working on an existing system without the option of upgrading all the relevant parts using the DirectX dlls.我知道这是一个旧线程,但我遇到了确切的问题,并且“不使用 DirectX”的解决方案不是一个选项,因为我在现有系统上工作,而没有使用 DirectX dll 升级所有相关部分的选项.
Fortunately I found a solution to work with the old DirectX assemblies on a .NET Framework version 4.6.1.幸运的是,我找到了一个解决方案,可以在 .NET Framework 4.6.1 版上使用旧的 DirectX 程序集。
Simply add this in the App.config file (right below the </appSettings>
):只需将其添加到 App.config 文件中(在
</appSettings>
正下方):
<startup useLegacyV2RuntimeActivationPolicy="true" >
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.61"/>
</startup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.