Operating System: :Linux Ubuntu 18.04:
Render System: :OpenGL Rendering Subsystem:
Hi guys, I've followed two different tutorials but feels like both of them are a little outdated. I've been messing around myself but I can't seem to fix the window x button. When I click it, nothing happens and the window doesn't close. Escape button works all fine though. Also the showConfigDialog() method doesn't work for me. And another problem: whenever I focus the window my mouse disappears, I have to alt-tab to see it again. My code:
Code: Select all
#include <iostream>
#include <OgreConfigFile.h>
#include <OgreShaderGenerator.h>
#include <OgreSceneNode.h>
#include <OgreException.h>
#include <OgreRenderSystem.h>
#include <OgreTextureManager.h>
#include <OgreViewport.h>
#include <OgreWindowEventUtilities.h>
#include <OIS/OISEvents.h>
#include "../entity/Entity.h"
#include "Window.h"
Window::Window() : mRoot(nullptr), mResourcesConfig(Ogre::BLANKSTRING), mPluginsConfig(Ogre::BLANKSTRING) {
#ifdef _DEBUG
mResourcesConfig = "/home/wojciech/code/game/configs/resources_d.cfg";
mPluginsConfig = "/home/wojciech/code/game/configs/plugins_d.cfg";
#else
mResourcesConfig = "/home/wojciech/code/game/configs/resources.cfg";
mPluginsConfig = "/home/wojciech/code/game/configs/plugins.cfg";
#endif
mRoot = std::make_unique<Ogre::Root>(mPluginsConfig);
Ogre::ConfigFile config;
config.load(mResourcesConfig);
Ogre::String name, locationType;
Ogre::ConfigFile::SettingsBySection_ settingsBySection = config.getSettingsBySection();
for (const auto &p : settingsBySection) {
for (const auto &r : p.second) {
locationType = r.first;
name = r.second;
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(name, locationType);
}
}
}
Window::~Window() {
Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this);
windowClosed(mWindow);
}
bool Window::go() {
// for (auto &rs : mRoot->getAvailableRenderers()) {
// std::cout << rs->getName() << std::endl;
// }
Ogre::RenderSystem* renderSystem = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
mRoot->setRenderSystem(renderSystem);
renderSystem->setConfigOption("Full Screen", "No");
renderSystem->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour");
mWindow = mRoot->initialise(true, "Test Game");
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
mSceneManager = mRoot->createSceneManager();
mSceneManager->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
Ogre::Light *light = mSceneManager->createLight("Main Light");
Ogre::SceneNode *lightNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
lightNode->attachObject(light);
lightNode->setPosition(20, 80, 50);
mMainEntity = std::make_unique<Entity>(mSceneManager, mSceneManager->getRootSceneNode()->createChildSceneNode(),
mWindow);
OIS::ParamList paramList;
size_t windowHandle = 0;
std::ostringstream windowHandleString;
mWindow->getCustomAttribute("WINDOW", &windowHandle);
windowHandleString << windowHandle;
paramList.insert(std::make_pair(std::string("WINDOW"), windowHandleString.str()));
mInputManager = OIS::InputManager::createInputSystem(paramList);
mKeyboard = static_cast<OIS::Keyboard *>(mInputManager->createInputObject(OIS::OISKeyboard, false));
mMouse = static_cast<OIS::Mouse *>(mInputManager->createInputObject(OIS::OISMouse, false));
windowResized(mWindow);
Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
mRoot->addFrameListener(this);
mRoot->startRendering();
}
bool Window::keyPressed(const OIS::KeyEvent &keyEvent) {
switch (keyEvent.key) {
case OIS::KC_E:
std::cout << "rotating right" << std::endl;
mMainEntity->rotateCameraRight();
}
}
void Window::windowResized(Ogre::RenderWindow *renderWindow) {
unsigned int width, height, depth;
int left, top;
renderWindow->getMetrics(width, height, depth, left, top);
const OIS::MouseState &mouseState = mMouse->getMouseState();
mouseState.width = width;
mouseState.height = height;
}
void Window::windowClosed(Ogre::RenderWindow *renderWindow) {
if (renderWindow == mWindow && mInputManager) {
mInputManager->destroyInputObject(mMouse);
mInputManager->destroyInputObject(mKeyboard);
OIS::InputManager::destroyInputSystem(mInputManager);
mInputManager = nullptr;
}
}
bool Window::frameRenderingQueued(const Ogre::FrameEvent &event) {
if (mWindow->isClosed())
return false;
mKeyboard->capture();
mMouse->capture();
return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
}