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

Author Topic: [SOLVED] MacOS Build and Windows Build has a Difference when Drawing Rectangle  (Read 2571 times)

0 Members and 1 Guest are viewing this topic.

simiF

  • Newbie
  • *
  • Posts: 3
    • View Profile
I am learning SFML by making Pong. My project is set up to build on Windows, MacOS, and Linux. I currently build on all 3 on every PR (thanks SFML template).

I also test on Windows and MacOS. I have made an odd observation, and I am not sure if it's an error on my side, or something funny going on with MacOS.

Below is a Windows screenshot, and both of the player and enemy paddles are perfectly aligned:


Below is a MacOS screenshot of the same build:


Some of the interesting observations:
  • Dividing Lane is perfectly down the middle
  • Both Player and Enemy paddles are shifted to the right

Below is the code snipped that determines the position of both paddles:
Player::Player(bool main_player, const float& width, const float& length)
        : _main_player{ main_player }, _width{ width }, _length{ length }, _size(_width, _length), _rect(_size)
{
    float x_pos_from_side = 200.f;

    float centered_y_pos = 0.5f * (_window_y_size - _length);
    float x_pos = _main_player ? x_pos_from_side : _window_x_size - x_pos_from_side - _width;

    _rect.setPosition(sf::Vector2f(x_pos, centered_y_pos));
}
« Last Edit: May 14, 2024, 01:20:46 am by simiF »

simiF

  • Newbie
  • *
  • Posts: 3
    • View Profile
I am not sure how the Insert Image works  :(. but the images are added as attachments

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
The first thing to consider are views. Which view are you using when drawing each item? Are you changing it between draw calls? If all your draw calls are together, this should be simple to check.

Then, consider where you are getting values such as "width" and "height". They likely should be the view's width and height, not the window's.

Also, consider that you must always know whether you are using view co-ordinates or pixel positions. e.g. getting the mouse position will be in pixel positions so does not necessarily match the location of objects until converted to co-ordinates. Note that if you are converting to co-ordinates, it must know which view's co-ordinates you wish to convert to. If you don't provide a view to "mapPixelToCoords", it will use the currently active view and, if you use multiple views, this may not be the one you actually draw it with.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
It might be a good idea to also try the program at the same window size on both. Currently the windows one is 1910x1102 and the mac is 3474x2214.
Also the mac screenshot appears to have the right side cut off, the rounded corners of the window aren't visible on the top or bottom right.


simiF

  • Newbie
  • *
  • Posts: 3
    • View Profile
Ah, kojack, you were right. When I instantiate the window in my source code, I just set it to 1920x1080. I need to do some digging to see what that actually means across different native resolution screens.

I also need to look into what views are  ::)

Thanks, y'all!  ;D

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Views are like cameras in other engines. They transform SFML coordinates into window coordinates.
By default it's a 1:1 pixel scale. So coordinates 100,100 in SFML would be pixel 100,100 in the window. But you can change the position, rotation and scale of the view, which lets you pan around and zoom on the scene without messing with what's rendered.
https://www.sfml-dev.org/tutorials/2.6/graphics-view.php

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
In addition - and something I was going to mention in my previous post but forgot - you should consider DPI awareness.

This can throw all sorts of things out if one version is DPI aware (even if automatic) and the other is not.

It's a very complicated issue, by the way, but I think Mac and Windows treat it differently by default. Possibly the way SFML treats it is different in those operating systems too but I'm not sure.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything