Sign in to follow this  

keeping window seperate from renderer

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

In practice, I've always had this problem where I've found it very difficult to keep the coupling between a window and a renderer to a minimum. Conceptually it seems a window should be the target of a renderer, and that's how I would like my design to work too. When I was working with OpenGL and C++ I was able to come up with a couple solutions but I never really cared for any of them. Now that I'm trying to learn C# and Direct3D it seems almost hopeless. Every bit of example code I've come across tosses everything into a class derived from Form and just calls the whole mess "Game" or something simliar. Has anyone with more experience with C# and Direct3D (it wouldnt take much) have a clean solution to this problem or even just some advice?

Share this post


Link to post
Share on other sites
I assume you have some sort of initialization method in your renderer class, for example Init(). You can just make it into something like this:

public bool Init(Control targetControl)
{
...
}


Now the init method takes a Control as a parameter. Remember that all Forms, Buttons, etc. are derived from this class.

Then you can just use targetControl when you initialize Direct3D:


PresentParameters pp = new PresentParameters();
...
pp.DeviceWindowHandle = targetControl.Handle;

Share this post


Link to post
Share on other sites
I dont know if its the "best" way or not, but I enjoy it. We both know that the window should be decoupled so that the renderer is platform independent. So I wrap the window, as you call it, into what I call a viewport. The viewport is platform specific, but thats okay! The viewport has variables to store the width, height, color depth, etc. for the window, as well as some methods for getting the ID for the paltform specific window. The platform specific window is defined in a derived Viewport class, for windows this is called WindowsViewport. The platform specific window class is WindowsWindow, for example, and basically encapsulates the creation and handling of a win32 window. The specific code is handled by a call to Init, which is called from the WindowsViewport.

For D3D, the renderer calls the viewport->GetWindow() method which returns the HWND to the actual window, this is used in the presentparams structure, and should be platform independant, except d3d obviously is a win32 thing. OGL I've not used, but I'm sure its got a similar interface.

Share this post


Link to post
Share on other sites

This topic is 4377 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.

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