标签: sharpdx

SharpDX:启用BlendState

我正试图让"SharpDX.Direct3D11.DeviceContext.OutputMerger.Blendstate"工作.没有这个,我有一个很好的场景(Polygones上有纹理,对于Spaceshooter).我在过去的三年里完成了OpenGL Graphics,所以我认为它可能就像在OpenGL中一样简单 - 只需启用Blending并设置正确的Dst/Src模式.但是如果我设置一个新的BlendStateDescription,所有输出都是黑色,即使"RenderTarget [x] .IsBlendEnabled"设置为"false".我搜索了一个教程或其他东西,并找到一个 - 但它使用效果.所以我的问题很简单 - 我是否必须在SharpDX中使用技术和效果?没有其他方法可以简单混合?

这就是我所做的:

mBackBuffer = Texture2D.FromSwapChain<Texture2D>(mSwapChain, 0);
mRenderView = new RenderTargetView(mDevice, mBackBuffer);
mContext.OutputMerger.SetTargets(mDepthStencilView, mRenderView);
mContext.OutputMerger.SetBlendState(new BlendState(mDevice, new BlendStateDescription()), new SharpDX.Color4(1.0f), -1);

mContext.OutputMerger.BlendState.Description.RenderTarget[0].IsBlendEnabled = true;
mContext.OutputMerger.BlendState.Description.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
mContext.OutputMerger.BlendState.Description.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha;
mContext.OutputMerger.BlendState.Description.RenderTarget[0].BlendOperation = BlendOperation.Add;           
mContext.OutputMerger.BlendState.Description.RenderTarget[0].SourceAlphaBlend = BlendOption.One;            
mContext.OutputMerger.BlendState.Description.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;          
mContext.OutputMerger.BlendState.Description.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;          
mContext.OutputMerger.BlendState.Description.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;           
Run Code Online (Sandbox Code Playgroud)

并且,即使只是简单地做:

mContext.OutputMerger.SetBlendState(new BlendState(mDevice, new BlendStateDescription()), new SharpDX.Color4(1.0f), -1);
mContext.OutputMerger.BlendState.Description.RenderTarget[0].IsBlendEnabled = false;
Run Code Online (Sandbox Code Playgroud)

输出全是黑色..也许我只需更改像素着色器中的某些内容?

directx windows-8 sharpdx

2
推荐指数
1
解决办法
2933
查看次数

SharpDX:从DataStream初始化Texture2D失败(虽然Texture1D工作正常)

我正在尝试从内存数据创建SharpDX.Direct3D11.Texture2D但总是得到SharpDXException(HRESULT:0x80070057,"参数不正确.").我为此目的使用了Texture1D,之前可以毫无问题地创建它.

我已将代码减少到此样本,但仍会产生异常:

using (var device = new Device(DriverType.Hardware, DeviceCreationFlags.Debug)) {
    // empty stream sufficient for example
    var stream = new DataStream(16 * 4, true, true);

    var description1D = new Texture1DDescription() {
        Width = 16,
        ArraySize = 1,
        Format = Format.R8G8B8A8_UNorm,
        MipLevels = 1,
    };
    using (var texture1D = new Texture1D(device, description1D, new[] { new DataBox(stream.DataPointer) })) {
        // no exception on Texture1D
    }

    var description2D = new Texture2DDescription() {
        Width = 8,
        Height = 2,
        ArraySize = 1,
        MipLevels = …
Run Code Online (Sandbox Code Playgroud)

c# directx textures directx-11 sharpdx

2
推荐指数
1
解决办法
3321
查看次数

XNA,DirectX和Monogame,SharpDX之间的区别

我一直在学习C#.我基本上来自非开发背景(意味着我不知道不同编程工具的实际工作).我刚开始学习Monogame,但很少有事情让我困惑.

首先它说Monogame是XNA的开源实现.这是什么意思? - 它使XNA开源 - 或者采用XNA的功能并实现它本身但具有与XNA相同的功能名称等 - 其他

是允许还是合法的吗?如果是,我可以在任何应用程序商店中复制任何应用程序并制作我自己的版本吗?它合法的需要有什么不同?

其次,当我安装Monogame时,还安装了SharpDX.当我搜索它时,我发现SharpDX是管理DirectX(我从未在DirectX中工作过).Monogame和SharpDX(或XNA和DirectX)之间有什么联系,我不能单独使用monogame或SharpDX?管理DirectX意味着什么?

第三,除了Xamarin提供的框架之外,还有更多的跨平台C#框架吗?我找不到更多.

c# monogame sharpdx

2
推荐指数
2
解决办法
6774
查看次数

D2DERR_RECREATE_TARGET错误是否真的意味着我必须跟踪渲染目标创建的所有内容?

我每小时多次随机获取此错误(D2DERR_RECREATE_TARGET),在阅读该错误后,我似乎无法避免它.我使用的是SharpDX,它是"一个在.Net平台下提供完整DirectX API的开源项目".

根据microsoft的文档:"Direct2D通过从EndDraw方法返回错误代码D2DERR_RECREATE_TARGET来指示丢失的设备.如果收到此错误代码,则必须重新创建渲染目标和所有依赖于设备的资源."

这是否真的意味着我需要跟踪渲染目标创建的每个依赖于设备的资源(有很多!)并停止使用或者我错了吗?或者也许这里有人知道解决这个错误的方法?

c# c++ directx direct2d sharpdx

2
推荐指数
1
解决办法
1034
查看次数

SharpDX.Windows 丢失?

首先,如果这是问这个问题的错误地方,我深表歉意,我在其他任何地方都找不到答案。

我已经将 SharpDX 引用导入到我的 C# 项目中,但是,SharpDX.Windows 引用不存在。我试过从网站下载它并使用 NuGet,但是对于它们两者,参考都不存在。

有谁知道如何解决这个问题或导致问题的原因是什么?

c# sharpdx

2
推荐指数
1
解决办法
3572
查看次数

MF SinkWriter 写入示例失败

我正在尝试使用 MediaFoundation 将 ID3D11Texture2D 编码为 mp4。下面是我目前的代码。

初始化接收器写入器

private int InitializeSinkWriter(String outputFile, int videoWidth, int videoHeight)
    {
        IMFMediaType mediaTypeIn = null;
        IMFMediaType mediaTypeOut = null;
        IMFAttributes attributes = null;

        int hr = 0;

        if (Succeeded(hr)) hr = (int)MFExtern.MFCreateAttributes(out attributes, 1);
        if (Succeeded(hr)) hr = (int)attributes.SetUINT32(MFAttributesClsid.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 1);            
        if (Succeeded(hr)) hr = (int)attributes.SetUINT32(MFAttributesClsid.MF_LOW_LATENCY, 1);

        // Create the sink writer 
        if (Succeeded(hr)) hr = (int)MFExtern.MFCreateSinkWriterFromURL(outputFile, null, attributes, out sinkWriter);

        // Create the output type
        if (Succeeded(hr)) hr = (int)MFExtern.MFCreateMediaType(out mediaTypeOut);
        if (Succeeded(hr)) hr = …
Run Code Online (Sandbox Code Playgroud)

c# directx dxgi sharpdx ms-media-foundation

2
推荐指数
1
解决办法
2161
查看次数

SharpDX在Windows Phone 8中加载纹理

我正在创建一个Windows Phone 8应用程序,我正在使用SharpDX来加载纹理.

我试图加载PNG,Content.Load<Texture2D>("filename.png")但我有错误,我已经意识到Windows Phone 8中的SharpDX只接受DDS纹理,不接受PNG/JPEG/BMP等.我已经将我的PNG转换为DDS使用texconv filename.png并将文件添加到我的解决方案就像我在我的项目中使用的其他文件(我可以正确加载).当我运行我的应用程序时,我得到一个例外:

{SharpDX.Serialization.InvalidChunkException: Unexpected chunk [DDS /0x20534444] instead of [TKFX/0x58464B54] at SharpDX.Serialization.BinarySerializer.BeginChunk(FourCC chunkId)}

好吧,我已经使用该texconv工具将有效的PNG转换为DDS .从我看到的,它是一个文件格式错误,并且fourCC代码对应于DDS,这是应该的.但是SharpDX期望TKFX格式(工具包效应?)而不是DDS.为什么?我试图加载纹理Content.Load<Texture2D>没有Content.Load<Effect>(我也有它加载着色器,它完美地工作).

如果有人发现如何加载PNG而不是DDS,那就更好了!

texture2d sharpdx windows-phone-8 dds-format

1
推荐指数
1
解决办法
1465
查看次数

在针对Win8.1 + Metro时使用SharpDX保存Texture2D?

我正在尝试将用户生成的Texture2D保存到磁盘,但是在定位DirectX11.1/Win8.1/Metro时看起来无法实现此标准的标准方法.没有ToStream/FromStream,也没有用于将纹理写入磁盘的DX11方法.

任何想法或建议?

c# directx directx-11 sharpdx windows-8.1

1
推荐指数
1
解决办法
1790
查看次数

SharpDX:如何在Winforms窗口中放置SharpDX窗口?

我实际上是试着将SharpDX Window放在Winforms窗口中,如下面的视频所示:http://www.youtube.com/watch?v = g -JupOxwB-k

在SharpDX中,这种方法不起作用.任何人都可以告诉我如何轻松地做到这一点?

sharpdx

1
推荐指数
1
解决办法
8292
查看次数

如何在C#应用程序中使用xbox one控制器

在C#中已经存在大量使用xbox 360控制器的信息,但我没有找到xbox one控制器的信息.

我需要非常基本的操作,特别是操纵杆和触发器值.

大多数在线信息都是针对C++应用程序的,但我不想尝试编写自定义库,而是想使用像SharpDX这样的东西.我如何在我的应用程序中使用它?

注意:我发布此信息是为了分享我找到的信息,以及为自己记录我的发现.我很想听听其他方法将控制器输入到.NET应用程序中.

c# sharpdx

1
推荐指数
1
解决办法
6842
查看次数