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

Author Topic: Scale sprites with repeating instead of stretching  (Read 3757 times)

0 Members and 1 Guest are viewing this topic.

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Scale sprites with repeating instead of stretching
« on: July 19, 2013, 09:30:16 am »
Hi. I'm new in SFML, but have experience in OpenGL.
Well... Is there a way to fill background with some sprite in SFML v1.6?

For example sprite size is 512x512, screen size is 1024x768.

If I resize it to screen size, the texture coordinates will still be the (0, 0) - (1, 1) and the sprite streches.
How can I resize sprite with changing texture coordinates to (0, 0) - (2, 1.5) to fill all the background without "for" statements etc.?

I've read about sf::RenderTexture and method setRepeated(bool), but it is in SFML v2.0

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Scale sprites with repeating instead of stretching
« Reply #1 on: July 19, 2013, 09:42:20 am »
This is not possible with SFML 1.6. But you should seriously consider switching to SFML 2.0.
Laurent Gomila - SFML developer

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Scale sprites with repeating instead of stretching
« Reply #2 on: July 19, 2013, 09:51:43 am »
Thanks a lot, Laurent! I'll do it right now.
And your project is awesome!  ;)

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Scale sprites with repeating instead of stretching
« Reply #3 on: July 19, 2013, 10:58:58 am »
Sorry, but how to use it?

I'm doing this:

BackgroundTexture.loadFromFile("data/img/gui/mainmenu/bg.jpg");
BackgroundTexture.setRepeated(true);
Background.setSize(sf::Vector2f(1024,768));
Background.setTexture(&BackgroundTexture);

but the image is still scaling instead of repeating

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Scale sprites with repeating instead of stretching
« Reply #4 on: July 19, 2013, 11:03:21 am »
Sorry, just found an answer... setTextureRect. Anyway thank you very much!!!