Tutorial 5 Error

Mashew

12-06-2008 04:41:33

I set up Tutorial 5 and added terrain to it. It works when I don't call the Terrain but, it shows up a Runtime Error when I do.

Here is the full code (I know it probably is not important but, I have no idea what could cause this. I am thinking the SceneManager is causing it):


using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Mogre;
using System.Drawing;

namespace Tutorial05
{
static class Program
{
[STAThread]
static void Main()
{
OgreStartup ogre = new OgreStartup();
ogre.Go();
}
}

class OgreStartup
{
Root mRoot = null;
float ticks = 0;

public void Go()
{
CreateRoot();
DefineResources();
SetupRenderSystem();
CreateRenderWindow();
InitResources();
CreateScene();
StartRenderLoop();
}

void CreateRoot()
{
mRoot = new Root();
}

void DefineResources()
{
ConfigFile cf = new ConfigFile();
cf.Load("resources.cfg", "\t:=", true);
ConfigFile.SectionIterator seci = cf.GetSectionIterator();
String secName, typeName, archName;

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);
}
}
}

void SetupRenderSystem()
{
if (!mRoot.ShowConfigDialog())
throw new Exception("The user canceled the configuration dialog.");

//// Setting up the RenderSystem manually.
//RenderSystem rs = mRoot.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
//mRoot.RenderSystem = rs;
//rs.SetConfigOption("Full Screen", "No");
//rs.SetConfigOption("Video Mode", "800 x 600 @ 32-bit colour");
}

void CreateRenderWindow()
{
mRoot.Initialise(true, "Main Ogre Window");

//// Embedding ogre in a windows hWnd. The "handle" variable holds the hWnd.
//NameValuePairList misc = new NameValuePairList();
//misc["externalWindowHandle"] = handle.ToString();
//mWindow = mRoot.CreateRenderWindow("Main RenderWindow", 800, 600, false, misc);
}

void InitResources()
{
TextureManager.Singleton.DefaultNumMipmaps = 5;
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
}

void CreateScene()
{
SceneManager mgr = mRoot.CreateSceneManager(SceneType.ST_GENERIC);
SceneManager mgr2 = mRoot.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);
Camera cam = mgr.CreateCamera("Camera");
mRoot.AutoCreatedWindow.AddViewport(cam);

mgr.SetWorldGeometry("terrain.cfg");
Entity ent = mgr.CreateEntity("ninja", "ninja.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

cam.Position = new Vector3(0, 200, -400);
cam.LookAt(ent.BoundingBox.Center);

mRoot.FrameEnded += new FrameListener.FrameEndedHandler(FrameEnded);
ticks = Environment.TickCount;
}

void StartRenderLoop()
{
mRoot.StartRendering();

//// Alternate Rendering Loop
//while (mRoot.RenderOneFrame())
//{
// // Do other things here, such as sleep for a short period of time
//}
}

bool FrameEnded(FrameEvent evt)
{
if (Environment.TickCount - ticks > 5000)
return false;

return true;
}
}
}

JoeC

12-06-2008 11:00:17

Er, Does it give an error message? If so it would be useful to know what it is.
Also have a look in the Ogre.log file and see what the reported error is.

The most likely problem is that Mogre can't find the terrain.cfg file. Have a look in your resources.cfg file. There should be a path to a folder containing the sample terrain.cfg file. If there isn't Mogre won't find it.

There's also a small chance that your graphics card can't handle the terrain texture but my feeling is that the default terrain is pretty basic.

Like I said, if you can tell us what the error message is we can have a better stab at diagnosing the problem