Are you a regular stikked user? Signup so you can keep track of your pastes!
  1. #include <Ogre.h>
  2. #include <windows.h>
  3. // You need to link OgreMain.lib for release mode and OgreMain_d.lib for debug mode
  4. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)   // Just use int main() if you are on a non windows OS
  5. {
  6.    Ogre::Root *root;         // The root object - Look at the manual for more on the structure
  7.     Ogre::SceneManager* smgr;   // Scene manager - used for placing things in the scene etc.
  8.     Ogre::Camera *cam;         // The camera - it sees
  9.     Ogre::Viewport *vp;         // The viewport - we could have several view ports on one window (split screen) and each one is linked to a camera
  10.     Ogre::RenderWindow *window;   // Our window - we could have a small viewport and actually place windows controls elsewhere on the window
  11.  
  12.    root = new Ogre::Root("", "", "OgreLog.log");   // Make the root object - use blank strings to not use the said parameter
  13.  
  14. #ifdef _DEBUG
  15.       root->loadPlugin("RenderSystem_GL_d");   // If we are in debug, use the debug render dll. This is loaded dynamically, not linked statically
  16. #else
  17.       root->loadPlugin("RenderSystem_GL");   // If we are in release, use the release render dll. This is loaded dynamically, not linked statically
  18. #endif
  19.  
  20.    root->setRenderSystem(*(root->getAvailableRenderers()->begin())); // Since we only loaded GL, this is what it sets it to
  21.  
  22.    root->initialise(false);   // We don't want an auto created window, thanks
  23.  
  24.    Ogre::NameValuePairList params; // Parameter structure
  25.     params["FSAA"] = "0";      // Antialiasing
  26.     params["vsync"] = "false";   // Vertical syncronisation
  27.    // Make our window
  28.    window = root->createRenderWindow("Simple Application Demo",// Window title
  29.                              800,                  // Screen X size (px)
  30.                              600,                  // Screen Y size (px)
  31.                              false,               // Fullscreen - we want a non fullscreen window
  32.                              &params);               // Our parameter structure - look in the docs for parameters
  33.  
  34.    Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC); // Texture filtering - anistrophic is nicer than bilinear or trilinear, or none for that matter
  35.  
  36.    window->setActive(true);      // Both of these are pretty obvious based on their names
  37.    window->setAutoUpdated(true);
  38.  
  39.    smgr = root->createSceneManager(Ogre::ST_GENERIC);   // There are other smgr types which are optimised for specific scene types
  40.  
  41.    cam = smgr->createCamera("camera1");   // This can be retrieved by name so we don't really need to keep a pointer to it
  42.    cam->setNearClipDistance(0.01);         // Anything closer than this will be clipped and we wouldn't be able to see it
  43.     cam->setFarClipDistance(500);         // Anything 501 units away will be invisible
  44.    vp = window->addViewport(cam);         // No other parameters just means "fill the window with what this cam sees"
  45.  
  46.    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
  47.    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)
  48.  
  49.    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
  50.    cam->setFOVy(Ogre::Degree(60));      // You should play with this until you get an image you are happy with
  51.    cam->setPosition(20,20,20);         // Position camera away from our thing
  52.    cam->lookAt(0,0,0);               // Look at the origin
  53.  
  54.    Ogre::ResourceGroupManager *rgm = Ogre::ResourceGroupManager::getSingletonPtr(); // Get a pointer to the resource group manager
  55.    rgm->addResourceLocation("../media", "FileSystem", "Stuff");   // Make a new resource group
  56.    rgm->initialiseResourceGroup("Stuff");                     // Initialise the new group
  57.  
  58.    Ogre::Entity *ent;                                 // We make entities, and then add them to nodes
  59.    ent = smgr->createEntity("terrain", "terrain.mesh");      // Make our entity based on my awesome mesh file
  60.    ent->setMaterialName("terrain");                     // See media/materials.material - also have a look on the docs at material file usage
  61.    Ogre::SceneNode* node = smgr->getRootSceneNode()->createChildSceneNode();   // Everything is a child of the root scene node
  62.    node->attachObject(ent);   // And our visible entity is attached to our scene node
  63.    node->setPosition(0,0,0);   // We just want it at the origin (where our camera points)
  64.    node->setScale(20,20,20);   // It's tiny, so make it 20x bigger
  65.  
  66.    while(! window->isClosed())   // While the window is open, run
  67.    {
  68.       Ogre::WindowEventUtilities::messagePump();   // This is neccessary to get windows messages
  69.       root->renderOneFrame();                  // I render manually because I don't like frame listeners
  70.    }
  71.    root->destroySceneManager(smgr);   // Destroy the scene manager
  72.    delete root;                  // Delete the root object and we are done!
  73.  
  74.    return 0;
  75. }

Reply to "Ogre Minimal Usage"

Here you can reply to the paste above

Create a snipurl

Make Private

Feeling clever? Set some advanced options.