2010-11-18 70 views
1

我想在DLL中創建一個託管DirectX 9設備,然後使用該DLL將場景渲染到屏幕外表面。我知道如何做離屏渲染,但我的問題是:DirectX 9 - 創建設備並渲染紋理裏面的DLL?

是否有可能在DLL中創建directx設備?

微弱嘗試#1(InvalidCallException):

Device device = new Device(0, DeviceType.Hardware, null, CreateFlags.SoftwareVertexProcessing, presentParams); 

微弱嘗試#2(InvalidCallException):可用

Device device = new Device(0, DeviceType.Hardware, new IntPtr(0), CreateFlags.SoftwareVertexProcessing, presentParams); 

的裝置構造函數重載有:

public Device(int, DeviceType, Control, CreateFlags, PresentParameters[]); 
public Device(int, DeviceType, IntPtr, CreateFlags, PresentParameters[]); 

任何幫助可能很有可能可以讓我的一天!

+0

提醒我如何通常創建設備,如果它不在DLL中。 – BeemerGuy 2010-11-18 04:11:05

+0

而不是將'Control'對象或'IntPtr'句柄傳入'null'或'new IntPtr(0)'中,而不是傳遞給那個控制對象,即'渲染窗口' – tbridge 2010-11-18 04:14:18

回答

0

找到了答案。我創建了一個隱藏的控件,適當地設置它的寬度和高度,然後將其設置爲目標。完美的作品。對於那些誰可以在此絆倒以後這裏是代碼:

// Create the hidden control 
Control hiddenControl = new Control(); 
control.Width = width; 
control.Height = height; 
control.Visible = false;   // Just for good measure, it wouldn't be displayed anyways 

// Present Parameters 
PresentParamaters presentParams = new PresentParamaters(); 
presentParams.SwapEffect = SwapEffect.Discard; 
presentParams.Windowed = true; 

// Create the device 
Device device = new Device(0, DeviceType.Hardware, hiddenControl, CreateFlags.SoftwareVertexProcessing, presentParams); 

這就是所有需要,假設就像我說要渲染到紋理之前。我不確定如果實際渲染到此控件,會發生什麼(如果有的話)。