====== LAB1: Ogre Startup Sequence ======
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 zombie parrot, as the follow up Labs will all be built on top of the base you create in Lab 1.
===== Discussion =====
Discussion thread for this lab will be on Piazza: [[https://piazza.com/class/hq7dlipqggr2qe?cid=6|Lab 1 Discussion Thread]]. Please don't hesitate to ask questions or comment on the Lab assignment.
===== Preparation =====
- Download and install C++ development environment, the instructions will assume you are using the [[http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express|MS Visual C++ Express 2010 environment]], which you can get for free. You're free to use other environments or platforms as long as you take care of making it work on your own (with the help of the Internet).
- Download and install [[http://www.ogre3d.org/download/sdk|OGRE 1.9 SDK for Visual C++ 2010 (32-bit)]]. I recommend extracting this to a folder with a relatively short path and no spaces. E.g. into "C:\OgreSDK". You are free to use other versions, but be advised you will be rowing your own boat if problems arise :)
**To prepare your environment and project you need to:**
- **Create a system environment variable** "**OGRE_HOME**" that points to Ogre SDK folder. You can then refer to this variable in your project setup as $(OGRE_HOME). This is so that you can easily take your project to a different machine where Ogre might be installed in a different folder. If each machine defines this variable, the project should be able to find the needed includes and libraries (see below). ''example: C:\Ogre1.9_vc100\OgreSDK_vc10_v1-9-0''
- **The Ogre run-time libraries (DLLs)** are in folders called bin/debug and bin/release inside the SDK folder. You need to add these two folders to your system path variable so that the system can find them when you launch your application.
- **It is good to organize all your lab source code**, from the very beginning of this class to avoid a complete mess later. VC++ helps you organize the code into **solutions** and **projects**. A solution is really a collection of projects, which is a great way to keep track of labs. Once you launch VC++, create a new project called "Lab1" inside a new solution called "GEDE2013" (it is a good idea to let VC++ create a folder for your solution - use the check box - and then your projects will appear inside that folder). The project should be a ''WIN32 Console Application'' and completely **empty**. You will write it from scratch.
- **Right-click on your project inside VC++ project explorer** and choose ''properties''. Add Ogre folders and files in several locations within the properties:
- **Change your build output directory:** Configuration Properties->General->Output Directory\\ Add ''$(ProjectName)\'' at the end of the output directory so it will look like:''$(SolutionDir)$(Configuration)\$(ProjectName)\''\\ This will help with organizing the builds for each lab project.{{ :public:t-gede-14-1:gede_lab1_outputdir.png?nolink |}}
- **Add additional include libraries:** C/C++->General->Additional Include Directories =$(OGRE_HOME)\include\OIS;$(OGRE_HOME)\include\OGRE;$(OGRE_HOME)\include;$(OGRE_HOME)\boost;%(AdditionalIncludeDirectories)
If the C/C++ tab is missing. For some reason, with some versions of Visual Studio you will need to have created a cpp file in order to get the C/C++ tab in the configuration properties, so adding a main.cpp file with a basic "hello world" to the project and building it will suffice. )
{{ :public:t-gede-14-1:gede_lab1_additional_include_directories.png?nolink |}}
- **Add connections to additional Ogre and input libraries:** Linker->Input->Additional Dependencies OgreMain_d.lib;OIS_d.lib;%(AdditionalDependencies)
Add this to the end of the current string, do not replace it, and make sure to seperate it with a semicolon.{{ :public:t-gede-14-1:gede_lab1_additionaldepend_debug.png?nolink |}}{{ :public:t-gede-14-1:gede_lab1_additionaldepend_release.png?nolink |}}
- **Also you will need to add additional Library folders** where the Ogre specific libraries and the required boost libraries are stored: Linker->General->Additional Library Directories =$(OGRE_HOME)\boost\lib;$(OGRE_HOME)\lib\debug;%(AdditionalLibraryDirectories)
{{ :public:t-gede-14-1:gede_lab1_debug_additional_libs.png?nolink |}}{{ :public:t-gede-14-1:gede_lab1_release_additional_libs.png?nolink |}}
- **If you are using a different version of Visual studio than 2010,** make sure to be using the vc100 toolset Project Configuration->General->Platform Toolset = Visual Studio 2010 (v100)
If the v100 toolset is not available, you will need to install VS 2010, or at least the correct VC++ toolset{{ :public:t-gede-14-1:gede_lab1_toolset_v100.png?nolink |}}
- Copy **plugins_d.cfg** and **resources_d.cfg** from the SDK bin/debug folder into your own GEDE2013/debug (or wherever your own compiled executables will be placed) if you followed section 5, thats where you will want to copy the files.\\ You need to modify the resources_d.cfg file by replacing the relative path of the resources with an absalute path.
Example: where the Ogre SDK path is "C:\Ogre1.9_vc100\OgreSDK_vc10_v1-9-0" \\
''FileSystem=../../OgreSDK_vc10_v1-9-0/media/materials/programs''\\ **to**\\
''FileSystem=C:/Ogre1.9_vc100/OgreSDK_vc10_v1-9-0/media/materials/programs'' \\
Make sure to change all references of ../../ to your absalute path.\\
Notice that Ogre cfg file wants forward slashes!\\
===== Lab Project =====
You should now follow the guide from "Ogre3D 1.7 Beginners Guide by Felix Kerger" which you can get {{:public:t-gede-14-1:ogrestartup_ogre3d_1.7_beginners_guide_chapter_9_by_felix_kerger.pdf|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.
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));
Your final results should look something like this:
{{ :public:t-gede-14-1:gede_lab1_final_example.png?nolink |}}
===== CODE =====
#include "OGRE/Ogre.h"
int main()
{
Ogre::Root* root = new Ogre::Root("plugins_d.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::ResourceGroupManager::getSingleton().addResourceLocation("/Ogre SDK/OgreSDK_vc10_v1-8-1/media/packs/Sinbad.zip","Zip");
Ogre::String sectionName, typeName, dataName;
Ogre::ConfigFile cf;
cf.load("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;
}
===== When You Are Finished =====
Upload your **commented source files** into Lab1 in MySchool (zip them up if more than one). The lab projects will not be graded, but their completion counts towards your participation grade.
And check out the next [[public:t-gede-14-1:lab2|Lab]] :)