[SOLVED] Window close (x) button not working

Problems building or running the engine, queries about how to use features etc.
Post Reply
wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

[SOLVED] Window close (x) button not working

Post by wojtaso9 » Sat Oct 27, 2018 3:12 pm

Ogre Version: :1.11.3:
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);
}
Last edited by wojtaso9 on Thu Nov 01, 2018 11:43 pm, edited 1 time in total.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 872
Joined: Sun Mar 30, 2014 2:51 pm
x 176
Contact:

Re: Window close (x) button not working

Post by paroj » Sat Oct 27, 2018 4:24 pm

0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: Window close (x) button not working

Post by wojtaso9 » Sat Oct 27, 2018 6:53 pm

Yeah when I was using that setup it worked but I don't believe that's a good long term solution? I mean I would like to have more control over my components cause sooner or later I will need it.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 872
Joined: Sun Mar 30, 2014 2:51 pm
x 176
Contact:

Re: Window close (x) button not working

Post by paroj » Sun Oct 28, 2018 12:22 pm

copying/ extending OgreBites is always an option ;)
0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: Window close (x) button not working

Post by wojtaso9 » Mon Oct 29, 2018 10:32 pm

I tried extending Ogre::ApplicationContext but that changed nothing, the window still can't be closed by clicking x. Can't find any info about it anywhere and I have no idea why that would happen :(
0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: Window close (x) button not working

Post by wojtaso9 » Wed Oct 31, 2018 10:10 pm

Update, I've been experimenting and still couldn't find a fix. Trimmed my code to a minimum resulting in this:

Window.h

Code: Select all

class Window {
  public:
    static bool mShouldWindowClose;

    Window();

    bool init();

  protected:
    bool renderLoop();

  private:
    Ogre::Root* mRoot;
    Ogre::String mResourcesConfig;
    Ogre::String mPluginsConfig;
    Ogre::RenderWindow* mWindow;
Window.cpp

Code: Select all

#include <iostream>
#include <OgreConfigFile.h>
#include <OgreSceneNode.h>
#include <OgreRenderSystem.h>

#include "Window.h"

bool Window::mShouldWindowClose = false;

Window::Window() {
#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 = Ogre::Root::getSingletonPtr();
  mRoot = new Ogre::Root(mPluginsConfig);
}

bool Window::init() {
  Ogre::RenderSystem *renderSystem = mRoot->getRenderSystemByName("OpenGL 3+ Rendering Subsystem");
  // OpenGL Rendering Subsystem also doesn't work
  mRoot->setRenderSystem(renderSystem);
  renderSystem->setConfigOption("Full Screen", "No");
  renderSystem->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour");
  mWindow = mRoot->initialise(false, "TestGame"); // setting this to true and removing next line also doesn't work
  mWindow = mRoot->createRenderWindow("MyWindow", 1240, 900, false);

  renderLoop();
}

bool Window::renderLoop() {
  while (!mShouldWindowClose && !mWindow->isClosed()) {
    mRoot->renderOneFrame();
    Ogre::WindowEventUtilities::messagePump();
  }
}
main.cpp

Code: Select all

#include "window/Window.h"

int main() {
  Window window;
  window.init();
  return 0;
}
This code works, the window shows up, I can resize it, move it but I can't close it by clicking X no matter what. I've run out of ideas :(
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 872
Joined: Sun Mar 30, 2014 2:51 pm
x 176
Contact:

Re: Window close (x) button not working

Post by paroj » Thu Nov 01, 2018 1:25 am

0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: Window close (x) button not working

Post by wojtaso9 » Thu Nov 01, 2018 12:32 pm

I'm gonna check later but hopefully it solves this. Shouldn't I be using WindowEventUtilities? What's the best alternative? Also are there some resources on what are the best practices while using Ogre3D? There are a lot of guides/tutorials but I feel like a lot of them are not optimal shortcuts and most of them are a little outdated. I know there is a deprecated list and I'm using it.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 872
Joined: Sun Mar 30, 2014 2:51 pm
x 176
Contact:

Re: Window close (x) button not working

Post by paroj » Thu Nov 01, 2018 12:58 pm

wojtaso9 wrote:
Thu Nov 01, 2018 12:32 pm
I'm gonna check later but hopefully it solves this. Shouldn't I be using WindowEventUtilities? What's the best alternative?
basically as the docs say: https://ogrecave.github.io/ogre/api/lat ... ml#details

personally I would use SDL2 as ApplicationContext does. (you can spare the event abstraction if you use it directly, though)
0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: Window close (x) button not working

Post by wojtaso9 » Thu Nov 01, 2018 6:21 pm

Great, as you suggested I migrated entirely to SDL2 and it's been working perfectly, thank you!. I suppose it's now better to use whatever SDL2 provides for keyboard/mouse/pad event handling instead of OIS? Any GUI libraries that go well with this stack you can recommend? God I have so many little questions, is there any chat like discord where I could ask simple questions as I don't want to flood the forums.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 872
Joined: Sun Mar 30, 2014 2:51 pm
x 176
Contact:

Re: Window close (x) button not working

Post by paroj » Thu Nov 01, 2018 8:54 pm

wojtaso9 wrote:
Thu Nov 01, 2018 6:21 pm
I suppose it's now better to use whatever SDL2 provides for keyboard/mouse/pad event handling instead of OIS?
yes, OIS is dead
wojtaso9 wrote:
Thu Nov 01, 2018 6:21 pm
Any GUI libraries that go well with this stack you can recommend?
https://github.com/OGRECave/ogre-imgui
wojtaso9 wrote:
Thu Nov 01, 2018 6:21 pm
God I have so many little questions, is there any chat like discord where I could ask simple questions as I don't want to flood the forums.
like the gitter channel I mentioned above?
1 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: [SOLVED] Window close (x) button not working

Post by wojtaso9 » Fri Nov 02, 2018 3:28 pm

Any other suggestions for a UI specifically for a game? IMGui seems like it has one way of doing things and it's mainly used for consoles/debuggers/other tools? Correct me if I'm mistaken? I need something I can implement a GUI with my own art and full customization.
0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: [SOLVED] Window close (x) button not working

Post by wojtaso9 » Fri Nov 02, 2018 11:23 pm

Also, if I use SDL2 to create a window and pass it to Ogre can I still use both SDL2 renderer and ogre renderer like if I wanted to render floating text with SDL2 and all the 3d stuff with ogre? Didn't seem to work for me but making sure I didn't make any mistakes.
0 x

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 537
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 12

Re: [SOLVED] Window close (x) button not working

Post by Slicky » Sat Nov 03, 2018 9:54 am

I don't know if you can with SDL but maybe. I've tried a bit with no luck so far (using 2.1). Look at MyGui for instance as a possible GUI solution.
0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: [SOLVED] Window close (x) button not working

Post by wojtaso9 » Sat Nov 03, 2018 3:41 pm

Thanks, I'll look into that, but meanwhile I'm running into another problem. I still can't figure out why Ogre can't load .material files.
This is my resources.cfg file:

Code: Select all

[Essential]
Zip=/home/wojciech/code/ogre-1.11.3/Samples/Media/packs/SdkTrays.zip
Zip=/home/wojciech/code/ogre-1.11.3/Samples/Media/packs/profiler.zip
FileSystem=/home/wojciech/code/ogre-1.11.3/Samples/Media/thumbnails

[General]
FileSystem=/home/wojciech/code/game/assets/models
This is console output that the folder loads properly:

Code: Select all

Added resource location '/home/wojciech/code/ogre-1.11.3/Samples/Media/thumbnails' of type 'FileSystem' to resource group 'General'
Added resource location '/home/wojciech/code/ogre-1.11.3/Samples/Media/packs/SdkTrays.zip' of type 'Zip' to resource group 'General'
Added resource location '/home/wojciech/code/ogre-1.11.3/Samples/Media/packs/profiler.zip' of type 'Zip' to resource group 'General'
Added resource location '/home/wojciech/code/game/assets/models' of type 'FileSystem' to resource group 'General'
This is the code that creates entities:

Code: Select all

  mNode = CustomWindow::SCENE_MANAGER->getRootSceneNode()->createChildSceneNode(pName, pPosition);
  mTile = CustomWindow::SCENE_MANAGER->createEntity("Tile.mesh"); // This loads properly
  mTile->setMaterialName("TileMaterial"); // This doesn't work
  mTile->setMaterialName("TileMaterial", "General"); // Doesn't work too
  mTile->setMaterialName("TileMaterial.material"); // Neither does this
This is the material file:

Code: Select all

// TileMaterial generated by blender2ogre 2018-11-03 15:29:13.205401

material TileMaterial {
    receive_shadows on
    technique {
        pass TileMaterial {
            lighting on
            ambient 0.18253588676452637 0.8000000715255737 0.052719391882419586 1.0
            diffuse 0.14602871158761843 0.640000066757203 0.042175514134399794 1.0
            specular 0.21991755068302155 0.5 0.10269200056791306 1.0 12.5
            emissive 0.0 0.0 0.0 1.0
            
            alpha_to_coverage off 
            colour_write on 
            cull_hardware clockwise 
            depth_check on 
            depth_func less_equal 
            depth_write on 
            illumination_stage  
            light_clip_planes off 
            light_scissor off 
            normalise_normals off 
            polygon_mode solid 
            scene_blend one zero 
            scene_blend_op add 
            shading gouraud 
            transparent_sorting on 
        }
    }
}
And it's in the exact same folder as Tile.mesh which loads properly.

And when I run this code I get this output:

Code: Select all

Can't assign material 'TileMaterial' to SubEntity of 'Ogre/MO129' because this Material does not exist in group 'General'. Have you forgotten to define it in a .material script?
The .material and .mesh files were generated automatically by Blender to Ogre exporter. I've pretty much ran out of ideas why it doesn't work :(
0 x

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 537
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 12

Re: [SOLVED] Window close (x) button not working

Post by Slicky » Sat Nov 03, 2018 3:53 pm

Hmm check your Ogre.log and make sure it parses the material file like this:

Code: Select all

15:38:34: Parsing scripts for resource group General
15:38:34: Parsing script Quad.program
15:38:34: Parsing script Copyback.material
0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: [SOLVED] Window close (x) button not working

Post by wojtaso9 » Sat Nov 03, 2018 8:28 pm

Nope, nothing quite like your output, nowhere in the logs is there anything about .material. The most relevant part I could find. Full log here:

Code: Select all

20:25:35: Parsing scripts for resource group General
20:25:35: Finished parsing scripts for resource group General
20:25:35: Creating resources for group General
20:25:35: All done
20:25:35: Parsing scripts for resource group OgreAutodetect
20:25:35: Finished parsing scripts for resource group OgreAutodetect
20:25:35: Creating resources for group OgreAutodetect
20:25:35: All done
20:25:35: Parsing scripts for resource group OgreInternal
20:25:35: Finished parsing scripts for resource group OgreInternal
20:25:35: Creating resources for group OgreInternal
20:25:35: All done
20:25:35: Added resource location '/home/wojciech/code/ogre-1.11.3/Samples/Media/thumbnails' of type 'FileSystem' to resource group 'General'
20:25:35: Added resource location '/home/wojciech/code/ogre-1.11.3/Samples/Media/packs/SdkTrays.zip' of type 'Zip' to resource group 'General'
20:25:35: Added resource location '/home/wojciech/code/ogre-1.11.3/Samples/Media/packs/profiler.zip' of type 'Zip' to resource group 'General'
20:25:35: Added resource location '/home/wojciech/code/game/assets/models' of type 'FileSystem' to resource group 'General'
Maybe I load it wrong? This is how I do it:

Code: Select all

  Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  Ogre::ConfigFile config;
  config.load("/home/wojciech/code/game/configs/resources.cfg");
//  Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/home/wojciech/code/game/assets/models/", "FileSystem");
  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);
    }
  }
0 x

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 537
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 12

Re: [SOLVED] Window close (x) button not working

Post by Slicky » Sat Nov 03, 2018 8:43 pm

It looks like the parsing is happening before you add the resource location. Check what you have done different from example apps. Looks like wrong order to me.
0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: [SOLVED] Window close (x) button not working

Post by wojtaso9 » Sat Nov 03, 2018 9:19 pm

Can't see anything wrong with it. I'm doing it almost identical to http://wiki.ogre3d.org/Ogre+Wiki+Tutorial+Framework (or maybe this tutorial is outdated which it very well may be). I create a Ogre::Root, then load plugins, then load resources using the function I posted above. No clue what's happening here :(
0 x

wojtaso9
Gnoblar
Posts: 12
Joined: Sat Oct 27, 2018 3:01 pm

Re: [SOLVED] Window close (x) button not working

Post by wojtaso9 » Sat Nov 03, 2018 10:30 pm

OK the problem is I didn't initialize the ResourceManager at the right time, seems like it had to be done after initialising root, setting render system and creating a window. Seems like the Materials are loading fine now. Thank you guys for your help!!
0 x

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 537
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 12

Re: [SOLVED] Window close (x) button not working

Post by Slicky » Sat Nov 03, 2018 10:34 pm

Try putting initialiseAllResourceGroups after all the config loading code.
0 x

Post Reply