A different way to set up Mogre, based on XNA

programing maniac

29-08-2008 15:49:27

I have just tried out XNA, and it was pretty good. I really liked the way it was set up, because it made everything organized. I went back to using Mogre because XNA was made for the x-box 360, and I don't even own one, so I decided to just use Mogre.

The one thing that I got out of XNA was the way it was set up-
Game1

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame1
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
//OtherStuff
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here

}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here

}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here

base.Update(gameTime);
}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(backcolor);

// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}


Program-

using System;

namespace WindowsGame1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}



It was really simple and organized and you could create stuff really easily. So I wanted to create this type of setup for Mogre, because I thought it would be easier to program with. I tried to make it, but I didn't get really far because of two things-

(My code so far)
Game-

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

namespace Game
{
class GAME
{
Root mRoot = null;
public void RenderSystemSetup()
{
}
protected void Initialize()
{
mRoot = new Root();
}
protected void LoadContent()
{
}
protected void Update()
{
}
protected void Draw()
{
}
}
}


Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Mogre;
using MogreNewt;

namespace Game
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
GAME ogre = new GAME();
ogre.Go();
}
}
}


First, the update method. I wasn't sure on how to go about doing that. I knew that the update method wasn't for the graphics, but for testing input and for movement. I saw how in the XNA setup, it used the method base.update(gameTime); and I wasn't sure about how to go about doing that with Mogre.

Second, the initialization method. All it does for XNA is base.Initialize(); I put the mRoot = new Root(); in the Mogre way, because I knew that had to be initialized, but I wasn't sure about if there were any other things that needed to be initialized, other then the scene manager (SceneMgr), and the render system ( RS)

Thanks, and if you have any questions or suggestions, Please tell me! :D

Bekas

29-08-2008 16:59:35

Did you take a look at the ExampleApplication class ?:
http://mogre.svn.sourceforge.net/viewvc/mogre/trunk/Mogre/Samples/ExampleApplication/Example.cs?view=markup

It's easy to modify it into what you want.

programing maniac

30-08-2008 04:24:15

:D :D :D :D
Exactly what I needed!!!!! :D :D

Thanks so much. I hope to post the finished code like tomorrow!!