• Advertisement

Archived

This topic is now archived and is closed to further replies.

D3DWindow class implementation (C#)

This topic is 5063 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

I''m developing my first C# D3D9 wrapper engine and have a few questions. My goal is to write a single D3DWindow class which inherits a normal Windows form so that it acts as my d3d class and the window all in one. This will make it easy to import to future games I create without dealing with any windows or forms. This means Main() will be external to this class. I''ve looked over a few example projects and they all have their main function in the window form. The pseudo code for the design of these projects are like this.
Main()
{
    Application.Run(new Form1());
}

Form1_Load()
{
    this.Show();
    Application.DoEvents();

    //Init D3D and other Game variables

    //Main loop (if fullscreen)

    //Dispose objects
    this.Close();
}
 
How do I apply this to my design where Main() is in a separate user-made class? This is what I have so far.
//D3DWindow.cs // Imported D3D9 Window class
//Game.cs      // User-made class

public class Game
{
    static D3DWindow graphics = null;
    // other

    Main()
    {
        // ????
    }
}

public class D3DWindow : Form
{
    // variables

    public D3DWindow(int width, int height) // Constructor
    {
        // set form properties
        // set presentparameters
        // initialise device
    }
}
 
What do I need in order to be able to type something like " graphics = new D3DWindow(800, 600);" in Main to start the program? Is it neccesary to use Application.Run and Form_Load in this situation? Thanks for your time.

Share this post


Link to post
Share on other sites
Advertisement
First, why are you manually formatting your post? The text on this forum wraps to fill visitors'' web browsers, which makes for far more comfortable reading. Please stop.

You can just rip Main out of that class and plop it into another. It''s static, so it has no access to non-static class members anyway - note that it explicitly allocates a Form1 instance as a parameter to Application.Run().

Share this post


Link to post
Share on other sites
quote:
Original post by Proudest
What do I need in order to be able to type something like "graphics = new D3DWindow(800, 600);" in Main to start the program?
If you''re going to make the form the focal window of the application (ie, when that form is deleted/closed the application exits), there''s no need for the graphics reference. Simply do Application.Run( new D3DWindow(800, 600) );

quote:
Is it neccesary to use Application.Run and Form_Load in this situation?
Read this to understand the purpose of Application.Run.

There are other issues at work here. Despite your noble intentions, you haven''t really gotten a handle on the .NET Framework or Windows Forms, and it shows. I''d recommend fully understanding them before proceding.

Share this post


Link to post
Share on other sites
Sorry for the formatting, I typed up this post in notepad earlier then pasted it. I''ve decided to separate the window and D3D classes and everything is on track except for one thing.

Since my main loop, Main(), and running variable for the loop are outside the scope of the window, how can I use a keydown event to change the running variable?

Is there a way to code my keydown events in in the class which has scope with the running variable? So I can pass the Window for which keys to capture and still have access to the running variable.

Thanks.

Share this post


Link to post
Share on other sites

  • Advertisement