Game Development Reference
texture a bit more for it to work as we like. First of all, there is a function inside the Tex-
ture class— Texture::setRepeated() , which takes bool and marks the texture
as repeatable if it is called with true. However, this is not enough; there is one more step.
When we map textures to surfaces, we typically have to specify texture coordinates for
each vertex of the surface. In SFML, this is done automatically for the Shape class. If we
were using the OpenGL API to render a square with a texture on top of it, we would have
to specify the texture coordinates in a normalized format (0…1; 0…1). SFML does not
use the normalized approach; rather it uses pixel space coordinates ([0… width —1], [0…
height —1]). Here is a diagram to demonstrate how texture coordinates are mapped to a
surface, which is then rendered on a screen (the gray rectangle):
We saw what happens when we make the surface (or the shape) bigger—it just stretches
the texture. We need to change the texture coordinates to repeat the texture multiple times
on that surface. This is done by making the texture rectangle (all four texture coordinates
in one structure) larger than the texture itself.
With that in mind, let's see how our code setup will change: