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

Author Topic: Texture to a rectangle  (Read 16369 times)

0 Members and 1 Guest are viewing this topic.

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Texture to a rectangle
« on: October 07, 2012, 12:25:27 pm »
I have soprems setting to a  renctangle the texture:

     sf::Texture texture;
        if (!texture.loadFromFile("resources/backgroundimage.png"))
     return -1;

    // Jucatorul din stanga
    sf::RectangleShape leftPaddle;
    leftPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
    leftPaddle.setOutlineThickness(3);
    leftPaddle.setTexture(texture);
    leftPaddle.setOrigin(paddleSize / 2.f);

And give me these erors:
F:\CPlusPlus\Work\AnticPong\anticpong.cpp||In function 'int main()':|
F:\CPlusPlus\Work\AnticPong\anticpong.cpp|50|error: no matching function for call to 'sf::RectangleShape::setTexture(sf::Texture&)'|
F:\CPlusPlus\Plugins\SFML-2.0\include\SFML\Graphics\Shape.hpp|74|note: candidates are: void sf::Shape::setTexture(const sf::Texture*, bool)|
||=== Build finished: 1 errors, 0 warnings ===|
 
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Texture to a rectangle
« Reply #1 on: October 07, 2012, 12:48:15 pm »
The documentation shows you the correct function signature of sf::RectangleShape::setTexture(). Or even your error message, if you read it exactly.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: Texture to a rectangle
« Reply #2 on: October 07, 2012, 12:56:00 pm »
I can't understand how to put it correctly.  :-\
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Texture to a rectangle
« Reply #3 on: October 07, 2012, 01:14:54 pm »
Have you even tried? The documentation states that the function has this signature:
void setTexture(const Texture* texture, bool resetRect=false)

As you see, it takes a pointer. You however are passing a reference.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: Texture to a rectangle
« Reply #4 on: October 07, 2012, 01:16:44 pm »
Yes, I read it, but I have problems in understood it and putting it in my code.
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Texture to a rectangle
« Reply #5 on: October 07, 2012, 01:24:58 pm »
Then you should read a C++ book to learn more about pointers and references. These are very important topics, and although I can give you the solution for this specific problem, it is important that you understand the concept in order to apply it to other situations.

To get a pointer to the texture, you need to take its address with the address-of operator.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: Texture to a rectangle
« Reply #6 on: October 07, 2012, 08:02:49 pm »
Thanks. After reading some tutorials and start understand what mean pointer I succefully made it.
Here is the code, if need some modifications please tell:
sf::Texture texture;
        if (!texture.loadFromFile("resources/backgroundimage.png"))
     return -1;

     const sf::Texture *pTexture = &texture;

    // Jucatorul din stanga
    sf::RectangleShape leftPaddle;
    leftPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
    leftPaddle.setOutlineThickness(3);
    leftPaddle.setOutlineColor(sf::Color::Black);
    leftPaddle.setFillColor(sf::Color(100, 100, 200));
    leftPaddle.setTexture(pTexture);
    leftPaddle.setOrigin(paddleSize / 2.f);
« Last Edit: October 07, 2012, 08:08:29 pm by AlexxanderX »
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Texture to a rectangle
« Reply #7 on: October 07, 2012, 09:21:37 pm »
That's correct. You can also directly pass the address of the texture:
leftPaddle.setTexture(&texture);
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything