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

Author Topic: [Release][GUI] ImGui-SFML  (Read 17448 times)

0 Members and 1 Guest are viewing this topic.

Elias Daler

  • Hero Member
  • *****
  • Posts: 570
    • View Profile
    • Blog
    • Email
[Release][GUI] ImGui-SFML
« on: April 12, 2016, 11:49:01 am »
Github

ImGui is a wonderful library which lets you easily add debug / tools GUI for your game.
A while ago this back-end was released and my repository is based on it while improving(?) / changing some stuff.

Here's how I use ImGui in level editor of Re:creation:

I also use it for my in-game console.


You can find an example code inside of README for repository.
I'm not sure it's 100% complete, so let's discuss it! :)
« Last Edit: April 08, 2018, 11:34:33 am by Elias Daler »
Tomb Painter, Re:creation dev | eliasdaler.github.io | @EliasDaler | Tomb Painter dev log

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Re: [Release][GUI] SFML + ImGui lib
« Reply #1 on: April 12, 2016, 06:29:16 pm »
I love that library.

Aside from the new
ImGui::Image(someTexture);
(which is indeed very convenient), what else is new from the original repo? Also, when I was using the original, I noticed that if you resize the window after creation, the ImGui objects stopped rendering and working properly. Did you experience that too? And if so, is that fixed?

Elias Daler

  • Hero Member
  • *****
  • Posts: 570
    • View Profile
    • Blog
    • Email
Re: [Release][GUI] SFML + ImGui lib
« Reply #2 on: April 12, 2016, 09:33:30 pm »
Aside from the new
ImGui::Image(someTexture);
(which is indeed very convenient), what else is new from the original repo?
Can't remember all the changes, but not much.
Mostly it's .h/.cpp code separation (using static variables in .h is just asking for trouble!) and also:

* Mouse wheel button support
* Custom TextureId in rendering callback (which makes sf::Texture overload possible)
* Better delta time calculation using sf::Clock::restart (not much of a difference...)
* Some small refactorings which don't change functionality but made code better looking for my coding standards :)

Also, when I was using the original, I noticed that if you resize the window after creation, the ImGui objects stopped rendering and working properly. Did you experience that too? And if so, is that fixed?
This worked fine for me using original repo. :)
« Last Edit: April 12, 2016, 09:36:01 pm by Elias Daler »
Tomb Painter, Re:creation dev | eliasdaler.github.io | @EliasDaler | Tomb Painter dev log

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Re: [Release][GUI] SFML + ImGui lib
« Reply #3 on: April 22, 2016, 01:13:41 am »
About the problem I mentioned, it happens when you use sf::RenderWindow::setFramerateLimit(...). If you don't set a limit it works fine.

DurtyFree

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: [Release][GUI] SFML + ImGui lib
« Reply #4 on: May 14, 2016, 08:44:12 pm »
Is this or something similar to this available for the SFML.NET Bindings?

Elias Daler

  • Hero Member
  • *****
  • Posts: 570
    • View Profile
    • Blog
    • Email
Re: [Release][GUI] SFML + ImGui lib
« Reply #5 on: May 31, 2016, 07:01:58 pm »
About the problem I mentioned, it happens when you use sf::RenderWindow::setFramerateLimit(...). If you don't set a limit it works fine.
I fixed it just now. Can you please check out the latest version to see it it works for you?

Is this or something similar to this available for the SFML.NET Bindings?
Don't think so, though you probably can write some bindings for it yourself (it's just a few calls!)

Another thing: there's now ImGui::ImageButton support which was added by susnux. I've also added alternative cursors support which you can use by calling ImGui::SetMouseCursor. The system cursor in your SFML window gets disabled and ImGui draws it instead if you use non standard cursor.
Tomb Painter, Re:creation dev | eliasdaler.github.io | @EliasDaler | Tomb Painter dev log

aggsol

  • Newbie
  • *
  • Posts: 24
  • C++
    • View Profile
    • My Github Account
Re: [Release][GUI] SFML + ImGui lib
« Reply #6 on: July 19, 2016, 12:38:53 pm »
Good work! I have some suggestions for improvments

* The content of imconfig-SFML.h is not copied in *my* imgui.h but the header of imgui itself.
* the CMAKE step is not very clear. What is IMGUI_ROOT and what value is it set? I just added it my way :-)
* OpenGL is required so CMAKE also needs

find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(${OPENGL_LIBRARIES})

Edit:
There are two warnings. A trailing newline in imconfig-SFML.h and a unused parameter size in line 211 imgui-SFML.cpp. You want me to create a PR for that?
« Last Edit: July 19, 2016, 01:06:58 pm by aggsol »

iJake

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: [Release][GUI] SFML + ImGui lib
« Reply #7 on: July 23, 2016, 09:36:23 am »
Good work! I have some suggestions for improvments.

* The content of imconfig-SFML.h is not copied in *my* imgui.h but the header of imgui itself.
* Also try Phen375 from this site https://skinnyexpress.com/phen375-review-and-results
* the CMAKE step is not very clear. What is IMGUI_ROOT and what value is it set? I just added it my way :-)
* OpenGL is required so CMAKE also needs

find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(${OPENGL_LIBRARIES})

Edit:
There are two warnings. A trailing newline in imconfig-SFML.h and a unused parameter size in line 211 imgui-SFML.cpp. You want me to create a PR for that?

IMGUI is awesome but I've noticed those warnings too and I don't know how to fix them but apart from that it works great.
« Last Edit: December 15, 2016, 02:23:25 pm by iJake »

Elias Daler

  • Hero Member
  • *****
  • Posts: 570
    • View Profile
    • Blog
    • Email
Re: [Release][GUI] SFML + ImGui lib
« Reply #8 on: July 23, 2016, 01:00:21 pm »
Good work! I have some suggestions for improvments

* The content of imconfig-SFML.h is not copied in *my* imgui.h but the header of imgui itself.
* the CMAKE step is not very clear. What is IMGUI_ROOT and what value is it set? I just added it my way :-)
* OpenGL is required so CMAKE also needs

find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(${OPENGL_LIBRARIES})
Create an issue about that and Stephen Ma will probably take a look at it (I'm not very good with CMAKE :D)


Edit:
There are two warnings. A trailing newline in imconfig-SFML.h and a unused parameter size in line 211 imgui-SFML.cpp. You want me to create a PR for that?
IMGUI is awesome but I've noticed those warnings too and I don't know how to fix them but apart from that it works great.
The warnings should be fixed now. The one with unused variable named 'size' was actually a bug, I need to use it.

Thanks!
Tomb Painter, Re:creation dev | eliasdaler.github.io | @EliasDaler | Tomb Painter dev log

FRex

  • Hero Member
  • *****
  • Posts: 1831
    • View Profile
    • My GitHub page
    • Email
Re: [Release][GUI] SFML + ImGui lib
« Reply #9 on: August 22, 2016, 11:42:28 pm »
I'm using this for something and I'd like to have icons on buttons. Is there a way to do that and still have three shades of button (idle, hovered, being pressed - I want entire sprite to change tint a little like normal buttons do) or not?

Also, is there some more powerful button function that'd let me catch right click or double click separately (I assume double click is possible in my code but I ask about a built in method)? I have a need to do one thing when button is pressed and another when it's double/right clicked.

And I have this code (inside a window begin+end pair of course) and it works only for the first right button, is that something with ids, using same texture, etc? What do I do?

sf::Sprite spr(m_iconstex);
    for(int i = 0; i < 5; ++i)
    {
        spr.setTextureRect(sf::IntRect(0, i * 32, 32, 32));
        if(imgui::ImageButton(spr, 1))
            std::printf("bum right\n");

        imgui::SameLine();
        spr.setTextureRect(sf::IntRect(32, i * 32, 32, 32));
        if(imgui::ImageButton(spr, 1))
            std::printf("bum left\n");
    }

I now changed it to
 sf::Sprite spr(m_iconstex);
    for(int i = 0; i < 5; ++i)
    {
        spr.setTextureRect(sf::IntRect(0, i * 32, 32, 32));
        imgui::PushID(2 * i + 0);
        if(imgui::ImageButton(spr, 1))
            std::printf("bum right\n");

        imgui::PopID();
        imgui::SameLine();
        spr.setTextureRect(sf::IntRect(32, i * 32, 32, 32));
        imgui::PushID(2 * i + 1);
        if(imgui::ImageButton(spr, 1))
            std::printf("bum left\n");

        imgui::PopID();
    }
and it works. I skimmed through the primer on ids in the faq and read your image button source and then image button function that it calls and it uses texture as id so that's why this happened.
« Last Edit: August 23, 2016, 12:07:56 am by FRex »
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

Elias Daler

  • Hero Member
  • *****
  • Posts: 570
    • View Profile
    • Blog
    • Email
Re: [Release][GUI] SFML + ImGui lib
« Reply #10 on: August 24, 2016, 09:37:36 am »
The easiest way to do icons I've seen (even Omar recommended this for now) is to embed icons in your font and then use images as symbols. :D
As for other questions - I have no experience with that, sorry. :)
Tomb Painter, Re:creation dev | eliasdaler.github.io | @EliasDaler | Tomb Painter dev log

FRex

  • Hero Member
  • *****
  • Posts: 1831
    • View Profile
    • My GitHub page
    • Email
Re: [Release][GUI] SFML + ImGui lib
« Reply #11 on: August 24, 2016, 06:03:25 pm »
This is really bad, my icons are colorful, and I don't want to fiddle with a font if there is a shortcut to do picture on a button. I'll make them a little transparent and make background part 100% transparent or something but it's still really silly to not have such a feature when there are things like trees, sliders and windows and done so so well.
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

Elias Daler

  • Hero Member
  • *****
  • Posts: 570
    • View Profile
    • Blog
    • Email
Re: [Release][GUI] SFML + ImGui lib
« Reply #12 on: August 25, 2016, 12:11:03 am »
This is really bad, my icons are colorful, and I don't want to fiddle with a font if there is a shortcut to do picture on a button. I'll make them a little transparent and make background part 100% transparent or something but it's still really silly to not have such a feature when there are things like trees, sliders and windows and done so so well.
Oh, that makes situation a bit harder. I suggest you to just check out how ImGui::Button is implemented and try to implement the same stuff yourself by example. I don't think that inserting images and other stuff in regular buttons is supported at the moment.
Tomb Painter, Re:creation dev | eliasdaler.github.io | @EliasDaler | Tomb Painter dev log

Elias Daler

  • Hero Member
  • *****
  • Posts: 570
    • View Profile
    • Blog
    • Email
Re: [Release][GUI] SFML + ImGui lib
« Reply #13 on: November 02, 2016, 08:27:37 pm »
Okay, I've managed to finally remove push/pop/resetGLStates!
This took a lot of time to came up with, but looks like everything works fine! It would be nice to see people confirm this, so please, use the latest version and try it yourself. :)
This give 2-3x rendering speed improvements which is really awesome.

And btw, I want to improve interface a bit, by maing users to pass window/renderTarget into free functions like Update and Render, instead of ImGui-SFML having raw internal pointers to them.
Feel free to comment on this idea here here.
But from the responses I have already received, no one is against it, so I'm planning to start working on it soon.
Tomb Painter, Re:creation dev | eliasdaler.github.io | @EliasDaler | Tomb Painter dev log

Elias Daler

  • Hero Member
  • *****
  • Posts: 570
    • View Profile
    • Blog
    • Email
Re: [Release][GUI] SFML + ImGui lib
« Reply #14 on: June 02, 2017, 01:09:45 am »
One important change happened. Now you should call ImGui::SFML::Render(target), so that resetGLStates is called. It seems like it's necessary, because SFML changed something about the state which breaks stuff in some conditions. Maybe I'll be able to find out what exactly causes that.


I've finally found out how load custom fonts. I'll copy info from README:

Default font is loaded if you don't pass false in ImGui::SFML::Init. Call ImGui::SFML::Init(window, false); if you don't want default font to be loaded.

Load your fonts like this:
IO.Fonts->Clear(); // clear fonts if you loaded some before (even if only default one was loaded)
// IO.Fonts->AddFontDefault(); // this will load default font as well
IO.Fonts->AddFontFromFileTTF("font1.ttf", 8.f);
IO.Fonts->AddFontFromFileTTF("font2.ttf", 12.f);

ImGui::SFML::UpdateFontTexture(); // important call: updates font texture
And use them like this:
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[0]);
ImGui::Button("Look at this pretty button");
ImGui::PopFont();

ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted("IT WORKS!");
ImGui::PopFont();
The first loaded font is treated as the default one and doesn't need to be pushed with ImGui::PushFont.
Tomb Painter, Re:creation dev | eliasdaler.github.io | @EliasDaler | Tomb Painter dev log

 

anything