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

Author Topic: sf::Texture::setRepeated Problems  (Read 2028 times)

0 Members and 1 Guest are viewing this topic.

drporto

  • Newbie
  • *
  • Posts: 3
    • View Profile
sf::Texture::setRepeated Problems
« on: July 24, 2014, 12:38:31 am »
#include <SFML/Graphics.hpp>
int main(){
        sf::RenderWindow window(sf::VideoMode(1280,720), "TesteGame");
        window.setPosition(sf::Vector2i(65,5));
        sf::Texture t; t.loadFromFile("Desert.png");
        t.setRepeated(true);
        sf::Sprite s(t,sf::IntRect(0,0,1280,720));
        while (window.isOpen()){
                sf::Event e;
                while (window.pollEvent(e)){
                        if (e.type == sf::Event::Closed) window.close();
                        window.draw(s);
                        window.display();
                }
        }
        return 0;
}
 

This is my code, it compiles without problems, but the the window shows some black areas that i don't know where they came from. Like this.



The picture used in the code.
http://s23.postimg.org/66z9whp8r/Desert.png

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Texture::setRepeated Problems
« Reply #1 on: July 24, 2014, 01:20:19 am »
Your IntRect is too large and the black areas are from the part of the texture past the actual image.
Try:
sf::Sprite s(t,sf::IntRect(0,0,640,480));
or just:
sf::Sprite s(t);
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

drporto

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: sf::Texture::setRepeated Problems
« Reply #2 on: July 24, 2014, 02:24:42 am »
But, i want the Desert.png picture filling the entire window.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Texture::setRepeated Problems
« Reply #3 on: July 24, 2014, 04:22:30 am »
My bad. You were right. I tested your code and it works fine for me.
Saying that, you should take the draw() and display() calls out of the pollEvent() testing loop.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Texture::setRepeated Problems
« Reply #4 on: July 24, 2014, 07:41:50 am »
Please read the documentation >:(

Quote from: sf::Texture::setRepeated
Warning: on very old graphics cards, white pixels may appear when the texture is repeated. With such cards, repeat mode can be used reliably only if the texture has power-of-two dimensions (such as 256x128).

(Ok, the pixels are not white...)
Laurent Gomila - SFML developer

drporto

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: sf::Texture::setRepeated Problems
« Reply #5 on: July 25, 2014, 12:37:34 am »
Thanks to both of you.