frame listreners in embedded mode?! How?

eddy

01-08-2011 18:08:11

Hello again!

I am interested if there is a way to initialize the frame listeners when running mogre in a a panel, or in a windows form. For example in an MDI project like my following test project:
.

I suspect this is a namespace issue. I tried calling the createframlisteners() in a couple of ways, but I allways get some kind of an error:

for example:
Error 1 'Mogre.TutorialFramework.BaseApplication.CreateFrameListeners()' is inaccessible due to its protection level
when I write:
protected override void CreateFrameListeners()
{
Mogre.TutorialFramework.BaseApplication.CreateFrameListeners();
}

or
protected override void CreateFrameListeners()
{
BaseApplication.CreateFrameListeners();
}

Error 3 'System.Windows.Forms.Form' does not contain a definition for 'CreateFrameListeners'
when I write:
protected override void CreateFrameListeners()
{
base.CreateFrameListeners()
}
;

p.s.: I put this code into my OgreForm.cs file.

McDonte

04-08-2011 11:56:24

Hi eddy,

I don't know what your "OgreForm.cs" file contains but I guess it is an adaption of the WindowsForms class, am I right? So, error 3 is understandable because "CreateFrameListeners" is not defined in the base class.

Error 1 and error 2 are related to the fact that "CreateFrameListeners" is no static method so you need an instance of BaseApplication to call it. So you can either add an instance of this class to your form or you choose to implement your own "CreateFrameListeners" method. Actually this is not so much code so I guess this would be the best solution. Take a look at the sources of the framework:


protected virtual void CreateFrameListeners()
{
mRoot.FrameRenderingQueued += new FrameListener.FrameRenderingQueuedHandler(OnFrameRenderingQueued);
}

I hope this helped!

eddy

04-08-2011 12:58:03

Thank You very much!

I think it did the trick. I made the proposed changes, with minor modifications. I.e.:

private void OgreForm_Load(object sender, EventArgs e)
{
Init();
CreateFrameListeners();
Go();
}
...
protected virtual void CreateFrameListeners()
{
mRoot.FrameRenderingQueued += new FrameListener.FrameRenderingQueuedHandler(ProcessBufferedInput); //<-Minor modification here
}

protected bool ProcessBufferedInput(FrameEvent evt)
{
return true;
}


I put a break point at return true; it is constantly stopping the program there so I suppose its working. Once again thank you.



Here is the source: http://www.2shared.com/uploadComplete.j ... 2naQ0gj7XK (if any beginner other then myself is interested)
Input needs to be sorted, and I do not have proper working codes for disposed and resize:

void OgreForm_Disposed(object sender, EventArgs e)
{
mRoot.Dispose();
mRoot = null;
}
void OgreForm_Resize(object sender, EventArgs e)
{
mWindow.WindowMovedOrResized();
}
public void Go()
{
Show();
while (mRoot != null && mRoot.RenderOneFrame())
Application.DoEvents();
}

Pyritie

13-08-2011 12:03:56

My main class is a big modification of the original form thing, but since I guess this is using Forms this might be helpful anyway. It's a subclass of "Form" from System.Windows.Forms

private void StartRendering() {
Root root = LKernel.Get<Root>(); // this is just my thing to get the root singleton
root.RenderOneFrame();

while (!quit && !this.IsDisposed && root != null) {
if (!root.RenderOneFrame())
break;
Application.DoEvents();
}
if (root != null)
root.Shutdown();
}

protected override void Dispose(bool disposing) {
base.Dispose(disposing);
}


it doesn't have a resize method

Beauty

18-09-2011 22:31:15

In my application I do it like this:

I have a main window (Windows.Forms), which contains a Panel with the name renderPanel.
For this you save a reference:
String handleOfRenderpanel = this.renderPanel.Handle.ToString();

When I create the Ogre/Mogre Root, I add a reference as param like this:
// Create Render Window
root.Initialise(false, "Main Ogre Window");
NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = handleOfRenderpanel;
// other options ...
RenderWindow renderWindow = root.CreateRenderWindow("Main RenderWindow", 1024, 768, false, misc);


Then I add a callback to my main window, which fires when the windows was resized:

this.Resize += new EventHandler(OgreForm_Resize);


The callback method defines the new size of the renderPanel (and by this the 3D view of Ogre):
private void OgreForm_Resize(Object sender, EventArgs e)
{
// do calculations
Int32 newWidth = ...
Int32 newHeight = ...
// apply
renderPanel.Size = new Size(newWidth, newHeight);
}


By the way, there is a tutorial about Embedding Mogre in Windows.Forms.