设备创建期间出错(D3DERR_NOTAVAILABLE)

时间:2012-09-24 13:02:09

标签: vb.net graphics directx direct3d slimdx

我正在尝试将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

1 个答案:

答案 0 :(得分:1)

我弄清楚我的问题是什么。之前我在DirectX控制面板中弄乱了我的DX9设置,由于某种原因,我启用了“仅限软件”设置,禁用了硬件加速。禁用此选项可解决问题。