Created
July 11, 2010 20:52
-
-
Save DanielG/471825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cmake_minimum_required(VERSION 2.6) | |
| project(ogre-test) | |
| include("CMake/setup-module-path.cmake") | |
| include("CMake/FindOgre-all.cmake") | |
| set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin" CACHE PATH "Binary output directory" FORCE) | |
| # Find all .cpp files and compile them | |
| file (GLOB OGRE_TEST_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") | |
| file (GLOB OGRE_TEST_HEADER_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h") | |
| # Add the executeable | |
| add_executable(ogre-test WIN32 ${OGRE_TEST_HEADER_FILES} ${OGRE_TEST_SOURCE_FILES}) | |
| target_link_libraries(ogre-test ${OGRE_LIBRARIES}) | |
| set_target_properties(ogre-test PROPERTIES DEBUG_POSTFIX _d) | |
| # Set Some install options | |
| option(OPT_DISTRIBUTE "Build and package for distribution?" OFF) | |
| if(UNIX AND OPT_DISTRIBUTE) | |
| set(CMAKE_INSTALL_PREFIX "/usr/local") | |
| endif() | |
| if(NOT OPT_DISTRIBUTE AND NOT WIN32) | |
| set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install" CACHE PATH "Install prefix" FORCE) | |
| endif() | |
| if(WIN32 AND NOT OPT_DISTRIBUTE) | |
| set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}" CACHE PATH "Install prefix" FORCE) | |
| endif() | |
| install(TARGETS ogre-test | |
| RUNTIME DESTINATION bin) | |
| # if win32, copy the Ogre DLLs over | |
| if(WIN32) | |
| install(FILES $ENV{OGRE_HOME}/bin/release/OgreMain.dll | |
| $ENV{OGRE_HOME}/bin/release/RenderSystem_Direct3D9.dll | |
| $ENV{OGRE_HOME}/bin/release/RenderSystem_GL.dll | |
| $ENV{OGRE_HOME}/bin/release/Plugin_OctreeSceneManager.dll | |
| $ENV{OGRE_HOME}/bin/release/cg.dll | |
| $ENV{OGRE_HOME}/bin/release/OIS.dll | |
| $ENV{OGRE_HOME}/bin/release/Plugin_CgProgramManager.dll | |
| $ENV{OGRE_HOME}/bin/release/Plugin_ParticleFX.dll | |
| $ENV{OGRE_HOME}/bin/release/Plugin_BSPSceneManager.dll | |
| $ENV{OGRE_HOME}/bin/release/Plugin_CgProgramManager.dll | |
| $ENV{OGRE_HOME}/bin/release/Plugin_PCZSceneManager.dll | |
| $ENV{OGRE_HOME}/bin/release/Plugin_OctreeZone.dll | |
| $ENV{OGRE_HOME}/bin/release/resources.cfg | |
| $ENV{OGRE_HOME}/bin/release/plugins.cfg | |
| DESTINATION bin | |
| CONFIGURATIONS Release RelWithDebInfo | |
| ) | |
| install(FILES $ENV{OGRE_HOME}/bin/debug/OgreMain_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/RenderSystem_Direct3D9_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/RenderSystem_GL_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/Plugin_OctreeSceneManager_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/cg.dll | |
| $ENV{OGRE_HOME}/bin/debug/OIS_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/Plugin_CgProgramManager_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/Plugin_ParticleFX_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/Plugin_BSPSceneManager_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/Plugin_CgProgramManager_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/Plugin_PCZSceneManager_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/Plugin_OctreeZone_d.dll | |
| $ENV{OGRE_HOME}/bin/debug/resources_d.cfg | |
| $ENV{OGRE_HOME}/bin/debug/plugins_d.cfg | |
| DESTINATION bin | |
| CONFIGURATIONS Debug | |
| ) | |
| endif(WIN32) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (CMAKE_BUILD_TYPE STREQUAL "") | |
| # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up | |
| # differentiation between debug and release builds. | |
| set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE) | |
| endif () | |
| set(CMAKE_DEBUG_POSTFIX "_d") | |
| find_package(OGRE REQUIRED) | |
| if(NOT "${OGRE_VERSION_NAME}" STREQUAL "Cthugha") | |
| message(SEND_ERROR "You need Ogre 1.7 Cthugha to build this.") | |
| endif() | |
| set(BOOST_ROOT "$ENV{OGRE_HOME}/boost_1_42") | |
| # Find Boost | |
| if (NOT OGRE_BUILD_PLATFORM_IPHONE) | |
| if (WIN32 OR APPLE) | |
| set(Boost_USE_STATIC_LIBS TRUE) | |
| else () | |
| # Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit | |
| set(Boost_USE_STATIC_LIBS ${OGRE_STATIC}) | |
| endif () | |
| if (MINGW) | |
| # this is probably a bug in CMake: the boost find module tries to look for | |
| # boost libraries with name libboost_*, but CMake already prefixes library | |
| # search names with "lib". This is the workaround. | |
| set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "") | |
| endif () | |
| set(Boost_ADDITIONAL_VERSIONS "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" ) | |
| # Components that need linking (NB does not include header-only components like bind) | |
| set(OGRE_BOOST_COMPONENTS thread date_time) | |
| find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) | |
| if (NOT Boost_FOUND) | |
| # Try again with the other type of libs | |
| set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS}) | |
| find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) | |
| endif() | |
| find_package(Boost QUIET) | |
| # Set up referencing of Boost | |
| include_directories(${Boost_INCLUDE_DIR}) | |
| add_definitions(-DBOOST_ALL_NO_LIB) | |
| set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES}) | |
| endif() | |
| include_directories(${OGRE_INCLUDE_DIRS}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <OgreCamera.h> | |
| #include <OgreEntity.h> | |
| #include <OgreLogManager.h> | |
| #include <OgreRoot.h> | |
| #include <OgreViewport.h> | |
| #include <OgreSceneManager.h> | |
| #include <OgreRenderWindow.h> | |
| #include <OgreConfigFile.h> | |
| int main() | |
| { | |
| // WARNIGN! On windows change this to the path where the default plugin config is saved, | |
| // probably somewhere in the OGRE_SDK dir | |
| std::string pluginsCfg = "/etc/OGRE/plugins.cfg"; | |
| // construct Ogre::Root | |
| Ogre::Root* root = new Ogre::Root(pluginsCfg); | |
| Ogre::RenderWindow* window; | |
| // configure | |
| // Show the configuration dialog and initialise the system | |
| // You can skip this and use root.restoreConfig() to load configuration | |
| // settings if you were sure there are valid ones saved in ogre.cfg | |
| if(root->restoreConfig() || root->showConfigDialog()) | |
| { | |
| // If returned true, user clicked OK so initialise | |
| // Here we choose to let the system create a default rendering window by passing 'true' | |
| window = root->initialise(true, "MinimalOgre Render Window"); | |
| } | |
| else | |
| { | |
| return false; | |
| } | |
| // Create Ogre scene manager | |
| Ogre::SceneManager* sceneMgr = root->createSceneManager(Ogre::ST_GENERIC, "MainSceneManager"); | |
| // Create Camera so we can display something in a viewport | |
| Ogre::Camera* cam = sceneMgr->createCamera("MainCam"); | |
| // Set some camera properies | |
| cam->setAspectRatio(1.33333333f); //< Camera aspect ratio, 1.33333333 is the equivalent of 4:3 | |
| cam->setFOVy(Ogre::Degree(30.0f)); //< Some kind of field of view stuff, don't ask me what that does xD | |
| cam->setNearClipDistance(5.0f); //< Near clip plane, for clipping stuff that gets too close to the camera | |
| cam->setFarClipDistance(1000.0f); //< Far clip plane, for clipping stuff that is reeealy far away from the camera | |
| // One thing to note is that the ratio of far to near clip plane should not exceed 1000 | |
| // because this would result in "deapth fighting" a condition where the GFX card cannot | |
| // decide which object is front most, thus resulting in strange flickering. | |
| // Add a viewport to the window where the camera will render whatever it is pointing at | |
| Ogre::Viewport* vp = window->addViewport(cam, 0); | |
| // Start the render loop | |
| root->startRendering(); | |
| // Delete the root object to make Ogre clean itself up | |
| delete root; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Setup the propper module paths so we can find the FindOGRE module | |
| if(WIN32) | |
| set(CMAKE_MODULE_PATH "$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}") | |
| endif(WIN32) | |
| if(UNIX) | |
| #TODO: Search all possible directories | |
| set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}") | |
| set(CMAKE_MODULE_PATH "/usr/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}") | |
| endif(UNIX) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment