There are five things you need to change in your code to get tgui working.
The first thing to do is including it. TGUI will include “SFML/Graphics.hpp” for you.
The next thing to do is creating a window. The window that is provided in tgui is just a wrapper around sf::RenderWindow, so all of its functions are kept. This means that you can call the constructor in the same way. (See lower for an alternative to tgui::Window).
Since sfml no longer provides a default font, you will have to set your own font.
When you will have objects, they will need to receive events. Otherwise they wouldn’t know if your mouse is on top of them or not. Every time you receive an event, you will have to tell the window about this event. So in your event loop you must add the following line:
The last thing to do is drawing the object on the screen. For this you must call the drawGUI function of the window. All object will be drawn on the screen in the order that you created them. So if your objects overlap each other then the last created object will be drawn in front.
So the full code will look like this:
Alternative to tgui::Window
In some cases you might not want to use tgui::Window. This could be just out of personal preference or because you need to override sf::RenderWindow yourself.