MOGRE @ ウィキ

0 MOGREアプリケーションのセットアップ

最終更新:

mogre

- view
だれでも歓迎! 編集

前準備


前提条件

このチュートリアルは標準のC#アプリケーションをプログラムとコンパイル出来ると仮定しています。
VisualC# 8.0 (Visualu C# 2005)をインストールしていること。 (Expressバージョンでも構いません)

編集者はVisual C# 2008で使用していますが問題はないようです。

はじめに

このチュートリアルはMogreのインストール方法、セットアップ方法とMogreアプリケーションの実行を行います。

インストール


Mogreのダウンロード

MogreのSourceForgeプロジェクトページから最新版をダウンロードできます。
ビルド済みファイルのSDKをダウンロードすることを推奨します。
このチュートリアルではデフォルト(c:\OgreSDK)にMogreSDKをインストールしたと仮定していきます。

You will also need vcredist_x86.exe; check it out in the same URL above. Some users reported that applications executed correctly after installation (e.g.: Visual Studio 2005, Team Edition, Version 8.0.50727-42).

Alternatively you can install the SP1 for your IDE (Visual Studio, C# Express, etc.) So you also can use the debug version of DLL files.

MogreFrameworkのダウンロード

このチュートリアルではMogreFrameworkという名前の.Netアセンブリを使用します。
まずファイルをダウンロードしてc:\OgreSDK\binディレクトリにこのファイルをコピーします。
MogreFrameworkをダウンロード
匿名SVNで最新版を取得することもできます。 at [1]. (コードの取得にTortoiseSVNの使用も可能です。)

上記のファイルが解凍された後に、MogreFrameWork.dllがC:\OgreSDK\bin\debug\とc:\OgreSDK\bin\releaseディレクトリの両方にあるはずです。

環境変数の設定
OgreはWindows環境変数に含む必要があるいくつかのDLLがあります。
これを行うには、コントロールパネルを開き、次にシステムを開きます。
詳細タブをクリックした後、環境変数ボタンをクリックします。システム環境変数からPATH変数を見つけクリックします。 その後に編集ボタンをクリックします。変数値の最後に";C:\OgreSDK\bin\release;C:\OgreSDK\bin\debug"を追加した後にOKボタンをクリックします。システムプロパティを閉じます。

Note: この操作を行った後にPCを再起動する必要があることがあります。

Mogreアプリケーションのビルド


プロジェクトの作成


Visual Studioを開き、新しいプロジェクトを作ります。Windowsアプリケーションを選択して、プログラムに名前をつけて、OKをクリックします。
Visual C#はForm1.csを作成しますがそれをプロジェクトから削除してください。

プロジェクトを作成する際に、参照を追加する必要があえいます。
プロジェクトの参照設定を右クリックして、参照の追加を選択します。
参照タブをクリックして、C:\OgreSDK\bin\releaseディレクトリに移動します。
Mogre.dllとMogreFramework.dllを選択してOKをクリックします。

設定ファイルの追加


プロジェクトの使用前に3つの設定ファイルをプロジェクトに加えます。
ウィンドウズの場合、C:\OgreSDK\bin\releaseディレクトリの全ての".cfg"の付くファイルをプロジェクトのbin\debugとbin\releaseフォルダ(それらのフォルダを作成する必要があるかもしれません)にコピーします。終わったら、プロジェクトに追加したresouce.cfgを開きます。
それに、ディレクトリの相対パスを含まれているに気付くでしょう。
これを手動で絶対パスを設定しなければなりません。全ての"../../"を"C:/OgreSDK/"に置換します。

アプリケーションのテスト


プログラムを完全に実行するために、program.csを開き、コードを以下に変更します。
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using MogreFramework;
using Mogre;

namespace Test
{
  static class Program
  {
      [STAThread]
      static void Main()
      {
          OgreWindow win = new OgreWindow();
          win.Go();
      }
  }
}
F5を押してアプリケーションを実行します。
まずスプラッシュスクリーンが見え、何もない真っ黒のウィンドウが表示されます。
If so, congratulations! You have just successfully created your first Ogre project. We will be doing more with this later.

Troubleshooting


Checklist


If you have problems getting started, check the following things first:

   * Did you install the Mogre SDK and NOT the standard OgreSDK? The Mogre SDK can be obtained from the [2]. The Mogre SDK will include Mogre.dll in the C:\OgreSDK\bin\debug and C:\OgreSDK\bin\release directories.
   * Did you download and install the MogreFramework? This assembly is NOT required to use Mogre, but it will be used in all Mogre tutorials.
   * Is your PATH variable properly set so that Ogre can find them?
   * Did you add references to "Mogre.dll" AND "MogreFramework.dll" in your project?
   * Did you copy the Ogre configuration files from the SDK directory to your project's output directories? (They should be placed in YourProjectsDirectory\bin\debug and YourProjectsDirectory\bin\release.)
   * Did you modify the config files in BOTH the release and debug directories to have the absolute path to the media files?
   * To use the Direct3D9-Renderer you need to install the DirectX Redistributables from November 2007 or newer. 

[edit]
Getting Help

If you have checked these things, feel free to post the problem you are having to the Mogre forums. Be sure to include a detailed description of the problem, the things you have tried to fix it, and paste the error messages from the Ogre.log file if there are any (this file is located in the project's output directory).
[edit]
Exception Handling With Mogre

Before wrapping up this tutorial, I'd like to breifly mention how to handle exceptions which originate from Ogre itself. Mogre and C# can handle C++ exceptions, but they do not act as you would expect them to. If you ever see a message which states "Runtime Error! ... This application has requested the Runtime to terminate in an unusual way..." then you probably encountered an error in Ogre somewhere.

To properly handle an exception thrown by the C++ Ogre library, you need to catch an exception of the type System.Runtime.InteropServices.SEHException. After catching this exception, you can see if it's an Ogre exception (instead of just a crash) by checking the static OgreException.IsThrown property. If that property is true, then you handle the exception. For example, here is a chunk of code to catch and display an Ogre exception:

try
{
   ...
}
catch (System.Runtime.InteropServices.SEHException)
{
   if (OgreException.IsThrown)
       MessageBox.Show(OgreException.LastException.FullDescription,
                       "An Ogre exception has occurred!");
   else
       throw;
}

Wrapping your main method with a try block such as this one can save you lots of headaches down the line when you are debugging your application. Notice we have not added a catch block to catch a generic Exception object. This way when we are debugging the application, Visual Studios can insert a breakpoint for an unhandled C# exception, whereas Visual Studios cannot do this for C++ exceptions.
[edit]
Final Note

By this point you should be able to create and run an empty Mogre project. All subsequent tutorials will assume you can successfully set up an Mogre project.

Also, a possible way to speed up the creation of new Mogre projects is to create a new Templete. An example templete is available here: BasicMogreSetup. NOTE- this templete is only able to be used with Visual Studios 2008 C#. A tutorial on how to create a templete is available here: How to Create a Templete in VSC# 2008.

Proceed to Mogre Basic Tutorial 1 The SceneNode, Entity, and SceneManager constructs

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

記事メニュー
目安箱バナー