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

Author Topic: Rotated SubRect  (Read 2664 times)

0 Members and 1 Guest are viewing this topic.

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Rotated SubRect
« on: May 16, 2009, 01:35:29 am »
I'm using a packed texture to hold my sprites, and some sprites are rotated.

Is there anyway to set the SubRect of the sprite so it reads in the rotated image correctly? I thought I could just reverse the top and bottom of the sub rect to make it work, but it seems to have no effect.

I know I can load the rotated image and then rotate the sprite, but then I'd have to keep adding 90 to any SetRotations I do later; it'd be a messy solution.

Thanks.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Rotated SubRect
« Reply #1 on: May 16, 2009, 09:11:28 am »
Why not rotating the picture whit photoshop/... ?
SFML / OS X developer

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Rotated SubRect
« Reply #2 on: May 16, 2009, 09:14:20 am »
I'm packing several images into one texture for better performance. Currently I'm not rotating them, but if I rotate some of them in this packed texture I can fit more in each texture.

dunce

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Rotated SubRect
« Reply #3 on: May 19, 2009, 09:30:17 am »
The resource manager that I created for my framework uses loading images from byte arrays. As a bonus I can decrypt encrypted images and place the bytes of the whole atlas or its parts in memory in any order I wish while loading them from the resource storage. Maybe this is a possible way for you to go? The drawback here is two-stage image processing (load to memory and convert-decrypt if necessary, and then get them on demand) instead of direct loading from a file.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Rotated SubRect
« Reply #4 on: May 20, 2009, 11:54:18 pm »
This is more like a hack, but:
You could make a class that inherits from sf::Sprite and do a fixup on angle or flip, based on the rotation you define for the image.

If you rewrite FlipX/Y and SetRotation you could add this functionality easily.

Not the best solution but it could work.

Something like:

HackSprite::SetImageRotation(float rot) { ImgRot=rot; }
HackSprite::SetRotation(float rot) { Sprite::SetRotation(rot-ImgRot); }


Regards
-Martín

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Rotated SubRect
« Reply #5 on: May 21, 2009, 02:53:27 am »
I'll probably just modify or subclass sf::Sprite. A rotated sub-rect is just a small change in the texture coordinates in the Render function. That's how FlipX and FlipY work.

It would be nice if SFML supported this. I know a lot of texture atlases support rotating sprites to save space.

Thanks.