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

Author Topic: ability to use rotated images with setTextureRect  (Read 15388 times)

0 Members and 2 Guests are viewing this topic.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: ability to use rotated images with setTextureRect
« Reply #15 on: August 07, 2014, 12:53:36 am »
And what about shapes? If we go this way, there's no reason to limit shape texturing to an AABB rectangle, we should be able to set each point's texture coordinates as well.
Isn't this a good thing? We don't want to limit peoples' creativity just because we aren't as creative as them ;). This would also solve the "cookie cutter" problem where a texture might not be properly spanned across a polygon if it isn't a quad, since that is currently the assumption of shape texturing.

Now for the implementation... sf::Sprite's local geometry is directly deduced from the texture rectangle. What if now we can set any shape composed of 4 points? The sprite will no longer be a quad.
This is also a good thing to have. Imagine how happy all of the people making isometric tile games would be if they could have sprites that are rhombuses instead of quads. :D Tighter texture atlas packing, less overdraw (more GPU performance) and less headaches among many other things.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

kimci86

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: ability to use rotated images with setTextureRect
« Reply #16 on: August 07, 2014, 12:31:32 pm »
Hi,
In my humble opinion, this feature already exists with sf::VextexArray.
What do you think ? Are you against using it ?

thomas9459

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: ability to use rotated images with setTextureRect
« Reply #17 on: August 07, 2014, 06:23:56 pm »
In my humble opinion, this feature already exists with sf::VextexArray.
What do you think ? Are you against using it ?
There are many cases where an sf::Sprite would be preferred because of the other functions provided by the class, especially the rotation/position/origin ones.

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: ability to use rotated images with setTextureRect
« Reply #18 on: August 08, 2014, 11:28:35 pm »
Why is this needed so much when in the end the output from rotating the texture coordinates would look the same as rotating the sprite? Some adjustment to client code would always be needed when using such a weird rotating texture packer.

superjoe

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: ability to use rotated images with setTextureRect
« Reply #19 on: August 09, 2014, 08:52:04 pm »
Why is this needed so much when in the end the output from rotating the texture coordinates would look the same as rotating the sprite? Some adjustment to client code would always be needed when using such a weird rotating texture packer.

It's not weird. Many texture packers have this feature.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: ability to use rotated images with setTextureRect
« Reply #20 on: August 09, 2014, 09:05:31 pm »
I think the question is whether SFML should explicitly support rotating texture rectangles because of these packers, whether it should leave the image rotating to the user to do in their code (e.g. somewhere in a resource manager) or whether SFML should support generic texture source specifications like I proposed. I still feel like if we were to implement something that made texturing sprites more flexible, we should go all the way, for the reasons I already mentioned. Locking rotations to multiples of 90 degrees sounds too much like catering to a specific subset of packers. After all, there might be obscure packers that rotate sprites in angles that are not multiples of 90 degrees... what do we do then?
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: ability to use rotated images with setTextureRect
« Reply #21 on: August 09, 2014, 10:47:48 pm »
The good thing with rotated rectangles is that modifications to the public API are minimal, while providing a feature which can be useful in multiple areas.

The full flexibility of providing the 4 texture coordinates directly solves more obscur problems, makes the public API and implementation much more complicated, for something that can already be done easily with vertex arrays. Don't forget that sprites are just a higher-level abstraction, the class itself exists only to makes things simpler, it doesn't do anything that can't already be done with vertex arrays. Making it more complicated would make it quite useless.
« Last Edit: August 09, 2014, 10:49:24 pm by Laurent »
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: ability to use rotated images with setTextureRect
« Reply #22 on: August 09, 2014, 11:34:08 pm »
The most "annoying" thing about using an sf::VertexArray instead of a regular sf::Sprite is the fact that sf::VertexArray isn't derived from sf::Transformable like sf::Sprite is. Even if you mean to use it as a rigid body, which implies that all rigid body transformations are applicable to it as well, SFML doesn't allow you to do that. I can't tell how annoying this is to those who actually care because I don't make extensive use of it myself, but I can imagine that some people might be put off by the fact that they have to sacrifice the transformable interface just because their texture data doesn't fit perfectly to sf::Sprite's assumptions.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: ability to use rotated images with setTextureRect
« Reply #23 on: August 10, 2014, 09:42:25 am »
class MyFlexibleSprite : public sf::Drawable, public sf::Transformable
{
    ... vertex array ... texture coordinates ...
};
Laurent Gomila - SFML developer

superjoe

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: ability to use rotated images with setTextureRect
« Reply #24 on: August 10, 2014, 11:29:37 am »
Locking rotations to multiples of 90 degrees sounds too much like catering to a specific subset of packers. After all, there might be obscure packers that rotate sprites in angles that are not multiples of 90 degrees... what do we do then?

I don't think this makes sense. Rotating 90 degrees you're guaranteed to be able to fit all the pixels in there perfectly and pretend that you never rotated the texture. Any other value and you give up 1:1 pixel mapping.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: ability to use rotated images with setTextureRect
« Reply #25 on: August 10, 2014, 11:09:20 pm »
I guess if sf::Sprite were to be limited to usage with axis-aligned sprite sheets your code would be fine with me as well :).
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Juhani

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: ability to use rotated images with setTextureRect
« Reply #26 on: August 14, 2014, 03:09:36 pm »
probably with having, let say, top/left being the top right corner and a negative width and let SFML do the work (for a 90 CW rotation) but probably too much hassle.

IMHO this is a good idea.

Edit: ;D Just realized that this would cause mirroring but not rotating. ::)

How about taking as arguments the top left and bottom right corner? If bottom right is more left than top left the texture is rotated 90 degrees, if higher it is -90 degrees, and if bottom right is both above and left of top left 180 degrees.
« Last Edit: August 14, 2014, 04:24:24 pm by Juhani »