#include <Ogre.h>
#include <windows.h>
// You need to link OgreMain.lib for release mode and OgreMain_d.lib for debug mode
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) // Just use int main() if you are on a non windows OS
{
Ogre::Root *root; // The root object - Look at the manual for more on the structure
Ogre::SceneManager* smgr; // Scene manager - used for placing things in the scene etc.
Ogre::Camera *cam; // The camera - it sees
Ogre::Viewport *vp; // The viewport - we could have several view ports on one window (split screen) and each one is linked to a camera
Ogre::RenderWindow *window; // Our window - we could have a small viewport and actually place windows controls elsewhere on the window
root = new Ogre::Root("", "", "OgreLog.log"); // Make the root object - use blank strings to not use the said parameter
#ifdef _DEBUG
root->loadPlugin("RenderSystem_GL_d"); // If we are in debug, use the debug render dll. This is loaded dynamically, not linked statically
#else
root->loadPlugin("RenderSystem_GL"); // If we are in release, use the release render dll. This is loaded dynamically, not linked statically
#endif
root->setRenderSystem(*(root->getAvailableRenderers()->begin())); // Since we only loaded GL, this is what it sets it to
root->initialise(false); // We don't want an auto created window, thanks
Ogre::NameValuePairList params; // Parameter structure
params["FSAA"] = "0"; // Antialiasing
params["vsync"] = "false"; // Vertical syncronisation
// Make our window
window = root->createRenderWindow("Simple Application Demo",// Window title
800, // Screen X size (px)
600, // Screen Y size (px)
false, // Fullscreen - we want a non fullscreen window
¶ms); // Our parameter structure - look in the docs for parameters
Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC); // Texture filtering - anistrophic is nicer than bilinear or trilinear, or none for that matter
window->setActive(true); // Both of these are pretty obvious based on their names
window->setAutoUpdated(true);
smgr = root->createSceneManager(Ogre::ST_GENERIC); // There are other smgr types which are optimised for specific scene types
cam = smgr->createCamera("camera1"); // This can be retrieved by name so we don't really need to keep a pointer to it
cam->setNearClipDistance(0.01); // Anything closer than this will be clipped and we wouldn't be able to see it
cam->setFarClipDistance(500); // Anything 501 units away will be invisible
vp = window->addViewport(cam); // No other parameters just means "fill the window with what this cam sees"
vp->setBackgroundColour(Ogre::ColourValue(0.3, 0.3, 0.3)); // Black is always so prone to making unlit triangles invisible, so i always use a dark grey
vp->setClearEveryFrame(true); // We want this unless we desire a wierd paintint effect (or we know that no empty space will ever be visible, which will save processing time)
cam->setAspectRatio(window->getWidth() / float(window->getHeight())); // Make our rendered images the correct X:Y ratio - e.g. 4:3 or 16:9 - you can play with this for wierd views
cam->setFOVy(Ogre::Degree(60)); // You should play with this until you get an image you are happy with
cam->setPosition(20,20,20); // Position camera away from our thing
cam->lookAt(0,0,0); // Look at the origin
Ogre::ResourceGroupManager *rgm = Ogre::ResourceGroupManager::getSingletonPtr(); // Get a pointer to the resource group manager
rgm->addResourceLocation("../media", "FileSystem", "Stuff"); // Make a new resource group
rgm->initialiseResourceGroup("Stuff"); // Initialise the new group
Ogre::Entity *ent; // We make entities, and then add them to nodes
ent = smgr->createEntity("terrain", "terrain.mesh"); // Make our entity based on my awesome mesh file
ent->setMaterialName("terrain"); // See media/materials.material - also have a look on the docs at material file usage
Ogre::SceneNode* node = smgr->getRootSceneNode()->createChildSceneNode(); // Everything is a child of the root scene node
node->attachObject(ent); // And our visible entity is attached to our scene node
node->setPosition(0,0,0); // We just want it at the origin (where our camera points)
node->setScale(20,20,20); // It's tiny, so make it 20x bigger
while(! window->isClosed()) // While the window is open, run
{
Ogre::WindowEventUtilities::messagePump(); // This is neccessary to get windows messages
root->renderOneFrame(); // I render manually because I don't like frame listeners
}
root->destroySceneManager(smgr); // Destroy the scene manager
delete root; // Delete the root object and we are done!
return 0;
}