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

Author Topic: SFML Bad Window on Raspberry PI with CMake  (Read 2184 times)

0 Members and 1 Guest are viewing this topic.

Austriker

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML Bad Window on Raspberry PI with CMake
« on: August 24, 2015, 06:04:11 pm »
Hi,

I am having an issue with SFML.
When I try to launch my app I have this error message :

Code: [Select]
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

So I tested the example in the tutorial :
http://www.sfml-dev.org/tutorials/2.3/start-linux.php

And it works perfectly ! But when i try to build the example using CMake I get the error message.

I removed everything else to narrow the location of the bug but I am stuck.

Here is the main CMake file :
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)
 

Here is the subdirectory CMakelist :
set(SOURCES
    main.cpp
)

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

The main.cpp :
#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;
}
 

I really don't understand the difference between the tutorial and my basic project.

Thanks for your help !
Sincereley

Verra

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: SFML Bad Window on Raspberry PI with CMake
« Reply #1 on: August 24, 2015, 11:49:52 pm »
I had the same problem on raspberry pi and I never was able to figure out how to fix it. I would love to learn if anybody has a solution for this.

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: SFML Bad Window on Raspberry PI with CMake
« Reply #2 on: August 25, 2015, 12:40:25 am »
Try putting the bitsPerPixels of the VideoMode on 16.
I just tried and I could run the pong example with sf::VideoMode::getDesktopMode() so I checked the bps on that and it returned 16. Creating a window with sf::VideoMode(800, 600, 16) seems to work fine.
TGUI: C++ SFML GUI

Austriker

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SFML Bad Window on Raspberry PI with CMake
« Reply #3 on: August 25, 2015, 11:10:27 am »
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 :

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})

set(SOURCES
    main.cpp
)

add_executable(sfml-app ${SOURCES})

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

 

But you need to have SFML installed system wide.

I am running SFML on RPI 2 with Raspbian
I builded SFML from source and installed it.

 

anything