flickering CEGUI window

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

MetaPhaze
Just popping in
Just popping in
Posts: 11
Joined: Fri Jan 23, 2015 15:30

Re: flickering CEGUI window

Postby MetaPhaze » Fri Jan 30, 2015 00:19

I've now tried 0.8.4

eix cegui
[I] dev-games/cegui
Available versions: 0.6.2b 0.7.7-r1{tbz2} (~)0.7.9{tbz2} (~)0.8.3 (~)0.8.4{tbz2} {bidi debug devil directfb doc examples expat freeimage gtk irrlicht lua ogre opengl pcre python static-libs tinyxml truetype xerces-c (+)xml zip PYTHON_TARGETS="python2_7"}
Installed versions: 0.8.4{tbz2}(04:56:04 PM 01/29/2015)(doc expat freeimage irrlicht lua ogre opengl pcre python static-libs tinyxml truetype xml zip -bidi -debug -devil -xerces-c PYTHON_TARGETS="python2_7")
Homepage: http://www.cegui.org.uk/
Description: Crazy Eddie's GUI System

Same deal when injecting inputs every frame.

MetaPhaze
Just popping in
Just popping in
Posts: 11
Joined: Fri Jan 23, 2015 15:30

Re: flickering CEGUI window

Postby MetaPhaze » Fri Jan 30, 2015 00:21

Code: Select all

#include <irrlicht.h>
#include <CEGUI/CEGUI.h>
#include <CEGUI/RendererModules/Irrlicht/Renderer.h>
#include <string>
#include <uuid/uuid.h>
#include <map>
#include <iostream>
#include "driverChoice.h"
#include "Component.h"
#include "EntityManager.h"
#include "Entity.h"

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

class MyEventReceiver : public irr::IEventReceiver {

   public:
      struct SMouseState {
         irr::core::position2di Position;
         bool LeftButtonDown;
         bool ButtonChanged;
         bool PositionChanged;
         SMouseState() : LeftButtonDown ( false ), ButtonChanged ( false ), PositionChanged ( false ) {}
         } MouseState;




      virtual bool OnEvent ( const irr::SEvent& event ) {
            /*   Soganatsu: !!!!!!!
            Okay, fixed it ;) Thansk anyways. For everyone with the same problem, here's the solution:
            You may only inject key/mouse Input everytime a key/mousestate actually changes, NOT every frame. */
         // Remember the mouse state
         if ( event.EventType == irr::EET_MOUSE_INPUT_EVENT ) {
               switch ( event.MouseInput.Event ) {
                     case irr::EMIE_LMOUSE_PRESSED_DOWN:
                        if(MouseState.LeftButtonDown == true) MouseState.ButtonChanged = false;
                        else MouseState.ButtonChanged = true;
                        MouseState.LeftButtonDown = true;
                        break;

                     case irr::EMIE_LMOUSE_LEFT_UP:
                        if(MouseState.LeftButtonDown == false) MouseState.ButtonChanged = false;
                        else MouseState.ButtonChanged = true;
                        MouseState.LeftButtonDown = false;
                        break;

                     case irr::EMIE_MOUSE_MOVED:
                        if(event.MouseInput.X != MouseState.Position.X) MouseState.PositionChanged = true;
                        else if (event.MouseInput.Y != MouseState.Position.Y) MouseState.PositionChanged = true;
                        else MouseState.PositionChanged = false;
                        MouseState.Position.X = event.MouseInput.X;
                        MouseState.Position.Y = event.MouseInput.Y;
                        break;

                     default:
                        // We won't use the wheel
                        break;
                     }

               //if(MouseState.PositionChanged == true)
               //{
               MouseState.PositionChanged = false;
               CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition ( this->GetMouseState().Position.X, this->GetMouseState().Position.Y );

               //}
               //if(MouseState.ButtonChanged == true)
               //{
               MouseState.ButtonChanged = false;

                  switch ( this->GetMouseState().LeftButtonDown ) {
                     case true:
                        CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown ( CEGUI::LeftButton );
                        break;

                     case false:
                        CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp ( CEGUI::LeftButton );
                        break;
                     }
               //}

               }

         // The state of each connected joystick is sent to us
         // once every run() of the Irrlicht device.  Store the
         // state of the first joystick, ignoring other joysticks.
         // This is currently only supported on Windows and Linux.
         if ( event.EventType == irr::EET_JOYSTICK_INPUT_EVENT
               && event.JoystickEvent.Joystick == 0 ) {
               JoystickState = event.JoystickEvent;
               }

         return false;
         }

      const irr::SEvent::SJoystickEvent& GetJoystickState ( void ) const
         {
         return JoystickState;
         }

      const SMouseState& GetMouseState ( void ) const
         {
         return MouseState;
         }


      MyEventReceiver()
         {
         }

      ~MyEventReceiver()
         {
         }

   private:
      irr::SEvent::SJoystickEvent JoystickState;
   };


//At first, we let the user select the driver type, then start up the engine, set a caption, and get a pointer to the video driver.

int main()
   {
   // ask user for driver
   irr::video::E_DRIVER_TYPE driverType = irr::driverChoiceConsole();

   if ( driverType == irr::video::EDT_COUNT )
      return 1;

   // create device
   MyEventReceiver ER;
   irr::IrrlichtDevice* device = irr::createDevice ( driverType,
                          irr::core::dimension2d<irr::u32> ( 1920, 1080 ), 24, false, true, true, &ER );

   if ( device == 0 )
      return 1; // could not create selected driver.

   // Bootstrap CEGUI::System with an IrrlichtRenderer object, an Irrlicht based
   // ResourceProvider, and an Irrlicht based ImageCodec.
   CEGUI::IrrlichtRenderer& myRenderer =
      CEGUI::IrrlichtRenderer::bootstrapSystem ( *device );

   device->setWindowCaption ( L"badDude" );

   irr::video::IVideoDriver* driver = device->getVideoDriver();

   // initialise the required dirs for the DefaultResourceProvider
   CEGUI::DefaultResourceProvider* rp = static_cast<CEGUI::DefaultResourceProvider*>
                               ( CEGUI::System::getSingleton().getResourceProvider() );
   rp->setResourceGroupDirectory ( "schemes", "../../datafiles/schemes/" );
   rp->setResourceGroupDirectory ( "imagesets", "../../datafiles/imagesets/" );
   rp->setResourceGroupDirectory ( "fonts", "../../datafiles/fonts/" );
   rp->setResourceGroupDirectory ( "layouts", "../../datafiles/layouts/" );
   rp->setResourceGroupDirectory ( "looknfeels", "../../datafiles/looknfeel/" );
   rp->setResourceGroupDirectory ( "lua_scripts", "../../datafiles/lua_scripts/" );
// This is only really needed if you are using Xerces and need to
// specify the schemas location
   rp->setResourceGroupDirectory ( "schemas", "../../datafiles/xml_schemas/" );
// set the default resource groups to be used
   CEGUI::ImageManager::setImagesetDefaultResourceGroup ( "imagesets" );
   CEGUI::Font::setDefaultResourceGroup ( "fonts" );
   CEGUI::Scheme::setDefaultResourceGroup ( "schemes" );
   CEGUI::WidgetLookManager::setDefaultResourceGroup ( "looknfeels" );
   CEGUI::WindowManager::setDefaultResourceGroup ( "layouts" );
   CEGUI::ScriptModule::setDefaultResourceGroup ( "lua_scripts" );
// setup default group for validation schemas
   CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();

   if ( parser->isPropertyPresent ( "SchemaDefaultResourceGroup" ) )
      parser->setProperty ( "SchemaDefaultResourceGroup", "schemas" );

// create (load) the TaharezLook scheme file
// (this auto-loads the TaharezLook looknfeel and imageset files)
   CEGUI::SchemeManager::getSingleton().createFromFile ( "TaharezLook.scheme" );
// create (load) a font.
// The first font loaded automatically becomes the default font, but note
// that the scheme might have already loaded a font, so there may already
// be a default set - if we want the "Commonweath-10" font to definitely
// be the default, we should set the default explicitly afterwards.
   CEGUI::FontManager::getSingleton().createFromFile ( "DejaVuSans-10.font" );


   CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
   CEGUI::Window* myRootWindow = wmgr.createWindow ( "DefaultWindow", "root" );
   CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow ( myRootWindow );
   CEGUI::FrameWindow* fWnd = static_cast<CEGUI::FrameWindow*> ( wmgr.createWindow ( "TaharezLook/FrameWindow", "testWindow" ) );
   CEGUI::Window * newWindow = wmgr.loadLayoutFromFile("mylayout.layout");
   myRootWindow->addChild(newWindow);

   fWnd->setPosition ( CEGUI::UVector2 ( CEGUI::UDim ( 0.25f, 0 ), CEGUI::UDim ( 0.25f, 0 ) ) );
   fWnd->setSize ( CEGUI::USize ( CEGUI::UDim ( 0.5f, 0 ), CEGUI::UDim ( 0.5f, 0 ) ) );
   fWnd->setText ( "Hello World" );
   myRootWindow->addChild ( fWnd );
//All 2d graphics in this example are put together into one texture, 2ddemo.png. Because we want to draw colorkey based sprites, we need to load this texture and tell the engine, which part of it should be transparent based on a colorkey.
//
//In this example, we don't tell it the color directly, we just say "Hey Irrlicht Engine, you'll find the color I want at position (0,0) on the texture.". Instead, it would be also possible to call driver->makeColorKeyTexture(images, irr::video::SColor(0,0,0,0)), to make e.g. all black pixels transparent. Please note that makeColorKeyTexture just creates an alpha channel based on the color.

   irr::video::ITexture* images = driver->getTexture ( "/home/metaphaze/models/BatBean.png" );
   driver->makeColorKeyTexture ( images, irr::core::position2d<irr::s32> ( 0, 0 ) );

//To be able to draw some text with two different fonts, we first load them. Ok, we load just one. As the first font we just use the default font which is built into the engine. Also, we define two rectangles which specify the position of the images of the red imps (little flying creatures) in the texture.

   irr::gui::IGUIFont* font = device->getGUIEnvironment()->getBuiltInFont();
   irr::gui::IGUIFont* font2 =
      device->getGUIEnvironment()->getFont ( "/home/metaphaze/cr_media/fonts/VeraBd.ttf" );

   irr::core::rect<irr::s32> imp1 ( 349, 15, 385, 78 );
   irr::core::rect<irr::s32> imp2 ( 387, 15, 423, 78 );

//Prepare a nicely filtering 2d render mode for special cases.

   driver->getMaterial2D().TextureLayer[0].BilinearFilter = true;
   driver->getMaterial2D().AntiAliasing = irr::video::EAAM_FULL_BASIC;
   Entity entity;
   irr::core::stringw myguid = entity.getID().c_str();
   irr::scene::ISceneManager* smgr = device->getSceneManager();
//Everything is prepared, now we can draw everything in the draw loop, between the begin scene and end scene calls. In this example, we are just doing 2d graphics, but it would be no problem to mix them with 3d graphics. Just try it out, and draw some 3d vertices or set up a scene with the scene manager and draw it.

   while ( device->run() && driver ) {
         if ( device->isWindowActive() ) {
               irr::u32 time = device->getTimer()->getTime();

               // start the scene
               driver->beginScene(true, true, irr::video::SColor(150,50,50,50));
               driver->draw2DImage(images, irr::core::position2d<irr::s32>(50,50), irr::core::rect<irr::s32>(0,0,640,480), 0, irr::video::SColor(255,255,255,255), true);
               // draw main scene
               smgr->drawAll();
               std::string sTime;
               std::ostringstream convert;
               convert << time;
               sTime = convert.str();
               fWnd->insertText(sTime, 0);
               // draw gui
               CEGUI::System::getSingleton().injectTimePulse((float)time);
               CEGUI::System::getSingleton().renderAllGUIContexts();

               // end the scene
               driver->endScene();

               }
         }

   device->drop();

   return 0;
   }

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: flickering CEGUI window

Postby Ident » Fri Feb 20, 2015 08:31

I am trying it out with OGL3 and CEGUI v0-8.

I alternatively added the following linees to the samplebrowser's update function which is called every frame:

Code: Select all

CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition ( 20.f, 20.f);

which, as expected, did nothing to the rendering and worked fine. Weirdly enough, my mouse movement was registered but not displayed (400FPS), I know it was registered due to hover-effects causing selections. Anyways, this worked fine.

Code: Select all

CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown ( CEGUI::LeftButton );

Works as expected. Buttons are pushed when hovering. No flickering.

Code: Select all

 CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp ( CEGUI::LeftButton );

No flickering, works as expected.

Code: Select all

CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown ( CEGUI::LeftButton );
CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp ( CEGUI::LeftButton );

No flickering, automatically clicks on anything upon hovering.



Conclusion: I can't reproduce your issue. The problem might, under circumstances, lie in your code or in Irrlicht (the latter I consider unlikely). Please try to get our v0-8 branch's code (not something from a packager) and build CEGUI yourself, then start the samplebrowser and see if you can reproduce the flickering - then share your changes with me. We got other UNIX users so it would be surprising if only you saw flickering there. Also tell me what you changed to make it flicker in the SampleBrowser.

So far I can unfortunately not do anything ):
CrazyEddie: "I don't like GUIs"


Return to “Help”

Who is online

Users browsing this forum: No registered users and 2 guests