This first Lab assignment is intended to get the Ogre3D environment started. Getting the development environment set up and configured can be a little tricky for the first time, so this Lab will be solely used to get the “Hello World” of Ogre3D built.
There will be a pdf guide that will take you through the basic application step by step. I strongly encourage you to try to understand the steps not just writing it down like a parrot, as the follow up Labs will all be built on top of the base you create in Lab 1.
Discussion thread for this lab will be on Piazza: Lab 1 Discussion Thread. Please don't hesitate to ask questions or comment on the Lab assignment.
To prepare your environment and project you need to:
example: C:\Ogre1.9_vc100\OgreSDK_vc10_v1-9-0
WIN32 Console Application
and completely empty. You will write it from scratch.properties
. Add Ogre folders and files in several locations within the properties:Note:
$(ProjectName)\
at the end of the output directory so it will look like:$(SolutionDir)$(Configuration)\$(ProjectName)\
$(OGRE_HOME)\include\OIS;$(OGRE_HOME)\include\OGRE;$(OGRE_HOME)\include;$(OGRE_HOME)\boost;%(AdditionalIncludeDirectories)
Note:
Debug: OgreMain_d.lib;OIS_d.lib;%(AdditionalDependencies) Release: OgreMain.lib;OIS.lib;%(AdditionalDependencies)
Note:
Debug: $(OGRE_HOME)\boost\lib;$(OGRE_HOME)\lib\debug;%(AdditionalLibraryDirectories) Release: $(OGRE_HOME)\boost\lib;$(OGRE_HOME)\lib\Release;%(AdditionalLibraryDirectories)
Project Configuration->General->Platform Toolset = Visual Studio 2012 (v110)
Note:
In my case: C:\Code\GEDE2015_Ogre_Labs
and create a new Folder called LabFiles
,OgreConfig
<OGRE SDK folder(same as OGRE_HOME)>/bin/debug/
you will find two files resources_d.cfg
and plugins_d.cfg
, copy those two into the folder OgreConfig
from the previous step. Note:
../..
with the path to the root of your Ogre SDK(again same as OGRE_HOME).LabFiles
Please try to keep file and folder names the same as in the examples so it won't be a nightmare for me to review them :)
You should now follow the guide from “Ogre3D 1.7 Beginners Guide by Felix Kerger” which you can get Here.
For this Lab we will only do the sections 1 - 3 of the Ogre 3D beginners Guide. The rest will be covered in the next Lab assignment.
The first 2 labs will be following this guide and getting familiar with the Ogre3D environment.
Important:
In step 1.2 change the path from plugins_d.cfg
to ../LabFiles/OgreConfig/plugins_d.cfg
Ogre::Root* root = new Ogre::Root("../LabFiles/OgreConfig/plugins_d.cfg");
Additionally in step 3.1 change the path from resourcfes_d.cfg
to ../LabFiles/OgreConfig/resourcfes_d.cfg
cf.load("../LabFiles/OgreConfig/resources_d.cfg");
After line 2 in section 2 of the Guide, please add this line to the code. Since the Ogre 1.9 default Scene Manager does not set the ambient light by default like back in 1.7, we have to that our selves.
sceneManager->setAmbientLight(Ogre::ColourValue(0.3f, 0.3f, 0.3f));
A friendly note: In the guide #include “OGRE/Ogre.h”
makes compiler go through a lot of jargon you are not using making compilation times horrible. Try to include only what you need, like so for Ogre::Root* #include “OGRE/OgreRoot.h”
.
When you manage to run your first application and get the configuration dialog after section 1 of the guide, Do not run it in fullscreen! Especially if you run it through the VS environment :)
Finally after you successfully render your first window, black or with Sinbad, do the following.
ogre.cfg
, move it to the folder <solution dir>/LabFiles/OgreConfig/
Ogre::Root* root = new Ogre::Root("../LabFiles/OgreConfig/plugins_d.cfg"); to Ogre::Root* root = new Ogre::Root("../LabFiles/OgreConfig/plugins_d.cfg","../LabFiles/OgreConfig/ogre.cfg");
Your final results should look something like this:
#include "OGRE/OgreRoot.h" #include "OGRE/OgreSceneManager.h" #include "OGRE/OgreSceneNode.h" #include "OGRE/OgreRenderWindow.h" #include "OGRE/OgreConfigFile.h" #include "OGRE/OgreEntity.h" int main() { Ogre::Root* root = new Ogre::Root("../LabFiles/OgreConfig/plugins_d.cfg","../LabFiles/OgreConfig/ogre.cfg"); if(!root->showConfigDialog()) { return -1; } Ogre::RenderWindow* window = root->initialise(true, "Ogre3D Beginners Guide"); Ogre::SceneManager* sceneManager = root->createSceneManager(Ogre::ST_GENERIC); Ogre::Camera* camera = sceneManager->createCamera("Camera"); camera->setPosition(Ogre::Vector3(0,0,30)); camera->lookAt(Ogre::Vector3(0,0,0)); camera->setNearClipDistance(5); Ogre::Viewport* viewport = window->addViewport(camera); viewport->setBackgroundColour(Ogre::ColourValue(0.0,0.0,0.0)); camera->setAspectRatio(Ogre::Real(viewport->getActualWidth())/Ogre::Real(viewport->getActualHeight())); Ogre::String sectionName, typeName, dataName; Ogre::ConfigFile cf; cf.load("../LabFiles/OgreConfig/resources_d.cfg"); Ogre::ConfigFile::SectionIterator sectionIter = cf.getSectionIterator(); while(sectionIter.hasMoreElements()) { sectionName = sectionIter.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = sectionIter.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for( i = settings->begin() ; i != settings->end() ; ++i ) { typeName = i->first; dataName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation(dataName, typeName, sectionName); } } Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); Ogre::Entity* ent = sceneManager->createEntity("Sinbad.mesh"); sceneManager->getRootSceneNode()->attachObject(ent); sceneManager->setAmbientLight(Ogre::ColourValue(.3f,.3f,.3f)); root->startRendering(); return 0; }
This lab projects will not be graded, but their completion counts towards your labs grade.