From 3896fd218a5677423622c687eea9e04b8ec47213 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Thu, 8 Jul 2010 11:53:59 +0200 Subject: [PATCH] Added stand-alone GUI test, compiles and runs --- .gitignore | 1 + CMakeLists.txt | 12 +++++++--- apps/mygui_dev/CMakeLists.txt | 11 +++++++++ apps/mygui_dev/main.cpp | 35 +++++++++++++++++++++++++++++ apps/openmw/mwrender/mwscene.cpp | 22 ++---------------- apps/openmw/mwrender/mwscene.hpp | 9 +++----- components/engine/ogre/renderer.cpp | 22 ++++++++++++++++++ components/engine/ogre/renderer.hpp | 23 ++++++++++++++++++- old_d_version/gui/cpp_mygui.cpp | 10 --------- old_d_version/ogre/cpp_ogre.cpp | 12 ---------- 10 files changed, 105 insertions(+), 52 deletions(-) create mode 100644 apps/mygui_dev/CMakeLists.txt create mode 100644 apps/mygui_dev/main.cpp delete mode 100644 old_d_version/ogre/cpp_ogre.cpp diff --git a/.gitignore b/.gitignore index 25bfc9436..8f48283fa 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ resources mwcompiler mwinterpreter clientconsole +MyGUI.log diff --git a/CMakeLists.txt b/CMakeLists.txt index c56eb4e3c..f89cb85f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,9 +130,9 @@ file(GLOB ESM_HEADER components/esm/*.hpp) source_group(components\\esm FILES ${ESM_HEADER}) set(OGRE - components/engine/ogre/renderer.cpp) + ${CMAKE_SOURCE_DIR}/components/engine/ogre/renderer.cpp) set(OGRE_HEADER - components/engine/ogre/renderer.hpp) + ${CMAKE_SOURCE_DIR}/components/engine/ogre/renderer.hpp) source_group(components\\engine\\ogre FILES ${OGRE} ${OGRE_HEADER}) set(INPUT @@ -203,7 +203,12 @@ include_directories("." ${OGRE_INCLUDE_DIR} ${OGRE_INCLUDE_DIR}/Ogre ${OIS_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${PLATFORM_INCLUDE_DIR} - ${CMAKE_HOME_DIRECTORY}/extern/caelum/include) + ${CMAKE_HOME_DIRECTORY}/extern/caelum/include + ${CMAKE_HOME_DIRECTORY}/extern/mygui_3.0.1/MyGUIEngine/include + ${CMAKE_HOME_DIRECTORY}/extern/mygui_3.0.1/OgrePlatform/include +) + + link_directories(${Boost_LIBRARY_DIRS} ${OGRE_LIB_DIR}) add_subdirectory( extern/caelum ) @@ -264,6 +269,7 @@ endif (APPLE) # Other apps and tools add_subdirectory( apps/clientconsole ) +add_subdirectory( apps/mygui_dev ) # Apple bundling if (APPLE) diff --git a/apps/mygui_dev/CMakeLists.txt b/apps/mygui_dev/CMakeLists.txt new file mode 100644 index 000000000..9d3c3790f --- /dev/null +++ b/apps/mygui_dev/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(mygui_test + main.cpp + ${OGRE} + ${OGRE_HEADER} +) +target_link_libraries(mygui_test + ${OGRE_LIBRARIES} + ${OIS_LIBRARIES} + MyGUIEngine + MyGUI.OgrePlatform +) diff --git a/apps/mygui_dev/main.cpp b/apps/mygui_dev/main.cpp new file mode 100644 index 000000000..027585363 --- /dev/null +++ b/apps/mygui_dev/main.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +#include +#include +using namespace MyGUI; + +#include +#include + +int main() +{ + Render::OgreRenderer ogre; + ogre.configure(false, "plugins.cfg", false); + ogre.createWindow("MyGUI test"); + ogre.createScene(); + + // Disable MyGUI logging + LogManager::initialise(); + LogManager::setSTDOutputEnabled(false); + + // Set up OGRE connection to MyGUI + OgrePlatform *platform = new OgrePlatform(); + platform->initialise(ogre.getWindow(), ogre.getScene()); + + // Create GUI + Gui *gui = new Gui(); + gui->initialise(); + + // Add the Morrowind windows resources + Ogre::ResourceGroupManager::getSingleton(). + addResourceLocation("resources/mygui/", "FileSystem", "General"); + + return 0; +} diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index 08172f885..0424647e1 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -15,22 +15,7 @@ using namespace Ogre; MWScene::MWScene(Render::OgreRenderer &_rend) : rend(_rend) { - Root *root = rend.getRoot(); - RenderWindow *window = rend.getWindow(); - - // Get the SceneManager, in this case a generic one - sceneMgr = root->createSceneManager(ST_GENERIC); - - // Create the camera - camera = sceneMgr->createCamera("PlayerCam"); - camera->setNearClipDistance(5); - - // Create one viewport, entire window - vp = window->addViewport(camera); - - // Alter the camera aspect ratio to match the viewport - camera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight())); - camera->setFOVy(Degree(55)); + rend.createScene("PlayerCam", 55, 5); // Set default mipmap level (NB some APIs ignore this) TextureManager::getSingleton().setDefaultNumMipmaps(5); @@ -43,10 +28,7 @@ MWScene::MWScene(Render::OgreRenderer &_rend) // the screen (when x is to the right.) This is the orientation that // Morrowind uses, and it automagically makes everything work as it // should. - SceneNode *rt = sceneMgr->getRootSceneNode(); + SceneNode *rt = rend.getScene()->getRootSceneNode(); mwRoot = rt->createChildSceneNode(); mwRoot->pitch(Degree(-90)); - - // For testing - sceneMgr->setAmbientLight(ColourValue(1,1,1)); } diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index bca2b831b..d65b7944b 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -21,9 +21,6 @@ namespace MWRender class MWScene { Render::OgreRenderer &rend; - Ogre::SceneManager *sceneMgr; - Ogre::Camera *camera; - Ogre::Viewport *vp; // Root node for all objects added to the scene. This is rotated so // that the OGRE coordinate system matches that used internally in @@ -33,10 +30,10 @@ namespace MWRender public: MWScene(Render::OgreRenderer &_rend); + Ogre::Camera *getCamera() { return rend.getCamera(); } Ogre::SceneNode *getRoot() { return mwRoot; } - Ogre::SceneManager *getMgr() { return sceneMgr; } - Ogre::Camera *getCamera() { return camera; } - Ogre::Viewport *getViewport() { return vp; } + Ogre::SceneManager *getMgr() { return rend.getScene(); } + Ogre::Viewport *getViewport() { return rend.getViewport(); } }; } diff --git a/components/engine/ogre/renderer.cpp b/components/engine/ogre/renderer.cpp index 61e2478eb..982f0f050 100644 --- a/components/engine/ogre/renderer.cpp +++ b/components/engine/ogre/renderer.cpp @@ -5,6 +5,8 @@ #include "OgreLogManager.h" #include "OgreLog.h" +#include + using namespace Ogre; using namespace Render; @@ -53,6 +55,26 @@ bool OgreRenderer::configure(bool showConfig, void OgreRenderer::createWindow(const std::string &title) { + assert(mRoot); // Initialize OGRE window mWindow = mRoot->initialise(true, title, ""); } + +void OgreRenderer::createScene(const std::string camName, float fov, float nearClip) +{ + assert(mRoot); + assert(mWindow); + // Get the SceneManager, in this case a generic one + mScene = mRoot->createSceneManager(ST_GENERIC); + + // Create the camera + mCamera = mScene->createCamera(camName); + mCamera->setNearClipDistance(nearClip); + mCamera->setFOVy(Degree(fov)); + + // Create one viewport, entire window + mView = mWindow->addViewport(mCamera); + + // Alter the camera aspect ratio to match the viewport + mCamera->setAspectRatio(Real(mView->getActualWidth()) / Real(mView->getActualHeight())); +} diff --git a/components/engine/ogre/renderer.hpp b/components/engine/ogre/renderer.hpp index 9f8069ca6..98c1a68d2 100644 --- a/components/engine/ogre/renderer.hpp +++ b/components/engine/ogre/renderer.hpp @@ -12,6 +12,9 @@ namespace Ogre { class Root; class RenderWindow; + class SceneManager; + class Camera; + class Viewport; } namespace Render @@ -20,11 +23,14 @@ namespace Render { Ogre::Root *mRoot; Ogre::RenderWindow *mWindow; + Ogre::SceneManager *mScene; + Ogre::Camera *mCamera; + Ogre::Viewport *mView; bool logging; public: OgreRenderer() - : mRoot(NULL) {} + : mRoot(NULL), mWindow(NULL), mScene(NULL) {} ~OgreRenderer() { cleanup(); } /** Configure the renderer. This will load configuration files and @@ -36,6 +42,12 @@ namespace Render /// Create a window with the given title void createWindow(const std::string &title); + /// Set up the scene manager, camera and viewport + void createScene(const std::string camName="Camera",// Camera name + float fov=55, // Field of view angle + float nearClip=5 // Near clip distance + ); + /// Kill the renderer. void cleanup(); @@ -50,6 +62,15 @@ namespace Render /// Get the rendering window Ogre::RenderWindow *getWindow() { return mWindow; } + + /// Get the scene manager + Ogre::SceneManager *getScene() { return mScene; } + + /// Camera + Ogre::Camera *getCamera() { return mCamera; } + + /// Viewport + Ogre::Viewport *getViewport() { return mView; } }; } diff --git a/old_d_version/gui/cpp_mygui.cpp b/old_d_version/gui/cpp_mygui.cpp index 2c4388a03..14dc54a41 100644 --- a/old_d_version/gui/cpp_mygui.cpp +++ b/old_d_version/gui/cpp_mygui.cpp @@ -463,16 +463,6 @@ extern "C" void gui_showHUD() extern "C" void gui_setupGUI(int32_t debugOut) { - ResourceGroupManager::getSingleton(). - addResourceLocation("media_mygui", "FileSystem", "General"); - - // Enable/disable logging to stdout - MyGUI::LogManager::initialise(); - MyGUI::LogManager::setSTDOutputEnabled(debugOut); - - mGUI = new MyGUI::Gui(); - mGUI->initialise(mWindow); - int mWidth = mWindow->getWidth(); int mHeight = mWindow->getHeight(); diff --git a/old_d_version/ogre/cpp_ogre.cpp b/old_d_version/ogre/cpp_ogre.cpp deleted file mode 100644 index 61385967f..000000000 --- a/old_d_version/ogre/cpp_ogre.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -// The global GUI object -MyGUI::Gui *mGUI; - -// This is used to determine if we are displaying any gui elements -// right now. If we are (and guiMode > 0), we redirect mouse/keyboard -// input into MyGUI. -int32_t guiMode = 0; - -#include "../gui/cpp_mygui.cpp" -#include "../terrain/cpp_terrain.cpp"