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

Author Topic: Calling SetScale inside Render function  (Read 1873 times)

0 Members and 1 Guest are viewing this topic.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Calling SetScale inside Render function
« on: December 31, 2011, 04:46:35 pm »
Suppose I have a class derived from sf::Drawable.
Is there an easy way to change the scale inside the Render function?

This would be the code to create, scale and draw the object:
Code: [Select]
Object obj;
obj.Scale(2, 2);
window.Draw(obj);

And this is where the problem lies:
Code: [Select]
void Object::Render(sf::RenderTarget& target, sf::Renderer& renderer) const
{
    // I want to change the scale here!
    SetScale(4, 4);
}

I have found a way to do this by using a second class also derived from sf::Drawable and let that class take care of the drawing.
But I was wondering if there isn't an easier way to accomplish this.

I am using SFML2.
TGUI: C++ SFML GUI

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Calling SetScale inside Render function
« Reply #1 on: December 31, 2011, 05:12:15 pm »
Use a recent SFML 2, there's no problem with the new graphics API.
Laurent Gomila - SFML developer

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Calling SetScale inside Render function
« Reply #2 on: December 31, 2011, 07:01:55 pm »
I just downloaded the latest snapshot and I changed my code a little bit (the class is now also derived from sf::Transformable), but the problem is still the same.

Code: [Select]
void Draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    SetScale(4, 4);
}

When using these lines I still get this error: "passing ‘const Object’ as ‘this’ argument of ‘void sf::Transformable::SetScale(float, float)’ discards qualifiers"
I am using Code::Blocks with gcc v4.5.2

I do understand what the error means, I am asking if there is a workaround.
TGUI: C++ SFML GUI

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Calling SetScale inside Render function
« Reply #3 on: December 31, 2011, 08:08:00 pm »
It took some time to get used to the new Draw function but I solved my problem now by using the RenderStates.

Thanks for the quick response you gave me.
TGUI: C++ SFML GUI