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

Author Topic: Scale/Resize sf::Texture (not sf::Sprite)  (Read 15129 times)

0 Members and 1 Guest are viewing this topic.

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Scale/Resize sf::Texture (not sf::Sprite)
« on: February 21, 2012, 06:40:46 am »
Hi,

My program sets the resolution to the user's desktop resolution, then all sprites get scaled by (USER_DESKTOP_WIDTH/OPTIMAL_NATIVE_WIDTH).

This works nicely with everything so far, except the fullscreen scrolling background texture, which shows scaling artifacts/patterns (or whatever they are called).

Since the scaling amount never changes for the background texture once the program is started, this issue would be fixed, if instead of scaling the sprite every frame, the texture/image would be resized to the user's desktop resolution once, during initialization, and the sprite itself won't be scaled in the game loop.

Is there a way to do this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #1 on: February 21, 2012, 08:21:19 am »
Quote
scaling artifacts/patterns

Can you show us?

Quote
Since the scaling amount never changes for the background texture once the program is started, this issue would be fixed, if instead of scaling the sprite every frame, the texture/image would be resized to the user's desktop resolution once, during initialization, and the sprite itself won't be scaled in the game loop.

What makes you think that you would do a better job than the graphics card? ;)
Laurent Gomila - SFML developer

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #2 on: February 21, 2012, 02:42:25 pm »
Quote
Can you show us?

My issue seems to be the same as in this thread:
http://sfml-dev.org/forum/viewtopic.php?p=41500&sid=1afb67cbb20dbef76550bec5c1cc3056

With screenshots I cannot show it, it is only visible during motion. (Every individual scaled displayed image seems to be fine on its own, but every frame the scaling ends up a bit different, showing grid-like patterns)

I could demonstrate this by scrolling 2 of the same images one on top, one on the bottom, the top one is scaled down, the bottom one is 1-to-1. It would be clearly visible.

When I'm done writing that I'll upload it somewhere and you'll see what I am talking about.

Quote
What makes you think that you would do a better job than the graphics card?

You'll see in a bit :)
It is not actually me making a better job, it is about not having it scaled every frame would make the actual image look more...consistent. Can't really explain it like this

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #3 on: February 21, 2012, 02:56:14 pm »
Have you tried texture.SetSmooth(true)?

Quote
It is not actually me making a better job, it is about not having it scaled every frame would make the actual image look more...consistent.

The image is not scaled every frame, it is always kept at its initial size. It's just that different pixels are chosen by the rasterizer if the target sprite is bigger/smaller; this choice depends on the texture filter, which can be either "nearest pixel" or "bilinear".
Laurent Gomila - SFML developer

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #4 on: February 21, 2012, 03:36:08 pm »
Quote from: "Laurent"
Have you tried texture.SetSmooth(true)?


yes, that is set.

Please check this out, it clearly demonstrates what I am talking about:
http://www.mediafire.com/?wdtm3z6wp8mszie

The upper texture is scaled down from its native resolution, the lower one is 1to1. Both are set to smooth. These are the furthest layers in my parallax background, so if you press UP/DOWN they slightly move accordingly, during that the artifacts are even more apparent.

Thank You!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #5 on: February 21, 2012, 03:51:55 pm »
Are you talking about the jerky movement of the borders?

Your application doesn't show the borders of the upper texture, so it's hard to see if the bug only applies to the scaled texture.
Laurent Gomila - SFML developer

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #6 on: February 21, 2012, 04:02:04 pm »
Quote from: "Laurent"
Are you talking about the jerky movement of the borders?

Your application doesn't show the borders of the upper texture, so it's hard to see if the bug only applies to the scaled texture.


No... That's very strange, it seems like it doesn't show up when you run it, because it is super apparent when I do. And I tested it with 3 computers.

To me the lower texture is nice and smooth, scrolling nicely.
The upper, bigger one that is scaled down shows lots of artifacts as it is moving.

On the scaled texture the bright pixels appear to be flickering when moved.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #7 on: February 21, 2012, 04:13:51 pm »
Are you using a recent revision of SFML 2?

Which graphics card did you test this app on?
Laurent Gomila - SFML developer

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #8 on: February 21, 2012, 04:27:07 pm »
Quote from: "Laurent"
Are you using a recent revision of SFML 2?

Which graphics card did you test this app on?


Yes, 3 days old snapshot.

I tested it on a NV8800GTS, although I am using an adapter for a 3rd screen which is messing with the NVidia drivers, also on a netbook with a crappy Intel GMA950 and on computers at my school which probably also have some built-in intel stuff.

What I could think is that on a proper video card with settings set to "High Quality" and the likes fixes the issue I am having.

Either way, this would be fixed if a texture could be resized. Is there a way to do this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #9 on: February 21, 2012, 04:33:08 pm »
Quote
Either way, this would be fixed if a texture could be resized. Is there a way to do this?

No.
Laurent Gomila - SFML developer

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #10 on: February 21, 2012, 05:04:16 pm »
I see.

I am not sure if I understand it correctly, but mipmapping should fix this issue I am having, and I see there are a few threads asking about it. Is mipmapping still planned to be implemented in SFML?

If not, is it possible to just do it with OpenGL calls, while managing the loading of textures and everything else with SFML?

Also, resizing the texture is not implemented in SFML, but it is possible with raw OpenGL, right?

(sorry for all these questions, I really appreciate your work and help)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #11 on: February 21, 2012, 07:45:11 pm »
There is a way to scale sf::Image, but you have to do it manually. E.g., create a new image and perform pixel mapping.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #12 on: February 21, 2012, 08:12:42 pm »
Quote from: "Nexus"
There is a way to scale sf::Image, but you have to do it manually. E.g., create a new image and perform pixel mapping.


By manually, you mean I have to do it with OpenGL calls?
Could you please show me how?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #13 on: February 21, 2012, 10:31:41 pm »
OpenGL is a rendering API, it doesn't perform offline image transformations.

What you need is an image library, not a drawing API. Or a scaling algorithm, it's not hard to implement.
Laurent Gomila - SFML developer

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Scale/Resize sf::Texture (not sf::Sprite)
« Reply #14 on: February 23, 2012, 03:06:04 am »
Quote from: "Laurent"
OpenGL is a rendering API, it doesn't perform offline image transformations.

What you need is an image library, not a drawing API. Or a scaling algorithm, it's not hard to implement.


Thank You!
I have used http://code.google.com/p/imageresampler/
It is very lightweight and can nicely resample png (only to bmp or tga, but that is okay).
I made it so the first time my program is ran, or when resolution changes the background textures are resized to to appear pixel perfect on the user's screen resolution, that way there is no aliasing.

 
Quote

When mipmapping, we build scaled-down versions of our texture maps; when rendering portions of the scene where low texture detail is needed, we use the smaller textures.  Mipmapping can save memory and rendering time, but the motivating idea behind the technique's initial formulation was to increase the quality of the scene by reducing aliasing.  Aliasing happens because we're coloring each pixel based on the surface that, when projected to the view plane, contains the pixel center.  Small visual details can fit between pixel centers, so that as the viewpoint moves around, they appear and disappear.

This is what I was experiencing when running the program on lower resolutions and using a high resolution background image.

 

anything