SFML community forums

Help => Graphics => Topic started by: binbinhfr on April 24, 2020, 07:40:30 pm

Title: Sprite multiple draw ?
Post by: binbinhfr on April 24, 2020, 07:40:30 pm
Hi,
Before going into programing, I'd like just a clarification (from a newbie). I tested textures, sprites, and repeated textures on sprites larger than the texture, but I wanted to be sure :
in a same "pre-render drawing session",  is it possible to use the same sprite multiple times to draw it on the screen ? I suppose no...

Said in another way : in order to draw repeatively a sprite on a non regular pattern, I must create several sprites from the same texture and draw them wherever I want, yes ?

Or another example : if I want to create a repeated background that could be zoomed out as far as I want, there is no "infinite repeated sprite" available : at a moment I have to repeat manually a texture by duplicating enough sprites to cover my screen ? (even if the sprite itself, within its limits, can be constructed from a repeated texture)
Title: Re: Sprite multiple draw ?
Post by: Laurent on April 24, 2020, 08:30:36 pm
Quote
in order to draw repeatively a sprite on a non regular pattern, I must create several sprites from the same texture and draw them wherever I want, yes ?
No. If you mean this:
sprite.setPosition(...);
target.draw(sprite);

sprite.setPosition(...);
target.draw(sprite);

...
... then it is perfectly possible.

Quote
if I want to create a repeated background that could be zoomed out as far as I want, there is no "infinite repeated sprite" available : at a moment I have to repeat manually a texture by duplicating enough sprites to cover my screen ?
Yes. Or maybe there's some trick that you can find with shaders?
Title: Re: Sprite multiple draw ?
Post by: binbinhfr on April 24, 2020, 08:45:11 pm
... then it is perfectly possible.

Oh, so I was right to ask this newbie question  ;D

I'll have a look at the shaders.

Thanks for your help and for SFML.
Title: Re: Sprite multiple draw ?
Post by: Hapax on April 25, 2020, 12:41:35 am
Hi.

if I want to create a repeated background that could be zoomed out as far as I want, there is no "infinite repeated sprite" available : at a moment I have to repeat manually a texture by duplicating enough sprites to cover my screen ? (even if the sprite itself, within its limits, can be constructed from a repeated texture)

You can create an infinitely repeated sprite by using a repeated texture and some offset tricks:
https://en.sfml-dev.org/forums/index.php?topic=14382.msg101088#msg101088

(click to show/hide)
Title: Re: Sprite multiple draw ?
Post by: binbinhfr on April 25, 2020, 10:05:32 am
thx Hapax.

Very useful.
But if I understood correctly, this large sprite will be limited by the max size of a single sprite/texture in my GPU. So If I want a larger background, I have to repeat this sprite manually, right ?
Title: Re: Sprite multiple draw ?
Post by: Hapax on April 26, 2020, 11:59:59 pm
A sprite doesn't have a limit on its size; its size is only really arbitrary values.
A texture does have a limit so as long as the repeated texture is stored fine in a sf::Texture, the sf::Sprite can be any size and repeat any number of times.
Title: Re: Sprite multiple draw ?
Post by: binbinhfr on April 27, 2020, 12:10:55 am
ok, thx for this clarification.
All is working fine, now that I understand all this stuff  8)