Jump to content
  • Advertisement
Sign in to follow this  
dingojohn

OpenGL SlimDX: Device creation question

This topic is 3823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I'm currently digging into C# SlimDX and I now have a question regarding the construction of a device. Note that I am also new to MDX and D3D in general; all prior 3d work has been done in OpenGL, and I guess this question could just as easily apply to MDX. Reading the "CreateDevice" tutorial in the docs, I stumbled upon this:
public static void InitializeD3D()
        {
            // Create a new PresentParameters object and fill in the necessary fields.
            PresentParameters presentParams = new PresentParameters();

            // Below are the required bare mininum, needed to initialize the D3D device.
            presentParams.BackBufferHeight = Window.ClientRectangle.Height;         // BackBufferHeight, set to  the Window's height.
            presentParams.BackBufferWidth = Window.ClientRectangle.Width;           // BackBufferWidth, set to  the Window's width.
            presentParams.DeviceWindowHandle = Window.Handle;                       // DeviceWindowHandle, set to  the Window's handle.

            // Create the device.
            D3DDevice = new Device(0, DeviceType.Hardware, Window.Handle, CreateFlags.HardwareVertexProcessing, presentParams);
        }
The question might be silly but I don't really get it. When working with a "bare minimum" why do I have to 1) set presentParameters.Handle to Window.Handle, and 2) use both presentParameters and Window.Handle as arguments? Why can't the constructor just accept the presentParamenters argument and take the DeviceVideoHandle from there? When would you want to use a different handle? Thanks in advance, and great project you guys are working at. Also, as an off topic sidenote does the Windows Forms also work with Mono on all platforms? I'm just thinking in terms of making my program work with both SlimDX and OpenGL for the sake of learning to abstract rendering away from logic.

Share this post


Link to post
Share on other sites
Advertisement
Presentation parameters are used for more than just device creation; they may be used for device reset, for example. The SlimDX constructors for Device in D3D9 take a window handle because the unmanaged ones do. The windows may have different uses -- the handle sent to the Device constructor is the focus window, which is used to alert D3D that window events have occured -- particularly when doing foreground/background transitions.

The window in the presentation parameters is the device window, which is where D3D draws the picture. The two windows must be the same when full screen, but need not be when in windowed mode. Present() can also override the device window. There's some weirdness involved, as well, in multiple fullscreen (multimonitor) setups, but offhand I don't remember it. The documentation (unmanaged) on MSDN explains in more detail.

Quote:

Also, as an off topic sidenote does the Windows Forms also work with Mono on all platforms?

It's workable, last I heard, but not pleasant.

Quote:

I'm just thinking in terms of making my program work with both SlimDX and OpenGL for the sake of learning to abstract rendering away from logic.

Waste of time, seperating rendering and logic can be done without bothering with the overhead and pain of the (all in all, rather useless) task of supporting multiple rendering APIs. If you want to compile your code for multiple platforms, stick with OpenGL.

Share this post


Link to post
Share on other sites
Thanks for the reply. It clarified things a bit.

You are probably right about the fact that it would be a waste of time to support both rendering APIs- the idea, however, appeals to me. I could just stick to OpenGL but I would still like to try and use SlimDX for the sake of the somewhat OO API and also the Math classes*, audio and such.


*) I really miss jyk's CML from C++ :

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!