Main Menu

Recent posts

#51
Installation help / Re: CMake cannot find SFML
Last post by texus - 26 March 2024, 22:25:32
I'm a bit confused about how the project is being build.

The log contained the following line:
Quote[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\mingw64\bin\g++.exe -SC:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/TGUI -Bc:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build -G "MinGW Makefiles"

The source directory is being set to the "TGUI" subdirectory, but the build directory is the one from your project? That would mean that it is trying to build TGUI and your own cmake script isn't even being executed.

If that command where to contain "-DSFML_DIR=c:/SFML/lib/cmake/SFML" then it would probably build TGUI successfully. However that would only build TGUI and not your project, so you probably want to change the source directory instead.
#52
Installation help / Re: CMake cannot find SFML
Last post by luka - 26 March 2024, 21:39:10
Quote from: texus on 26 March 2024, 08:40:15The set(SFML_DIR "c:/SFML/lib/cmake/SFML") should be sufficient when placed before the find_package or add_subdirectory line.

TGUI tries to find SFML with "find_package(SFML 2 CONFIG COMPONENTS graphics REQUIRED)".

- Which files does c:/SFML/lib/cmake/SFML contain?
- Which SFML version is located in c:/SFML?
- Did you build SFML yourself or download a precompiled version from their website?
- Which MinGW version are you using?

Thank you for the prompt response and assistance.

1. alle the cmake files
   - SFMLConfig.cmake
   - SFMLConfigDependencies.cmake
   - SFMLConfigVersion.cmake
   - SFMLSharedTargets.cmake
   - SFMLSharedTargets-debug.cmake
   - SFMLSharedTargets-release.cmake
   - SFMLStaticTargets.cmake
   - SFMLStaticTargets-debug.cmake
   - SFMLStaticTargets-release.cmake
2. SFML 2.6.0 is installed
3. I downloaded a precompiled version from their website.
4. I am using GCC 13.1.0 MinGW 64-bit
#53
Installation help / Re: CMake cannot find SFML
Last post by texus - 26 March 2024, 08:40:15
The set(SFML_DIR "c:/SFML/lib/cmake/SFML") should be sufficient when placed before the find_package or add_subdirectory line.

TGUI tries to find SFML with "find_package(SFML 2 CONFIG COMPONENTS graphics REQUIRED)".

- Which files does c:/SFML/lib/cmake/SFML contain?
- Which SFML version is located in c:/SFML?
- Did you build SFML yourself or download a precompiled version from their website?
- Which MinGW version are you using?
#54
Installation help / CMake cannot find SFML
Last post by luka - 26 March 2024, 06:27:21
Hello, I'm currently trying to integrate TGUI into my SFML project. I'm using CMake and VS Code, but I've encountered a problem where TGUI can't find SFML. I have the error message ready here, which mentions setting the SFML_DIR, but I'm not sure exactly where to do that. Any help would be greatly appreciated.

[main] Building folder: AutoBackupScript2
[main] Configuring project: AutoBackupScript2
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\mingw64\bin\g++.exe -SC:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/TGUI -Bc:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake]
[cmake] Searching for SFML 2...
[cmake]
[cmake] -- Could NOT find SFML (missing: SFML_DIR)
[cmake]
[cmake] Searching for SFML 3...
[cmake]
[cmake] -- Could NOT find SFML (missing: SFML_DIR)
[cmake] CMake Error at cmake/Dependencies.cmake:80 (message):
[cmake]  CMake couldn't find SFML.
[cmake]
[cmake]  Set SFML_DIR to the directory containing SFMLConfig.cmake (usually
[cmake]  something like SFML_ROOT/lib/cmake/SFML)
[cmake]
[cmake] Call Stack (most recent call first):
[cmake]  cmake/Dependencies.cmake:93 (tgui_find_dependency_sfml)
[cmake]  src/Backend/CMakeLists.txt:153 (tgui_add_dependency_sfml)
[cmake]  src/CMakeLists.txt:305 (include)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\mingw64\bin\g++.exe -SC:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/TGUI -Bc:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build -G "MinGW Makefiles" exited with code: 1


I have integrated TGUI into my project as follows:

Project/
├── CMakeLists.txt (Main project)
├── src/
│  └── main.cpp
└── TGUI/

and SFML is not directly in the project folder, but it usually finds it after setting the SFML_DIR.

My CMakeLists.txt from the main project:

cmake_minimum_required(VERSION 3.17)
project(AutoBackupScript VERSION 0.1.0 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)

# Füge die Quelldateien hinzu
set(SOURCES
    src/main.cpp

)

include_directories(headers)

# Füge das ausführbare Ziel hinzu und verlinke ImGui
add_executable(AutoBackupScript ${SOURCES})

#target_link_libraries(AutoBackupScript PRIVATE TGUI)

# Suche und verlinke SFML
set(SFML_DIR "c:/SFML/lib/cmake/SFML")  # Pfad zum SFML CMake-Modul
find_package(SFML COMPONENTS system window graphics network audio REQUIRED)
if (SFML_FOUND)
    target_link_libraries(AutoBackupScript PRIVATE sfml-system sfml-window sfml-graphics sfml-network sfml-audio)
endif()

#target_link_libraries(AutoBackupScript PRIVATE TGUI)

set(SFML_DIR "c:/SFML/lib/cmake/SFML")
#include_directories(${CMAKE_SOURCE_DIR}/TGUI)
#include_directories(${CMAKE_SOURCE_DIR})
#add_subdirectory(TGUI)

#find_package(TGUI 1 REQUIRED)
#target_link_libraries(AutoBackupScript PRIVATE TGUI::TGUI)

# Kopiere DLLs in das Build-Verzeichnis
if(WIN32)
    file(GLOB BINARY_DEP_DLLS "c:/SFML/bin/*.dll")
    file(COPY ${BINARY_DEP_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
    file(GLOB MINGW_DEP_DLLS "C:/mingw64/bin/*.dll")
    file(COPY ${MINGW_DEP_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
endif()

#55
Help requests / Re: Segmentation fault when a ...
Last post by GetterSetter - 25 March 2024, 18:58:11
Quote from: texus on 25 March 2024, 18:24:54all TGUI widgets need to be destroyed before the Gui object is destroyed.
Oh, that's it. I swapped two lines in the code (see below) and it settled the matter, thank you!
//How it was:
Scene scene;
tgui::Gui gui;

//How it is now:
tgui::Gui gui;
Scene scene;
#56
Help requests / Re: Segmentation fault when a ...
Last post by texus - 25 March 2024, 18:24:54
Is the Scene class perhaps being destructed after the main() function has finished executing?
SFML and TGUI objects need to be destroyed before the end of the main function and shouldn't be part of a static global object.

Edit: Also, all TGUI widgets need to be destroyed before the Gui object is destroyed.
#57
Help requests / Segmentation fault when a list...
Last post by GetterSetter - 25 March 2024, 16:17:13
Hello, I suppose that I'm missing something but can't figure out what. I have the next class (some realization nuances are omitted):
class Scene
{
public:
    std::list<tgui::Group::Ptr> groups;
private:
    using iterator = std::list<tgui::Group::Ptr>::iterator;
    iterator current_group;
    void change_scene(iterator &from, iterator &to);

};

In the main function I have something like that:

scene.groups.emplace_back(tgui::Group::create());

//Some widgets initialization and adding them to the group

gui.add(scene.groups.begin());
It works pretty nice until I close the program (and ~Scene() is called) and get Seg fault message. I've attached the picture from the debugger.
#58
Help requests / Re: Problems with dynamic text...
Last post by GetterSetter - 23 March 2024, 17:36:44
Thank you, now it works!
#59
Help requests / Re: Problems with dynamic text...
Last post by texus - 23 March 2024, 17:22:00
Actually I think this issue was fixed already recently.
The "Texture::operator==" contained a bug where it considered two images with the same filename but a different part rect to be identical to each other.
So calling setTexture would do nothing because the code thought that you were just setting the same texture again.

I just uploaded TGUI 1.2.0 to the website (if it still shows 1.1 on the download page then refresh the page with ctrl+F5). If you use that version then this and the earlier reported bug should be fixed.
#60
Help requests / Problems with dynamic texture ...
Last post by GetterSetter - 23 March 2024, 17:14:06
Hello!
What I'm supposed to do: when button was clicked its texture should be changed.
I have textures in one single .png file and my code looks like:
bool linked = 1;
    tgui::Texture link_t[2];
    for (short i = 0; i < 2; ++i)
        link_t[i].load("lu.png", {unsigned(50 * i), 0, 50, 50});

    auto link_b = gui.get<tgui::Button>("link_b");

    auto lb_func = [&link_b, &linked, &link_t]()
    {
        linked = !linked;
        link_b->getRenderer()->setTexture(link_t[linked]);
    };

    gui.get<tgui::Button>("link_b")->onClick(lb_func);
It's expected the texture to be changed every time I click the button, but actually it changes only once.

So I've written the following code to "separate" textures:
bool linked = 1;
    tgui::Texture linked_t, unlinked_t;

    linked_t.load("linked.png");
    unlinked_t.load("unlinked.png");

    auto link_b = gui.get<tgui::Button>("link_b");

    if (linked)
        link_b->getRenderer()->setTexture(linked_t);
    else
        link_b->getRenderer()->setTexture(unlinked_t);

    auto lb_func = [&link_b, &linked, &linked_t, &unlinked_t]()
    {
        linked = !linked;
        if (linked)
            link_b->getRenderer()->setTexture(linked_t);
        else
            link_b->getRenderer()->setTexture(unlinked_t);
    };

    gui.get<tgui::Button>("link_b")->onClick(lb_func);
And it works pretty good! I think the problem that my first piece of code uses the textures with the same ID. Perhaps, that's the reason why setTexture() doesn't change the texture.