OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Tutorial 4
View page
Source of version: 4
(current)
!!Creating the tutorial Application This will create a simple application, nothing fancy, yet. !!!WinMain Before we start creating the actual application, we need to handle -+WinMain+-. -+WinMain+- is called when starting an executable. Add a file called WinMain.cpp to the project created in ((Tutorial 3)). If you don’t know how to do this, then look at the MS Dev Studio Users Guide. Enter the following code into WinMain.cpp: {CODE(wrap="1", colors="c++")}// Include the TutorialApplication header #include "TutorialApplication.h" // We are always windows, no need for checks #define WIN32_LEAN_AND_MEAN #include <windows.h> // The mean and nasty WinMain INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) { // Start the application try { // Create an instance of our application TutorialApplication TutorialApp; // Run the Application TutorialApp.go(); } catch ( Ogre::Exception &error ) { // An exception has occured MessageBox( NULL, error.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL ); } return 0; }{CODE} What this code does is create the TutorialApplication, calls the go method and provides a nice trap for any exceptions that could occur. !!!TutorialApplication Let’s now create the actual TutorialApplication. There are two ways you can do this. You can either do this by hand, or you can use the Insert/New Class functionality. We will use the latter for this Tutorial. Create a new class called TutorialApplication, have it derived from the ExampleApplication, as shown below. {img fileId="1624" thumb="y" alt="xorekis4_1.png" rel="box[g]"} When you click ok, it will complain that it cannot find the appropriate headers to include of the base class. Just ignore it and click ok anyway. You have now created two new files. -+TutorialApplication.h+- and -+TutorialApplication.cpp+-. Our next step is to modify the generated files of TutorialApplication. Open up -+TutorialApplication.h+- in DevStudio. Remember when you created this class, DevStudio complained about not finding a header? We will now manually add the required include line. Above the class TutorialApplication line add the following: {CODE(wrap="1", colors="c++")}#include "ExampleApplication.h"{CODE} Unfortunately we cannot compile our Tutorial yet. ExampleApplication has a virtual function defined that needs to be added to our TutorialApplication. Add the following two lines to the class: {CODE(wrap="1", colors="c++")}protected: void createScene();{CODE} Now your class definition should look like the following: {CODE(wrap="1", colors="c++")}#include "ExampleApplication.h" class TutorialApplication : public ExampleApplication { public: TutorialApplication() { //no implementation yet } virtual ~TutorialApplication(); protected: void createScene() { //no implementation yet } };{CODE} Let’s complete the changes required. We need to add a body to the method createScene. Open up TutorialApplication.cpp and add the following: {CODE(wrap="1", colors="c++")}void TutorialApplication::createScene() { // empty body for now }{CODE} !!!Your first compile If everything was done correctly, you can now compile. I ran into a little problem when I compiled mine. I tend to use multithreaded code, and had not set the project to be multithreaded, so I received the following load of errors: * -+LIBCMT.lib(osfinfo.obj) : error LNK2005: __alloc_osfhnd already defined in LIBCD.lib (osfinfo.obj)+- * -+LIBCMT.lib(osfinfo.obj) : error LNK2005: __set_osfhnd already defined in LIBCD.lib (osfinfo.obj)+- * -+LIBCMT.lib(osfinfo.obj) : error LNK2005: __free_osfhnd already defined in LIBCD.lib (osfinfo.obj)+- * -+LIBCMT.lib(osfinfo.obj) : error LNK2005: __get_osfhandle already defined in LIBCD.lib (osfinfo.obj)+- * -+LIBCMT.lib(osfinfo.obj) : error LNK2005: __open_osfhandle already defined in LIBCD.lib (osfinfo.obj)+- The way to fix this if you get the same errors, is to open the settings for the project, and select the C++ tab. Select Code Generation from the Category combobox. Change the Use run-time library from singlethread debug to multithread debug. Recompile. If everything worked this time, then you get a valid compile. So now what? Lets Run this application. !!!Your First Run Let me guess, you got an exception about missing resources.cfg. Guess what, let's add in the resources now. Using File Explorer copy all of the directories and files in -+C:\OgreTutorials\OgreNew\Samples\Media+- to our media directory at -+C:\OgreTutorials\bin\media+-. Now copy the file resources.cfg from -+C:\OgreTutorials\OgreNew\Samples\Common\Bin\Debug+- to -+C:\OgreTutorials\Bin\Debug+-. We need to edit the -+resources.cfg+- for it to work with our resources. Open up -+resources.cfg+- in Notepad or Write. Now change the -+=../../../Media+- to -+=../Media+-. Re-run the Application. If you get an exception that says a certain .dll could not be found, then double-check that the working directory is set to the folder that contains the .dll files. If you set the resource file correctly, you should now see the Ogre’s Driver Selection Dialog. Selection your driver and hit ok. You will now see a black screen, with the Ogre Logo in the bottom right and the FPS display in the bottom left. Here I am running the TutorialApplication in a window using OpenGL. {img fileId="1625" thumb="y" alt="xorekis4_2.png" rel="box[g]"} __Congratulations, you have successfully created and run your first Ogre Application.__ The rest of the tutorials will be building upon this application: ((Tutorial 5)).
Search by Tags
Search Wiki by Freetags
Latest Changes
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
Critter AI
Mogre Add-ons
MOGRE
Mogre MyGUI wrapper
MOGRE Editable Terrain Manager
...more
Search
Find
Advanced
Search Help
Online Users
16 online users