我正在尝试将SlimDX设备创建教程从DX11转换为DX9。这是一个非常简单的教程,您可以在其中创建一个窗口,添加 dx9 设备并用纯色填充屏幕。但是,当我尝试创建设备时,我遇到了一个D3DERR_NOTAVAILABLE
错误。所有代码似乎都有意义,它看起来与示例中使用的 C# 代码非常相似。有什么想法吗? 注意:我创建了 BaseDisplay
类的实例,并在另一个类中调用 InitSlimDX
方法。
Imports SlimDX.Windows
Imports SlimDX.Direct3D9
Imports SlimDX
Imports Device = SlimDX.Direct3D9.Device
Imports Resource = SlimDX.Direct3D9.Resource
Imports System.Windows.Forms.ThreadExceptionDialog
Imports System.IO
Public Class BaseDisplay
Inherits RenderForm
'SlimDX Class Vars
Protected device As Device = Nothing
Protected backBuffer As Surface
Protected presentParams As PresentParameters
Public Sub New()
Show()
End Sub
Public Sub InitSlimDX()
Dim d3d As Direct3D = New Direct3D()
Dim primaryAdaptor As AdapterInformation = d3d.Adapters().First()
presentParams = New PresentParameters()
With presentParams
.BackBufferWidth = Me.ClientSize.Width
.BackBufferHeight = Me.ClientSize.Height
End With
Me.device = New Device(d3d, primaryAdaptor.Adapter, DeviceType.Hardware, Me.Handle, CreateFlags.HardwareVertexProcessing, presentParams)
Me.device.BeginScene()
backBuffer = device.GetBackBuffer(0, 0)
Me.device.ColorFill(backBuffer, New Color4(Color.CornflowerBlue))
Me.device.EndScene()
Me.device.Present()
End Sub
Public Overloads Sub Dispose()
device.Dispose()
MyBase.Dispose()
End Sub
End Class
我弄清楚了我的问题是什么。早些时候,我在DirectX控制面板中弄乱了DX9设置,并且由于某种原因,我启用了禁用硬件加速的"仅软件"设置。禁用此选项解决了此问题。