SFML community forums

Help => General => Topic started by: HeinzK on January 20, 2025, 03:17:52 pm

Title: 2.6.2 to 3.0.0 sf::Vertex AchseV[]
Post by: HeinzK on January 20, 2025, 03:17:52 pm
 After I edited some 100 places with sf::Vertex ...
 //> 2.6.2
 k_Vertexs.push_back
           (
             sf::Vertex
                 (
                   sf::Vector2f(fX1, fY1),
                   CoZ
                 )
           );

 //> 3.0.0
 k_Vertexs.push_back
           (
             {
               sf::Vector2f(fX1, fY1),
               CoZ
             }
           );

... I hope this is correct? (Unfortunately, I can only test it again once everything has been 'translated'!),

I have come across a problem!

//> 2.6.2
sf::Vertex AchseV[] =
{
  sf::Vertex(sf::Vector2f(0.0, 0.0)),
  sf::Vertex(sf::Vector2f(0.0, 0.0))
};

//> 3.0.0
sf::Vertex AchseV[] =
{
  sf::Vector2f({0.0, 0.0}),
  sf::Vector2f({0.0, 0.0})
};
...
AchseV[0].position.x = (float)k_pMaus->GetlMausX();
pWindow->draw(AchseV, 2, sf::Lines);
...

How will this be solved in 3.0.0?

Code:
 
(click to show/hide)
Title: Re: 2.6.2 to 3.0.0 sf::Vertex AchseV[]
Post by: eXpl0it3r on January 21, 2025, 10:16:04 am
You can use aggregate initialization (https://en.cppreference.com/w/cpp/language/aggregate_initialization) like this:

sf::Vertex AchseV[] =
{
  { sf::Vector2f(0.f, 0.f) },
  { sf::Vector2f(0.f, 0.f) }
};
Title: Re: 2.6.2 to 3.0.0 sf::Vertex AchseV[]
Post by: HeinzK on January 21, 2025, 10:20:00 am
Thank you very much, but wy not:
sf::Vertex AchseV[] =
{
  { sf::Vector2f({0.0, 0.0}) },
  { sf::Vector2f({0.0, 0.0}) }
};
Title: Re: 2.6.2 to 3.0.0 sf::Vertex AchseV[]
Post by: eXpl0it3r on January 21, 2025, 10:37:46 am
The inner {0.0, 0.0} will create a sf::Vector2<double> instance, which you then pass to the sf::Vector2f constructor. The compiler will likely optimize this away, but it's completely redundant.

So it's better to directly call the sf::Vector2f constructor with float values.
Title: Re: 2.6.2 to 3.0.0 sf::Vertex AchseV[]
Post by: HeinzK on January 21, 2025, 10:50:08 am
Understood.
My next problem.
2.6.2
sf::IntRect View = pWindow->getViewport(pWindow->getView());
AxisV[0].position.y = (float)(View.top + View.height);
3.0.0 there is now sf::View ... so:
sf::IntRect Vw = pWindow->getViewport(pWindow->getView());
AxisV[0].position.y = (float)(Vw.top + Vw.height);
.. but this does not work (.top und .height not available)
.. please help.
Title: Re: 2.6.2 to 3.0.0 sf::Vertex AchseV[]
Post by: eXpl0it3r on January 21, 2025, 11:13:52 am
You can check the migration guide (https://www.sfml-dev.org/tutorials/3.0/getting-started/migrate/#sfrectt) for all the changes needed.

sf::Rect has changed and now offers position and size as properties, size contains the x and y properties
Title: Re: 2.6.2 to 3.0.0 sf::Vertex AchseV[]
Post by: HeinzK on January 21, 2025, 02:02:58 pm
I work with the migration guide. I anderstood:
v2: sf::IntRect rect(250, 400, 50, 100);
v3: sf::IntRect rect({250, 400}, {50, 100});
.. but I don't find the 'width' and 'height' properties.
(https://www.zwianer.de/$Download$/sfml1.png)
Title: Re: 2.6.2 to 3.0.0 sf::Vertex AchseV[]
Post by: eXpl0it3r on January 21, 2025, 02:38:13 pm
Sorry, I derped size and position are vector2 instances, so you get x and y

width = size.x
height = size.y