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

Author Topic: hello. a question about setTextureRect  (Read 1680 times)

0 Members and 1 Guest are viewing this topic.

hdsiria

  • Newbie
  • *
  • Posts: 23
    • View Profile
hello. a question about setTextureRect
« on: March 27, 2024, 05:18:02 pm »
I use RectangleShape to hold the map. I use setTextureRect to adjust the area where the map appears in RectangleShape .
 But if I set the area to exceed the size of the original map, there's a blur of color around it. I wonder if I can remove these colors or make them black
 rectangleShape.setTextureRect(sf::IntRect(-100,-10,9000,9000));
 
The original size was 8000*8000.The picture of the problem is attached
« Last Edit: March 27, 2024, 05:22:33 pm by hdsiria »

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: hello. a question about setTextureRect
« Reply #1 on: March 28, 2024, 04:11:45 am »
OpenGL has the following texture wrapping modes: GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT, GL_REPEAT and GL_MIRROR_CLAMP_TO_EDGE.
Clamp to edge does what you are seeing, the edge pixels are extended infinitely around the texture.
Clamp to border lets you specify a single colour (like black) to show around the texture.
Repeat makes the texture tile (so it repeats).

SFML however only supports repeat and clamp to edge. It doesn't have clamp to border. (At least in SFML 3, which I'm using).

I don't know if there's an easy way to trick it besides editing texture.cpp to add the border mode in.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: hello. a question about setTextureRect
« Reply #2 on: March 28, 2024, 07:20:52 am »
There's no support for GL_CLAMP_TO_BORDER indeed.

I recommend to not stick to texture size and draw a border of your own.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/