Sign in to follow this  
LandWarrior

[SlimDX] Render to control instead of Form

Recommended Posts

LandWarrior    100
Hello community, I searched high and low but couldn't find a simple answer. I also searched the forums pretty deep and found nothing... is there already such a post? In this case excuse me ;) My Question is: Is it possible to render to a control instead of the GameWindow (which SlimDX kindly provides in the Samples, which is pretty much a copycat from XNA's approach), or does it have the same issues Shawn remarked in the numerous XNA-related control-rendering threads? I just ask here since I could not find a definite answer, but I assume it is the same problem? The reason is that I want to develop a level editor in Win Forms, but to this point couldn't find either a control that exists that does that, nor an (easy) possbility to do that on my own. In a nutshell, I want to redirect the output from the GameWindow to any control, so that I don't need to write _another_ class just for the Control, which I have to do to follow Shawn's approach. I tried in XNA already, worked but the approach was disliked by Shawn (Team XNA). Is this such an issue? It would be great if you could clarify :) Best Regards, chris

Share this post


Link to post
Share on other sites
Washu    7829
When creating your device pass in the handle of the object you wish to render to (which represents the Win32 HWND). Some controls do not have a handle because they are not actually "window" class objects, however the control best for what you want to do is probably the Panel object, which does.

Note that for a game editor you should be more friendly with how you render things, instead of the traditional game loop (where you take 100% CPU when you can) you should look at implementing a modified one that only renders when the scene is actually updated (unless you're doing a realtime display of the game).

Share this post


Link to post
Share on other sites
LandWarrior    100
Hello again,

great - this was the hint that I need. Of course a realtime-rendering/updating is pretty unimportant in the editor most of the time, so we can just apply null to the gameTime and the components ignore that then :)
So I don't need a render/update loop for the editor!

Thank you, you made my day.

EDIT:

That's strange, I've used a custom IntPtr as the Handle to my Panel instead of the GameWindow.Handle, but I keep always getting this error:

// Exceptions:
// System.InvalidOperationException:
// You can only call this method before the first window is created by your
// Windows Forms application.

It's the method

public static void SetCompatibleTextRenderingDefault(bool defaultValue);

It moans that this method must be called before any IWin32Window calls, but I don't understand, since this method is already called in Program.cs, Main() in the very first line! Is there something I am missing? Twice calling it yields - naturally - the same exception.

EDIT2: Nevermind, problem solved by accident.

I found that in the SlimDX Sample Class "Game.cs", the static constructor is performing just that method "Application.SetCompatibleTextRenderingDefault()" and THAT is causing the exceptions. When commenting this and "Application.EnableVisualstyles()" out, it works just fine.

Best Regards,
chris

[Edited by - LandWarrior on February 17, 2010 12:47:37 PM]

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