SFML community forums

Help => Graphics => Topic started by: drporto on July 24, 2014, 12:38:31 am

Title: sf::Texture::setRepeated Problems
Post by: drporto 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.

(http://s30.postimg.org/o29csbrg1/Problem.png)

The picture used in the code.
http://s23.postimg.org/66z9whp8r/Desert.png
Title: Re: sf::Texture::setRepeated Problems
Post by: Hapax 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);
Title: Re: sf::Texture::setRepeated Problems
Post by: drporto on July 24, 2014, 02:24:42 am
But, i want the Desert.png picture filling the entire window.
Title: Re: sf::Texture::setRepeated Problems
Post by: Hapax 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.
Title: Re: sf::Texture::setRepeated Problems
Post by: Laurent 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...)
Title: Re: sf::Texture::setRepeated Problems
Post by: drporto on July 25, 2014, 12:37:34 am
Thanks to both of you.