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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - mxwxz

Pages: [1]
1
Window / [OSX] setPosition inconsistency with getDesktopMode
« on: September 03, 2022, 09:34:34 am »
getDesktopMode returns physical pixel size in OSX retina, however in recent Mac the default scale is 2X.
Supposing the physical pixel is 3024*1964 (14 inch mac), scaled pixel (using screenshot tool or similar tools to get the window size) is 1512*982.
The following code creates a 800*600 window(in screenshot tool it shows 800*600 covering about 1/4 of the screen, meaning that 800*600 is scaled pixel and 1600*1200 in physical pixel).
But when I try to center the window using data of getDesktopMode and setPosition, it is inconsistency.
size.x / 2 and size.y / 2 produce 1512*982, but window.setPosition set the position in scaled pixel.
This means that
window.setPosition(sf::Vector2i(size.x / 2 - 400, size.y / 2 - 300));
will put the window in the right bottom corner and
window.setPosition(sf::Vector2i(size.x / 4 - 400, size.y / 4 - 300));
will center the window.

So, can we provide the API to get the scale ratio or make getDesktopMode returns the scaled pixel size? Since  all the size and position of other APIs are based on scaled pixel.

#include <SFML/Window.hpp>

int main() {
    sf::Window window(sf::VideoMode(sf::Vector2u(800, 600)), "My window");
    auto size = sf::VideoMode::getDesktopMode().size;
    // window.setPosition(sf::Vector2i(size.x / 2 - 400, size.y / 2 - 300));
    window.setPosition(sf::Vector2i(size.x / 4 - 400, size.y / 4 - 300));

    // run the program as long as the window is open
    while (window.isOpen()) {
        // check all the window's events that were triggered since the last
        // iteration of the loop
        sf::Event event;
        while (window.pollEvent(event)) {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }
    }

    return 0;
}

2
General / How to build SFML as a third-part library with cmake?
« on: December 27, 2018, 05:12:00 pm »
Hi, I'm starting to try SFML, it works fine when I manually build(or use the SDK), and add it to the "Additional Library". But now I'd like to build a project with cmake and I want a "one click" solution to get it built.

Here is my folder:
root
--SFML(the src code from github)
--Myapp
----main.cpp
----main.h
----CMakeLists.txt
--CMakeLists.txt

In main.cpp and main.h is just a "Hello world" code of SFML, so we dont talk about it.
In "root/CMakeLists.txt":
cmake_minimum_required (VERSION 3.8)
project ("test")
add_subdirectory ("SFML")
add_subdirectory ("Myapp")

In "root/Myapp/CMakeLists.txt":
cmake_minimum_required (VERSION 3.8)

find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable (myapp "main.cpp" "main.h")
target_link_libraries(myapp sfml-graphics sfml-audio)

Just like the wiki, but I got an error in VS 2017:
Requested SFML configuration (Shared) was not found

I found that in "SFMLConfig.cmake" there is
set(targets_config_file "${CMAKE_CURRENT_LIST_DIR}/SFML${config_name}Targets.cmake")
And I cant find the "SFML${config_name}Targets.cmake" in the "CMAKE_CURRENT_LIST_DIR", so it break.

I also tried in ubuntu using
mkdir build
cd build
cmake ..
I got these:
  By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "SFML", but
  CMake did not find one.

  Could not find a package configuration file provided by "SFML" (requested
  version 2.5) with any of the following names:

    SFMLConfig.cmake
    sfml-config.cmake

  Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
  "SFML_DIR" to a directory containing one of the above files.  If "SFML"
  provides a separate development package or SDK, be sure it has been
  installed.

Now I dont want to install the SDK manually everytime, how can i use just "cmake .." and it will build SFML and then build myapp linked with it? Any suggestions?

Pages: [1]