nickgravelyn
19-07-2006 17:32:14
Are there any tutorials for creating a Winforms app with an Ogre rendering view? I wanted to start working with ODN a bit more, but without access to Winforms, I don't see the advantage (in my specific case) to using ODN vs Ogre with C++.
pjcast
19-07-2006 18:15:30
I am just curious.. Express does not have System.Windows.Forms (Winforms)? I was under the impression that it was only lacking the visual designer.. Which I rarely use anyway, I design all my forms in code.
Ajare
19-07-2006 18:20:27
There are various Winforms tutorials on the web. I used
this one to get started. I think you need to create a Windows app, rather than a console one. Anyway, to get Ogre in, create a Panel in the form somewhere, and then call
mRenderWindow = mRoot.Initialise (panel);
in your OGRE startup code. That's how the WinForms demo that ODN comes with does it. Having said that, I'm still bombing out on creating the Root, so I don't know if it actually works.
nickgravelyn
20-07-2006 02:01:07
I am just curious.. Express does not have System.Windows.Forms (Winforms)? I was under the impression that it was only lacking the visual designer.. Which I rarely use anyway, I design all my forms in code.
Nope, it definitely has System.Windows.Forms as well as the visual designer.
There are various Winforms tutorials on the web. I used this one to get started. I think you need to create a Windows app, rather than a console one. Anyway, to get Ogre in, create a Panel in the form somewhere, and then call
mRenderWindow = mRoot.Initialise (panel);
in your OGRE startup code. That's how the WinForms demo that ODN comes with does it. Having said that, I'm still bombing out on creating the Root, so I don't know if it actually works.
Thanks. I'll see what I can come up with later this evening.
pjcast
20-07-2006 03:05:56
Hmm, I see now.. I just missunderstood your post (of not having access to winforms).
In anycase, this is how I create Ogre:
if( msInstance != null )
throw( new Exception("Duplicate Ogre Instance!") );
msInstance = this;
mCreator = main;
OutputManager.Instance.CreateWindow("Ogre");
//Create ogre subsystem
String plugins = mCreator.AppDirectory + "/plugins.cfg";
OutputManager.Instance.AppendTextLine("Ogre", "Loaded Plugins.cfg");
mOgreContainer.mRoot = new Root(plugins);
OutputManager.Instance.AppendTextLine("Ogre", "Created Root");
//Try to restore saved settings
mOgreContainer.mRoot.RestoreConfig();
//Create a list of found rendersystems (and try to load one)
String configRenderer = MainForm.Instance.GetConfigOption("Rendersystem");
RenderSystemList renderers = mOgreContainer.mRoot.GetAvailableRenderers();
RenderSystemList.RenderSystemListEnumerator i = renderers.GetEnumerator();
int count = 0;
int index = -1;
while (i.MoveNext())
{
EditorManager.Instance.EditBox.RenderDropDownList.Items.Add(i.Current.Name);
msAvailRenderers[count] = i.Current.Name;
if (configRenderer == i.Current.Name)
index = count;
++count;
}
if( count == 0 )
throw(new Exception("No Rendersystem to load!"));
//Set one that was saved
if (index >= 0)
mOgreContainer.mRoot.SetRenderSystem(renderers[index]);
else //Set the first found one
mOgreContainer.mRoot.SetRenderSystem(renderers[0]);
msCurrentRenderer = mOgreContainer.mRoot.GetRenderSystem().Name;
OutputManager.Instance.AppendTextLine("Ogre", "Activated " + msCurrentRenderer);
EditorManager.Instance.EditBox.RenderDropDown.Text = msCurrentRenderer;
mOgreContainer.mRoot.SaveConfig();
mOgreContainer.mRenderWindow = mOgreContainer.mRoot.Initialise(mForm);
mOgreContainer.mSceneManager = mOgreContainer.mRoot.CreateSceneManager((UInt16)SceneType.Generic, "ExampleSMInstance");
mOgreContainer.mCamera = mOgreContainer.mSceneManager.CreateCamera("MainCamera");
mOgreContainer.mCamera.Position = new Math3D.Vector3(200, 200, 150);
mOgreContainer.mCamera.LookAt = new Math3D.Vector3(0, 0, 0);
mOgreContainer.mCamera.NearClipDistance = 5;
mOgreContainer.mCamera.AutoAspectRatio = true;
mOgreContainer.mViewport = mOgreContainer.mRenderWindow.AddViewport(mOgreContainer.mCamera);
mOgreContainer.mViewport.BackgroundColor = Color.Black;
TextureManager.Instance.SetDefaultNumMipmaps(5);
//This timer updates the rendering
mTimer = new System.Windows.Forms.Timer();
mTimer.Interval = (int)msRenderingSpeed;
mTimer.Tick += new System.EventHandler(mTimer_Elapsed);
mTimer.Start();
//Register some event listeners
mForm.Resize += new System.EventHandler(mForm_Resize);
mForm.SizeChanged += new System.EventHandler(mForm_Resize);
mForm.Disposed += new System.EventHandler(mForm_Disposed);
//Movement
EnableMovement = true;
//Hook up to Tabwindow
mTab = new Crownwood.Magic.Controls.TabPage(mTitle, mForm, mCreator.Icon);
mCreator.EditorM.AddEditorPane(this, mTab);
mForm.AllowDrop = true;
mOgreContainer is just a class I made that contains references to a camera, viewport, scenemanager, root, window, and some helper methods in my editor. I don't use a config dialog, but just load the last used rendersystem from the previous app run. And mForm is a System.WIndows.FOrms.Panel, and that is placed inside a tab window.
Anyway, HTH..
My Editor