Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2.0 and CEGUI 7.7 issue  (Read 2992 times)

0 Members and 1 Guest are viewing this topic.

Calneon

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML 2.0 and CEGUI 7.7 issue
« on: November 11, 2012, 05:18:54 pm »
I'm having trouble implementing CEGUI into my SFML game. I did some testing and found out that it's to do with drawing a sprite.

Here's what the basic Hello World CEGUI tutorial window looks like for me when I also try to draw a sprite:



And this is what it looks like with the sprite draw call commented out:



Here's the code:

#include <CEGUI.h>
#include <RendererModules\OpenGL\CEGUIOpenGLRenderer.h>
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
using namespace CEGUI;

int main(int /*argc*/, char* /*argv*/[])
{
        sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML works!");
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);

        CEGUI::OpenGLRenderer& myRenderer = CEGUI::OpenGLRenderer::create();
        CEGUI::System::create( myRenderer );

        // 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::Imageset::setDefaultResourceGroup("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");

        SchemeManager::getSingleton().create("TaharezLook.scheme");
        System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
        WindowManager& winMgr = WindowManager::getSingleton();
        DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
        System::getSingleton().setGUISheet(root);
        FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "Demo Window");
        root->addChildWindow(wnd);
        wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
    wnd->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
        wnd->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
    wnd->setMinSize(UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
        wnd->setText("Hello World!");

        sf::Texture     texture;
        sf::Sprite sprite;
        texture.loadFromFile("Data/Textures/Ship.png");
        sprite.setTexture(texture);

        while (window.isOpen())
        {
                sf::Event event;

                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear(sf::Color(255, 255, 255));
                window.draw(sprite);
                CEGUI::System::getSingleton().renderGUI();
                window.display();
        }

        return 0;
}

Drawing a shape works properly, it's only a sprite which messes things up. Also, once the sprite draw call has been called once, I can stop calling it and the issue still persists. It's messing with the underlying OpenGL somehow.

Anybody have any advice?

FRex

  • Hero Member
  • *****
  • Posts: 1847
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFML 2.0 and CEGUI 7.7 issue
« Reply #1 on: November 11, 2012, 05:33:12 pm »
Try call resetGLStates on your window before drawing your gui.
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 and CEGUI 7.7 issue
« Reply #2 on: November 11, 2012, 05:36:24 pm »
It could be that CEGUI changes some OpenGL states or similar, thus you probably will have to use push/popGLStates, but I've no idea what CEGUI does in the background...
There's an outdated tutorial on the old wiki on how to use CEGUI, but it's for SFML 1.6 and an old CEGUI version.

Maybe you'd find better help on their forum (if that exists), since there might be able to tell you what to do, to get CEGUI working with SFML 2.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Calneon

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML 2.0 and CEGUI 7.7 issue
« Reply #3 on: November 11, 2012, 05:43:18 pm »
resetGLStates doesn't seem to do anything. If I draw the sprite after initialization, then reset states it still doesn't work. I'll fiddle around with push/pop states and see if that helps. I also have a thread on the CEGUI forums but no replies there yet.

EDIT: Success! Push/pop states was the way to go. Here's what my render loop looks like now:

                window.clear(sf::Color(255, 255, 255));

                window.pushGLStates();
                window.draw(sprite);
                window.popGLStates();

                CEGUI::System::getSingleton().renderGUI();

                window.display();
« Last Edit: November 11, 2012, 05:46:02 pm by Calneon »

alienjon

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML 2.0 and CEGUI 7.7 issue
« Reply #4 on: February 25, 2013, 12:58:03 am »
Quote from: Calneon
EDIT: Success! Push/pop states was the way to go. Here's what my render loop looks like now:

Oh good grief thank you.  I was having the exact same problem and starting to pull my hair out.  Thanks for the fix on this.  On a related note:

Quote from: eXpl0it3r
There's an outdated tutorial on the old wiki on how to use CEGUI, but it's for SFML 1.6 and an old CEGUI version.
  The whole reason I was having this problem is related to my trying to learn CEGUI with SFML.  I've read through and updated the tutotial code here for SFML 2.0 and CEGUI 0.79.  Not the cleanest I've written, but it works.  I might look into updating the WIKI, as I'm not particularly happy with the CEGUI tutorials for 7.9.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 and CEGUI 7.7 issue
« Reply #5 on: February 25, 2013, 01:19:38 am »
I might look into updating the WIKI, as I'm not particularly happy with the CEGUI tutorials for 7.9.
Make sure to update the new wiki on the GitHub page! ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/