Sign in to follow this  
Trillian

[MDX] Setupping D3D

Recommended Posts

Hello! I'm starting to work with MDX now using C#. I'm trying to setup a simple window. The thing is, I don't want to create a class that inherits from System.Windows.Forms.Form, like most tutorials I saw where doing. Instead, I want to have a class with a System.Windows.Forms.Form instance as a data member. I'm currently having two problems : my "game loop" freezes the app (window does not get updated) and I cannot create my D3D device. Here's my code :
using WinForms = System.Windows.Forms;
using D3D = Microsoft.DirectX.Direct3D;

namespace Whatevar
{
    internal sealed class Program
	{
        private WinForms.Form _window;
        private D3D.Device _d3dDevice;
        private D3D.PresentParameters _d3dPP = new D3D.PresentParameters();

        private void Run()
        {
            _window = new WinForms.Form();
            _window.ClientSize = new System.Drawing.Size(800, 600);
            _window.Text = "CryoSharp test window";
            _window.Visible = true;
            _d3dPP.EnableAutoDepthStencil = false;
            _d3dPP.BackBufferCount = 1;
            _d3dPP.BackBufferFormat = D3D.Format.X8R8G8B8;
            _d3dPP.BackBufferWidth = 800;
            _d3dPP.BackBufferHeight = 600;
            _d3dPP.DeviceWindow = _window;
            _d3dPP.Windowed = true;
            _d3dDevice = new D3D.Device(0, D3D.DeviceType.Hardware, _window, D3D.CreateFlags.HardwareVertexProcessing, _d3dPP);

            while(_window.Created)
            {
                _window.Update();
            }
        }

        // Main
        static int Main()
        {
            Program prog = new Program();
            prog.Run();
            return 0;
        }
	};
}


There are two problems here. First : my "while" loop isn't right (do I have to use unmanaged "PeekMessage"?) Second : "new D3D.Device" generates an InvalidCallException. I don't really know why these two problems show up, could anyone help? By the way, is MDX deprecated in favor of XNA? Is MDX's development discontinued? Is there a way to set the MDX debug output level like you can with DX? [Edited by - Trillian on June 10, 2007 8:17:28 AM]

Share this post


Link to post
Share on other sites
1) In the while loop call WinForms.Application.DoEvents which is similar to PeekMessage. Plus you never actually render anything(not even a blank screen) which is probably why your program appears to be frozen.

2) Don't specify the backbuffer dimensions or format for a windowed device. For a windowed device the backbuffer will be set to the windows client area and the format is equal to the monitors display setting.

3) MDX will no longer be updated, however IMO it is a more "direct" wrapper of DirectX than XNA and has things that XNA doesn't, so I wouldn't consider it deprecated.

4) The debug settings for DX should work the same for MDX since it is just a wrapper. You can also use the utility program PIX which comes with the SDK.

5) <nitpicky> Your naming convention is quite horrible, being everything with an underscore is probably the opposite of the standard C# naming convention. </nitpicky>

Share this post


Link to post
Share on other sites
Thanks for all the info!

The thing is... I still have some problems! First, I made the following changes :


_d3dPP.BackBufferFormat = D3D.Format.Unknown;
_d3dPP.BackBufferWidth = 0;
_d3dPP.BackBufferHeight = 0;
// [...]
WinForms.Application.DoEvents();



The problem is, my app still doesn't get to the main loop as the "new D3D.Device" still throws an InvalidCallException and I don't know why!

I appreciate your comment on my naming convention. In fact, you might not have guessed about it but I was actually trying to be conforming to MS conventions! I've looked at the documents on msdn about proposed naming schemes but there was absolutely nothing about private members. I thought I had seen the _camelCase convention somewhere so I decided to pick it up. I just wanted anything but yet another PascalCase convention (it is used for EVERYTHING, I have trouble with name conflicts now).

If you know what the "official" naming convention for private members, I'd like to know it.

Thanks!

Share this post


Link to post
Share on other sites
just leave them out, like this:


_d3dPP.EnableAutoDepthStencil = false;
_d3dPP.BackBufferCount = 1;
_d3dPP.SwapEffect = D3D.SwapEffect.Discard; // <- add swap effect
_d3dPP.Windowed = true;
_d3dDevice = new D3D.Device(0, D3D.DeviceType.Hardware, _window, D3D.CreateFlags.HardwareVertexProcessing, _d3dPP);



Also make sure to add in the swap effect type and check to make sure your device supports HardwareVertexProcessing.

About the naming convention, I always use PascalCase as it's what all Microsofts APIs use. I think though if you have a private member with a public property, that the member should be camelCase and the property PascalCase.

Share this post


Link to post
Share on other sites
Thank you, I got it working now!

Thanks also for the naming convention thing. I'll simply remove the underscores before my camelCases. This might create problems with camelCase method arguments but I'll try to sort it out :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this