[solved] MogreForm with 2 renderers

nargil

10-09-2007 15:44:47

I've tried: public partial class MogreForm : Form
{
protected MyOgreWindow mogreWin;
protected MyOgreWindow preview;

public MogreForm()
{
InitializeComponent();
this.Disposed += new EventHandler(MogreForm_Disposed);

mogreWin = new MyOgreWindow(new Point(0, 0), mogrePanel.Handle);
mogreWin.InitMogre();

preview = new MyOgreWindow(new Point(0, 0), groupBox1.Handle);
preview.InitMogre();
}
...


but it crashes at preview.InitMogre();
I'm writing an editor for my game and I want to have the main scene and a preview renderer displaying only the current mesh from the list of avaible meshes that can be added to the scene.

bleubleu

10-09-2007 18:12:13

Hi!

What does InitForm() do ?

Here the sequence of operation for what you want to do :
  1. Create Root[/*:m]
  2. Initialize the rendering system[/*:m]
  3. Initialize your scene manager.[/*:m]
  4. For each view in your editor : Create the RenderWindow, cameras, viewports, etc..[/*:m]
  5. Start rendering and have fun.[/*:m][/list:u]Mat

nargil

10-09-2007 23:54:12

Thx for reply - it helped alot!

InitMogre(); was the standard function from the sample. So 2 root were created. I made the root object static

public class OgreWindow
{
public static Root root;
public SceneManager sceneMgr;
protected static int numer = 0;

protected Camera camera;
public Viewport viewport;
protected RenderWindow window;
protected Point position;
protected IntPtr hWnd;

public OgreWindow(Point origin, IntPtr hWnd)
{
position = origin;
this.hWnd = hWnd;
}

public void resize()
{
window.WindowMovedOrResized();
camera.AspectRatio = (float)viewport.ActualWidth / (float)viewport.ActualHeight;
root.RenderOneFrame();
}

public virtual void CreateScene()
{
}

public void InitMogre()
{

//-----------------------------------------------------
// 1 enter ogre
//-----------------------------------------------------
if (root == null)
{
root = new Root();

//-----------------------------------------------------
// 2 configure resource paths
//-----------------------------------------------------
ConfigFile cf = new ConfigFile();
cf.Load("resources.cfg", "\t:=", true);

// Go through all sections & settings in the file
ConfigFile.SectionIterator seci = cf.GetSectionIterator();

String secName, typeName, archName;

// Normally we would use the foreach syntax, which enumerates the values, but in this case we need CurrentKey too;
while (seci.MoveNext())
{
secName = seci.CurrentKey;
ConfigFile.SettingsMultiMap settings = seci.Current;
foreach (KeyValuePair<string, string> pair in settings)
{
typeName = pair.Key;
archName = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName);
}
}

//-----------------------------------------------------
// 3 Configures the application and creates the window
//-----------------------------------------------------
bool foundit = false;
foreach (RenderSystem rs in root.GetAvailableRenderers())
{
root.RenderSystem = rs;
String rname = root.RenderSystem.Name;
if (rname == "Direct3D9 Rendering Subsystem")
{
foundit = true;
break;
}
}

if (!foundit)
return; //we didn't find it... Raise exception?

//we found it, we might as well use it!
root.RenderSystem.SetConfigOption("Full Screen", "No");
root.RenderSystem.SetConfigOption("Video Mode", "1024 x 768 @ 32-bit colour");
root.Initialise(false);
}

NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = hWnd.ToString();
numer++;
window = root.CreateRenderWindow("Simple Mogre Form Window" + numer.ToString(), 0, 0, false, misc);
if(numer==1)ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

CreateScene();
}


now i can inherit like:
public class MogrePreview : OgreWindow
{
public MogrePreview(Point origin, IntPtr hWnd) : base(origin, hWnd)
{
}
public override void CreateScene()
{
sceneMgr = root.CreateSceneManager(SceneType.ST_EXTERIOR_REAL_FAR, "SceneMgrPreview");
sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f);

Light slonce = sceneMgr.CreateLight("slonce");
slonce.Position = new Vector3(100f, 100f, -100f);

camera = sceneMgr.CreateCamera("SimpleCamera");
camera.Position = new Vector3(0f, 50f, -100f);

camera.LookAt(new Vector3(0f, 0f, 0f));
camera.NearClipDistance = 5;

viewport = window.AddViewport(camera);
viewport.BackgroundColour = new ColourValue(0.2f, 0.3f, 0.5f, 1.0f);


// do some object creation here...
}

and the same for the main rendering window

Thx again for help

laurent_mrejen

28-11-2008 16:57:49

Hi,

Your code doesn't work with me. I can't also debug the example

Can you help me?

Bostich

28-11-2008 17:05:41


Can you help me?


Hi laurent_mrejen,

can you specify your Problem? Without any error Message, its hard to help you ;)

Bostich

laurent_mrejen

30-11-2008 17:37:39

My problem is that the initMogre function of the examples that comes with mogre doesn't work. It stops at this function without the way to debug it.

The error message is "can't find the specified module"
Does anyone have any idea ?

Thanks in advance

Laurent Mrejen
www.existenz-software.fr

JJJx

08-01-2011 23:07:22

My problem is that the initMogre function of the examples that comes with mogre doesn't work. It stops at this function without the way to debug it.

Hi,

I just had 4 hours work with creating a new project from scratch and putting in everything there is of the sample project MogreForms.

I had your problem too.

My Solution is: Its not possible to debug the application if you have compiled with debug configuration.

But at last that was not the only problem to make that new project work. So I know this thread seems to be closed but if I can help anybody with what I found out I better give you my steps to make a new winforms-mogre-thing work:

- First: switch to release-configuration.
if you cannot find out how to switch to release-mode - what happened to me - you probably have to switch off the childrens security mode, that is:
(now I dont know the english menus, hope it works if I describe the options)
In the extras/options-menu under "projects and projects folders" (or something similar) click the checkbox "extented build configurations" (or similar) on.
then you will see in the properties of the project the comboboxes to change build config. ==> change to release
You can then start debugging and step through anyways but you cannot debug the mogre-libs.
(I tried to reference mogre_d.dll but it didnt work)
- make sure your project saves the executable in the mogre\bin folder. (project properties)
- If you then - like me - at least can compile an run an see an empty form window - thats nice.
- Took me another hour and filecompare to find out that you surely have to set the paint event of the control where you want to put ogre things into (thats normally the panel named mogrePanel) to the method that renders. In the sample code that is: MogreForm_Paint
For this you have to look at the properties of the mogrePanel and switch to the view with the events. change the paint event to MogreForm_Paint.
The problem with this is that you cannot see this in the samples properties probably because they have been made with earlieer .net-versions.

That is it. Hope that helps someone and save some hours of compatibility trouble shooting

Beauty

12-01-2011 10:23:28

Have a look to the source code of the Mogre wiki tutorial framework.
It contains the basics of initializing and scene creation.

The source is available here:
https://bitbucket.org/amirabiri/mogre.t ... mework/src

How to modify the source code to start without the config window, you read here:
http://www.ogre3d.org/tikiwiki/Mogre+Wi ... Other+Uses