Codeblock and TGUI

Started by Garwin, 12 April 2022, 09:30:19

Garwin

I have tried to install TGUI libraries on Codeblock and so far without success. Firstly I tried development version 1.0, than final stable 0.9, both without success. I am doing probably something wrong. I will try to repeat what I did for version 0.9.

Release 20.03 rev 11983 (2020-03-12 18:24:30) gcc 8.1.0 Windows/unicode - 64 bit
SFML 2.5.1 (it works standalone)

1. downloaded precompiled TGUI 0.9.3 for MinGW 7.3.0 (SEH) - 64-bit
2. setting codeblock as described in tutorial - using static link of libraries (both TGUI and SFML)
3. paths to TGUI is set not relative

Enclosed is error report trying to build simple test program:
Issues is that it seems they are some strange paths

#include <TGUI/TGUI.hpp>


int main()
{
    sf::RenderWindow window{ {800, 600}, "TGUI example - SFML_GRAPHICS backend" };

    tgui::Gui gui{window};
    gui.mainLoop();
}


Any help appretiated.

texus

#1
Those errors look related to SFML. When you link SFML statically, you also have to link to its dependencies. The linking errors suggest that you aren't linking to the following SFML dependencies:
Quotefreetype
opengl32
winmm
gdi32

If you are linking to them, then maybe the order of linking is wrong. When you specify the libraries to link, do you have tgui at the end? Perhaps try putting tgui-s-d at the top of the list instead. When statically linking, libraries need to be ordered based on what they depend on (and for GCC the order is first TGUI, then SFML, then SFML's dependencies).


The MinGW compiler version usually has to match exactly between your project and what was used to build SFML and TGUI.
While the errors you showed don't look related to this, I don't think you can mix GCC 8.1 from CodeBlocks with the 7.3 that was used to compile TGUI without getting other issues (linker errors or crashes). If you use GCC 8.1 then you will most likely have to compile TGUI yourself. There is no precompiled TGUI library for GCC 8.1 because there is no stable SFML library for that compiler. So unless you are using an SFML snapshot instead of SFML 2.5.1, I would expect that you would have to compile SFML yourself as well (or switch your compiler to MinGW-w64 7.3.0 x86_64‑posix‑seh for which both SFML and TGUI provide libraries).
You can try keeping your current setup, maybe it will just work, but I won't be fully surprised if the program crashes on rendering once you resolved the linking errors.

Garwin

Thanks for the help.

As I am amateur, hobbiest , I have just tried to make it work. I use dynamic linking and it works.
Probably better solution than static linking.

Garwin

I just have tried https://tgui.eu/examples/0.10/popup-menu/ relaiting pop-up menu to start study of examples of library but trying to build this easy example does not work.

Looking at errors I am quite confused as trying to find "GuiBase" in any hpp file of TGUI is uncessfull.
I rename header to be in line with header file in the TGUI directory:
#include <TGUI/Backend/SFML-Graphics.hpp>
but GuiBase cannot be found anywhere.

C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|14|error: variable or field 'rightClickCallback' declared void|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|14|error: 'GuiBase' is not a member of 'tgui'|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|14|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|14|error: expected primary-expression before 'position'|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp||In function 'int main()':|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|31|error: 'GuiSFML' is not a member of 'tgui'|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|47|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|56|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|65|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|65|error: 'rightClickCallback' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|68|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|72|error: 'gui' was not declared in this scope|

texus

#4
It looks like the 0.10 examples are a bit outdated, the class was renamed to BackendGui.
I'll fix it ASAP in all the examples.

Garwin

Thanks, it helps.

I rename other changes but there is still one error I have not found the reason.

    tgui::GuiSFML gui(window);

I renamed it to:

    tgui::BackendGuiSFML gui(window);


as found in BackendGuiSFML.hpp but it does not help.

||=== Build: Debug in SFML_TGUI (compiler: GNU GCC Compiler) ===|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp||In function 'int main()':|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|31|error: no matching function for call to 'tgui::BackendGuiSFML::BackendGuiSFML(sf::RenderWindow&)'|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\_LIB\TGUI-0.10\include\TGUI\Backend\Window\SFML\BackendGuiSFML.hpp|48|note: candidate: tgui::BackendGuiSFML::BackendGuiSFML()|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\_LIB\TGUI-0.10\include\TGUI\Backend\Window\SFML\BackendGuiSFML.hpp|48|note:   candidate expects 0 arguments, 1 provided|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

texus

#6
tgui::GuiSFML was from TGUI 0.9, in TGUI 0.10 you can just use tgui::Gui.

Edit: Popup example seems to be the only one still using GuiSFML, I'll fix that line too. (The "GuiBase" has been updated on the website in the meantime, but the old version is still in some caches).

Garwin

It seems I will need to learn how to compile libraries. Finaly run, but except background there is nothing and right click shows some problem with OpenGL.

Text from console running program.

An internal OpenGL call failed in RenderTarget.cpp(302).
Expression:
   glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8)
Error description:
   GL_INVALID_OPERATION
   The specified operation is not allowed in the current state.

An internal OpenGL call failed in RenderTarget.cpp(711).
Expression:
   glDrawArrays(mode, static_cast<GLint>(firstVertex), static_cast<GLsizei>(vertexCount))
Error description:
   GL_INVALID_OPERATION
   The specified operation is not allowed in the current state.

texus

Since the SFML code is unlikely to be broken, and neither TGUI or your project is making OpenGL calls that could interfere with SFML, this does sound like some library incompatibility.
So you will indeed either need to learn how to compile SFML and TGUI, or alternatively learn how to change the compiler in CodeBlocks and downgrade the GCC version.

Garwin

Interesting thing is that I found out that I have:
g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Strange that opening Codeblock shows gcc 8.1.0. but it seems more likely that it is MinGW 8.1.0

texus

Depending on which CodeBlocks binary you install, it will use a bundled 8.1 from C:\Program Files\CodeBlocks\MinGW
You can change that in Settings > Compiler... from the menu bar and then writing a different path under the "Toolchain executables" tab.

If you set it to a directory containing MinGW 7.1 then everything should be compatible when you are using the SFML 2.5.1 downloaded from the SFML website.

Garwin

Finally it works. Thanks a lot for your time.

Somehow changing of linking of SFML libraries from static to dynamic was not saved.
Saved now and it works like a charm.

I will start to look what library is offering.


Tooltips seems very nice.  Just an idea moving position of tooltip up/left by difference between bounding box of last entry in relation to videomode.

texus

QuoteJust an idea moving position of tooltip up/left by difference between bounding box of last entry in relation to videomode.
I'm not sure what you mean. It should already be moving the tool tip if it would be outside the window. Isn't it behaving like that for you?

Garwin

Quote from: texus on 12 April 2022, 16:39:26
QuoteJust an idea moving position of tooltip up/left by difference between bounding box of last entry in relation to videomode.
I'm not sure what you mean. It should already be moving the tool tip if it would be outside the window. Isn't it behaving like that for you?

No, it is not. See screenshot.


texus

Can you show how you create the tool tip? Because that behavior would be a bug.

For testing I just tried the following on a button near the right side of the window and it did work as intended:
button->setToolTip(tgui::Label::create("Testing with some long string"));