DockContent WeifenLuo Problem

Jo0oker

02-02-2010 22:32:06

Hello,
I want to create a mogre window in a weifenlou(DockPanel Suite) form.
Weifenlou is a way for special Windowsforms.

Here an example:

But when i create a mogre window in weifenlou, it is only gray.

here is the code for creating the window:

public partial class TestForm : Form
{
#region Private Member

//GfxManager
GFXManager myGFXManager;

public ITOgre test;
GFXWindow t;

#endregion

#region Public Member

/// <summary>
/// GFX Manager
/// </summary>
public GFXManager GFXManager
{
get { return myGFXManager; }
set { myGFXManager = value; }
}

#endregion

public TestFormForm()
{
InitializeComponent();

//GfxManager
myGFXManager = new GFXManager();

t = new GFXWindow();
test = myGFXManager.TOgreManager.GetNew(t, 8, "MainDevice");
}

private void TestFormForm_Shown(object sender, EventArgs e)
{


t.MdiParent = this;
t.Show(MainDockPanel);
t.DockState = DockState.Document;

}
}


GFXWindow t; Is the important window...

And here is the TOgre source:

#region Private member
//
private Camera myCamera;
private Root myRoot;
private SceneManager mySceneMgr;
private Viewport myViewport;
private RenderWindow myWindow;
private RenderSystem myRenderSystem;
private Form myForm;
private DockContent myDockContent;
//Constante
private const string CameraType = "Camera";
private const string SceneManagerName = "Main SceneManager";

#endregion

#region OgreDevice
/// <summary>
/// Creats a Ogredevice
/// </summary>
public TOgre(string Title, uint Width, uint Height, bool IsFullScreen, int AntiAliasing)
{
//Create window
myForm = new Form();

//Agree window properties
myForm.Size = new Size(Convert.ToInt32(Width), Convert.ToInt32(Height));
myForm.Text = Title;
myForm.AutoScaleMode = AutoScaleMode.Font;
myForm.FormBorderStyle = FormBorderStyle.Fixed3D;
myForm.StartPosition = FormStartPosition.CenterScreen;
myForm.MaximizeBox = false;
myForm.ResumeLayout(false);

//Create root
myRoot = new Root();

//Resources
LoadStandardResources();

//RenderSystem
myRenderSystem = myRoot.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
myRoot.RenderSystem = myRenderSystem;
myRenderSystem.SetConfigOption("Full Screen", "No");
myRenderSystem.SetConfigOption("Video Mode", "800 x 600 @ 32-bit colour");

//Create renderwindow
CreateRenderWindow(myForm.Handle, Title, Width, Height, IsFullScreen, AntiAliasing);

//create resourcesmanager
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

//Create Scenemanager
mySceneMgr = myRoot.CreateSceneManager("TerrainSceneManager");//SceneType.ST_GENERIC, SceneManagerName);

//Create camera
CreateCamera();

//Create viewport
CreateViewport();

//Dispose event
myForm.Disposed += new EventHandler(OgreDevice_Disposed);

//Shows the window
myForm.Show();

//
TextureManager.Singleton.DefaultNumMipmaps = 5;
}

public TOgre(WeifenLuo.WinFormsUI.Docking.DockContent DockContent, int AntiAliasing)
{
myDockContent = DockContent;

//Create root
myRoot = new Root();

//Resources
LoadStandardResources();

//RenderSystem
myRenderSystem = myRoot.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
myRoot.RenderSystem = myRenderSystem;
myRenderSystem.SetConfigOption("Full Screen", "No");
myRenderSystem.SetConfigOption("Video Mode", "800 x 600 @ 32-bit colour");

//Create renderwindow
CreateRenderWindow(myDockContent.Handle, myDockContent.Text, Convert.ToUInt32(myDockContent.Size.Width), Convert.ToUInt32(myDockContent.Size.Height), false, AntiAliasing);

//create resourcesmanager
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

//Create Scenemanager
mySceneMgr = myRoot.CreateSceneManager("TerrainSceneManager");//SceneType.ST_GENERIC, SceneManagerName);

//Create camera
CreateCamera();

//Create viewport
CreateViewport();

//Dispose event
myDockContent.Disposed += new EventHandler(OgreDevice_Disposed);

//
TextureManager.Singleton.DefaultNumMipmaps = 5;
}
#endregion

#region Frame listener
public void SetFrameStartListener(Mogre.FrameListener.FrameStartedHandler FrameListner_Void)
{
myRoot.FrameStarted += new FrameListener.FrameStartedHandler(FrameListner_Void);
}
#endregion

#region Create stuff
/// <summary>
/// Creats a new Viewport
/// </summary>
private void CreateViewport()
{
myViewport = myWindow.AddViewport(myCamera);
myViewport.BackgroundColour = new ColourValue(0f, 0f, 0f, 1f);
}

/// <summary>
/// Creats a new Camera
/// </summary>
private void CreateCamera()
{
myCamera = mySceneMgr.CreateCamera(CameraType);
myCamera.NearClipDistance = 1f;
myCamera.Position = new Vector3(0f, 0f, 0f);
myCamera.LookAt(Vector3.ZERO);
}

/// <summary>
/// Creates a new RenderWindow
/// </summary>
/// <param name="ParentHandle"></param>
/// <param name="Title"></param>
/// <param name="Width"></param>
/// <param name="Height"></param>
/// <param name="IsFullScreen"></param>
private void CreateRenderWindow(IntPtr ParentHandle, string Title, uint Width, uint Height, bool IsFullScreen)
{
myRoot.Initialise(false, Title);
NameValuePairList miscParams = new NameValuePairList();
if (ParentHandle != IntPtr.Zero)
{
miscParams["externalWindowHandle"] = ParentHandle.ToString();
myWindow = myRoot.CreateRenderWindow(Title + " [Direct3D9]", Width, Height, IsFullScreen, miscParams);
}
else
{
miscParams["externalWindowHandle"] = myForm.Handle.ToString();
myWindow = myRoot.CreateRenderWindow(Title + " [Direct3D9]", Width, Height, IsFullScreen, miscParams);
}
}

/// <summary>
/// Creates a new RenderWindow
/// </summary>
/// <param name="ParentHandle"></param>
/// <param name="Title"></param>
/// <param name="Width"></param>
/// <param name="Height"></param>
/// <param name="IsFullScreen"></param>
private void CreateRenderWindow(IntPtr ParentHandle, string Title, uint Width, uint Height, bool IsFullScreen, int AntiAliasing)
{
myRoot.Initialise(false, Title);
NameValuePairList miscParams = new NameValuePairList();
if (ParentHandle != IntPtr.Zero)
{
miscParams["externalWindowHandle"] = ParentHandle.ToString();
miscParams["FSAA"] = AntiAliasing.ToString();
myWindow = myRoot.CreateRenderWindow(Title + " AA 16", Width, Height, IsFullScreen, miscParams);
}
else
{
miscParams["externalWindowHandle"] = myForm.Handle.ToString();
miscParams["FSAA"] = AntiAliasing.ToString();
myWindow = myRoot.CreateRenderWindow(Title + " AA 16", Width, Height, IsFullScreen, miscParams);
}
}
#endregion

#region Events
/// <summary>
/// If the form is closed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OgreDevice_Disposed(object sender, EventArgs e)
{
myRoot = null;
myWindow = null;
myCamera = null;
myViewport = null;
mySceneMgr = null;
}
#endregion

#region Public properties

public Camera Camera
{
get
{
return myCamera;
}
set
{
myCamera = value;
}
}

public RenderWindow RenderWindow
{
get
{
return myWindow;
}
set
{
myWindow = value;
}
}

public Root Root
{
get
{
return myRoot;
}
}

public SceneManager SceneManager
{
get
{
return mySceneMgr;
}
set
{
mySceneMgr = value;
}
}

public Viewport Viewport
{
get
{
return myViewport;
}
set
{
myViewport = value;
}
}

public Form Form
{
get { return myForm ; }
set { myForm = value; }
}

public DockContent WeifenLuoDockContent
{
get { return myDockContent; }
set { myDockContent = value; }
}
#endregion

#region Standard resources
public void LoadStandardResources()
{
ConfigFile file = new ConfigFile();
file.Load("resources.cfg", "\t:=", true);
ConfigFile.SectionIterator sectionIterator = file.GetSectionIterator();
while (sectionIterator.MoveNext())
{
string currentKey = sectionIterator.CurrentKey;
foreach (KeyValuePair<string, string> pair in sectionIterator.Current)
{
string key = pair.Key;
string name = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation(name, key, currentKey);
}
}
}
#endregion

#region Event delegates
/// <summary>
/// Delegate from the scene eventhandler
/// </summary>
/// <param name="Device"></param>
public delegate void SceneEventHandler(TOgre Device);
#endregion


I hope some one can help me.

greats,
Jo0oker

Vectrex

03-02-2010 01:05:20

Check out the "tecnofreak" editor since it uses the same docking and it uses morge. I think he just recently swapped to native ogre though so you might have to get an older version from his svn

Jo0oker

03-02-2010 09:08:48

Hm, this doesn´t work, because even the last revesion of the repository countains only
the version with native ogre...

greats,
Jo0oker

Vectrex

03-02-2010 09:25:55

you should be able to get SVN to grab an old version. I use Tortoise SVN and it's reasonably easy to get a version from the history

Jo0oker

03-02-2010 09:28:36

I also use trtoise svn and the url: https://tecnofreakanima.svn.sourceforge ... freakanima

But even when i use revesion 2, there is only the CPP version...

greats,
Jo0oker

kraj0t

04-02-2010 10:08:15

I've had lots of issues with DockContent and Mogre in the past. It's been a long while since that, so I don't remember perfectly, but after inspecting my code, I can tell you this.

Don't know why, but a DockContent's handle is not good for Ogre. You must create something inside the DockContent. A Panel works great. Then, you must specify the panel's Handle when creating the RenderWindow.

However, beware! That's not the only problem you're going to run into. If you're using MOIS, then it's quite possible that you have to use different handles for initialising your InputManagers and RenderWindows. Want more troubles? If you want to allow your dockContents to float around, then you'll have to deal with DockContent's madness, because it seems like when you dock/undock your windows, their Handles change!

I'm telling you, you're gonna sweat blood. Anyways, don't give up.

I'll try to have a deeper look at my code. Ask me more things if you need to.

Vectrex

04-02-2010 11:27:03

This DEFINATELY sounds like something that should be wikied. WeifenLuo + MOIS minimal example.

kraj0t

04-02-2010 12:40:32

That's a good idea. But I'm awfully busy lately.

I'll see if I find the time to add it to the wiki ASAP.

Anyways, you can do it yourself if you think you've got the point :-)

Jo0oker

04-02-2010 16:49:00

Ok, i solved the problem.
I have to create the window and set the parent before creating the TOgre-Device :)

greats,
Jo0oker

Cosmas47

03-03-2014 22:19:41

I really hate to resurrect a 4 year old thread, but I don't quite understand the solution to the problem here, and this thread covers it the most.
Does anyone have an example, they'd be willing to share?

BrainScan

06-03-2014 22:04:03

I don't think anyone on this thread is still around. I'm sorry, I'm not familiar with WeifenLuo at all so I'm not sure how much help I can be. Perhaps you can try and describe the problem you're having in more detail?