TGUI on raspberry pi

Started by Austriker, 24 August 2015, 15:39:23

Austriker

Hi,

Does TGUI supports raspberry ?
I managed to build it but when i launch my app it stops with this error :


Failed to create window
X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  3 (X_GetWindowAttributes)
  Resource id in failed request:  0x140000d
  Serial number of failed request:  65
  Current serial number in output stream:  66


Sincerely

texus

I did have TGUI working on a raspberry pi some time ago, so it should be possible.

But doesn't that error come when trying to create the sfml window?

I'm not sure about the current state but when I tried it I needed an adapted sfml version (which someone put on the sfml forum) in order to get sfml to work. And it only worked for fullscreen windows.

Austriker

I had a working version of SFML before I added TGUI. Looking at git history to see what I changed.

texus

QuoteI had a working version of SFML before I added TGUI.
Then you should try to figure out where it goes wrong. Start with an sfml app, test it, link to tgui, test it, include tgui, test it, create a gui object, test it, ...

texus

I just realized something, you are using tgui 0.6 right?
I wonder how you even managed to build it on the raspberry pi, did you install mesa opengl drivers to use software rendering?

You need tgui 0.7-dev for which you have to check the TGUI_OPENGL_ES option. You might also have to point cmake to the correct libraries yourself (which were somewhere in the /opt folder if I'm correct).

Austriker

Yes i am using the the v06.

But I didn't need to tweak anything to build it. Just had to build SFML from source and then i followed the TGUI linux tutorial.

I narrowed my problem down.
I started by doing the SFML Linux tutorial :
https://www.sfml-dev.org/tutorials/2.3/start-linux.php
It works perfectly

I changed the main of my project with the example code. And it still get the error !

I don't understand why it doesn't work. It almost the since the only difference is I use CMake to build the example.

cmake_minimum_required(VERSION 2.6)

project(Brain C CXX)

# Fichier de sortie
set(EXECUTABLE_OUTPUT_PATH build/${CMAKE_BUILD_TYPE})
set(LIBRARY_OUTPUT_PATH lib/${CMAKE_BUILD_TYPE})

# Compiling in C++11. Settings compiler flags.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g")

# Detect Libs
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/Modules" ${CMAKE_MODULE_PATH})

find_package(SFML 2 REQUIRED system window graphics)
if(NOT SFML_FOUND)
    message(FATAL_ERROR "Could not find SFML")
endif()

add_subdirectory(Brain)


and the subdirectory CMake

set(SOURCES
    main.cpp
)

add_executable(brain ${SOURCES})
target_link_libraries(brain
    ${SFML_LIBRARIES}
)


That's really weird.

texus

When building sfml did you check SFML_OPENGL_ES? The only way that TGUI 0.6 could work on the raspberry pi is when you are using normal opengl and not opengl es. But desktop opengl is not hardware accelerated on raspberry pi, so isn't sfml super slow (like only a few frames per second?). TGUI 0.7-dev has also been given the TGUI_OPENGL_ES option to build for opengl es which is hardware accelerated.

QuoteIt works perfectly
I changed the main of my project with the example code. And it still get the error !
What example code are you talking about exactly? You should try to change the working version line by line until it fails, only then will you really know what is going wrong.

I have 2 raspberries lying around here but neither has an OS installed on them currently so I can't test it myself yet.

Austriker

I found the origin of the problem.
It was the SFML CMake module.

Here is the example code :
Code (cpp) Select
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

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

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

Austriker

So with a little bit of detail :

I used the FindSFML module to detect SFML (I took the module from the TGUI repo). It was the source of the bug. I solved the problem by doing the library linking directly :


target_link_libraries(brain
sfml-system
sfml-window
sfml-graphics)


But you need to have SFML installed system wide.

But know I am having an issue linking TGUI :

/usr/local/lib/libtgui.so: undefined reference to `sf::String::substring(unsigned int, unsigned int) const'
/usr/local/lib/libtgui.so: undefined reference to `sf::Image::~Image()'
collect2: error: ld returned 1 exit status


So I am trying to switch on TGUI v0.7-dev but I am having an error building it on my mac. :


$ make
[  2%] Building CXX object src/TGUI/CMakeFiles/tgui.dir/Widget.cpp.o
/libs/tgui/src/TGUI/Widget.cpp:451:16: error: chosen constructor is
      explicit in copy-initialization
        return {};
               ^~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/map:838:14: note:
      constructor declared here
    explicit map(const key_compare& __comp = key_compare())
             ^
1 error generated.
make[2]: *** [src/TGUI/CMakeFiles/tgui.dir/Widget.cpp.o] Error 1
make[1]: *** [src/TGUI/CMakeFiles/tgui.dir/all] Error 2
make: *** [all] Error 2

texus

#9
QuoteI used the FindSFML module to detect SFML (I took the module from the TGUI repo). It was the source of the bug. I solved the problem by doing the library linking directly
I didn't though of this before, but the FindSFML.cmake in TGUI is the one that ships with SFML 2.3. I know that is could no longer find SFML 2.1 (https://github.com/SFML/SFML/issues/950) but maybe it also affects SFML 2.2.
Edit: Sorry, you aren't using SFML 2.2 I guess, that was someone else on this forum apparently.

QuoteBut know I am having an issue linking TGUI
These errors would indicate that TGUI finds header files of SFML 2.2 or higher while the SFML library you link with is 2.0 or 2.1.

QuoteSo I am trying to switch on TGUI v0.7-dev but I am having an error building it on my mac
The mac version was tested on Yosemite, do you perhaps have an older mac version? I'll try and see if I can still compile it with Mountain Lion.

Austriker

I use SFML 2.3.1 builded from the git repo.

And I am running on Yosemite 10.10.4.

texus

The mac errors should be fixed now.

Quote/usr/local/lib/libtgui.so: undefined reference to `sf::String::substring(unsigned int, unsigned int) const'
/usr/local/lib/libtgui.so: undefined reference to `sf::Image::~Image()'
You should really double check that there isn't any older SFML version installed on your pc, it seems to find SFML 2.0 or 2.1 somewhere.