Sign in to follow this  
CrimsonGT

Main() Function in Seperate source file?

Recommended Posts

CrimsonGT    130
Im not new to programming, but I am to c++. I am writing a very basic Ogre application and the tutorial I followed has the main() loop right in with everything else. I am trying to figure out how to seperate it so I can have like a main.cpp and then ogre.cpp file. My reason is that I am extremely OCD and have to keep everything as organized as possible. Basically I want all of this in ogre.cpp except for the main() Here is my code... //Include all of files needed for the Project #include "wo_Globals.h" #if defined(WIN32) #include "windows.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { #else int main(int argc, char *argv[]) { #endif //Initialize Ogre Variables Ogre::Root *mRoot; Ogre::RenderWindow *mWindow; Ogre::SceneManager *sceneMgr; Ogre::Camera *mCamera; Ogre::Viewport *viewPort; mRoot = new Root("", ""); //Load Render System #if defined(_DEBUG) mRoot->loadPlugin("RenderSystem_GL_d"); #else mRoot->loadPlugin("RenderSystem_GL"); #endif RenderSystemList *renderSystems = NULL; RenderSystemList::iterator r_it; renderSystems = mRoot->getAvailableRenderers(); r_it = renderSystems->begin(); mRoot->setRenderSystem(*r_it); mRoot->initialise(false); //Load Plugins #if defined(_DEBUG) mRoot->loadPlugin("Plugin_CgProgramManager_d"); mRoot->loadPlugin("Plugin_OctreeSceneManager_d"); #else mRoot->loadPlugin("Plugin_CgProgramManager"); mRoot->loadPlugin("Plugin_OctreeSceneManager"); #endif //Initialize Resources ResourceGroupManager::getSingleton().addResourceLocation( "resource", "FileSystem", "General"); ResourceGroupManager::getSingleton().initialiseResourceGroup("General"); //Hardcoded Defaults - Temp NameValuePairList opts; opts["resolution"] = "1024x768"; opts["fullscreen"] = "false"; opts["vsync"] = "false"; //Create the actual Window mWindow = mRoot->createRenderWindow("Warlords", 1024, 768, false, &opts); //Create the Scene Manager, Camera, and Viewport sceneMgr = mRoot->createSceneManager(ST_GENERIC); mCamera = sceneMgr->createCamera("PlayerCam"); mCamera->setNearClipDistance(5); viewPort = mWindow->addViewport(mCamera); viewPort->setBackgroundColour(ColourValue(0,0,0)); mCamera->setAspectRatio((Real)1.333333); //For Input Handler unsigned long hWnd; mWindow->getCustomAttribute("WINDOW", &hWnd); //Setup the Inputer Handler Simulation *mSim = new Simulation(); InputHandler *mHandler = new InputHandler(mSim, hWnd); mSim->requestStateChange(SIMULATION); //While Game State is not SHUTDOWN, Continue to Render while (mSim->getCurrentState() != SHUTDOWN) { mHandler->capture(); WindowEventUtilities::messagePump(); mRoot->renderOneFrame(); } //Scene Cleanup Section delete mRoot; return 0; }

Share this post


Link to post
Share on other sites
Crypter    748
THIS should help.

Quote:

m not new to programming, but I am to c++

If you are new to C++, I highly recommend learning more about C++ before jumping into a large engine, like Ogre.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this