开发者

DirectX 9 - Create device and render to texture inside DLL?

I am trying to create a Managed DirectX 9 Device in a DLL and then use that DLL to render scenes to an offscreen surface. I know how to do the offscreen rendering, but my question is:

Is it possible to create a directx device inside a DLL?

Feeble attempt #1 (InvalidCallException):

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

Feeble attempt #2 (InvalidCallException开发者_如何学JAVA):

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

The device constructor overloads available are:

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

Any help could quite possibly make my day!


Found the answer. I created a hidden control, set the width and the height of it appropriately and then set it as the target. Works perfect. For those who may stumble upon this later here is the code:

// 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);

Thats all it takes, assuming like I said before you are rendering to a texture. I'm not sure what (if anything) would happen if you were to actually render to this control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜