The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_RenderCopy scaling artifacts
tjpalmer


Joined: 02 Mar 2015
Posts: 8
Take two (on a new topic now) to see if I can get help.

I build a single 320x200 text in a pixel-specific way, and then I use SDL_RenderCopy to draw it at full window size.

However, it has stray pixels. See for example between the middle row of bricks here:



Is this expected behavior? I've tried setting hints, to no effect. Any recommendations?
Re: SDL_RenderCopy scaling artifacts
mbabuskov


Joined: 08 Feb 2015
Posts: 29
tjpalmer wrote:
I've tried setting hints, to no effect. Any recommendations?


Are you sure you set hints before texture was created? Which hints did you try? Linear, nearest?
SDL_RenderCopy scaling artifacts
Pallav Nawani


Joined: 19 May 2011
Posts: 122
Location: Dehradun, India
Hints should be set before texture is created. Afterwards it doesn't matter.
What kind of artifacts? Can you upload a screenshot somewhere?

Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter:  http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768



On Wed, Mar 4, 2015 at 2:29 PM, mbabuskov wrote:
Quote:



tjpalmer wrote:

I've tried setting hints, to no effect. Any recommendations?




Are you sure you set hints before texture was created? Which hints did you try? Linear, nearest?



bigosaur.com


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_RenderCopy scaling artifacts
tjpalmer


Joined: 02 Mar 2015
Posts: 8
mbabuskov wrote:
Are you sure you set hints before texture was created? Which hints did you try? Linear, nearest?


Thanks so much for the reply. I had missed the need to set it before the texture is created.

However, as I somewhat feared (though I still wanted to try it), this won't help. Linear doesn't have the stray pixels, but I really want nearest, because linear blurs. (Linear still has edge issues, too, at the very ends of the texture, although I think I know how to deal with that by putting a transparent edge in my texture.)

I've tried scaling manually myself on CPU now, too. It looks just right, but it's too slow. (Current implementation is step by float, and truncate. Could look at optimizing.) I've considered all kinds of hacks (CPU scale to not full but still integer fraction of screen/window size, many other things, ...), but maybe I should just bite the bullet and go to GL and shaders. That's a bunch of extra work and learning curve, but I suspect I could get it to do the simple scaling that I want.

Any other easy fixes I should try first?
Re: SDL_RenderCopy scaling artifacts
mbabuskov


Joined: 08 Feb 2015
Posts: 29
tjpalmer wrote:
However, as I somewhat feared (though I still wanted to try it), this won't help


Won't or didn't?

I using this for my game and it works fine. Perhaps there's something wrong with alpha channel on your image or something like that (for example I discovered that some graphics programs create files with unexpected extra data in the alpha channel that can messup the way it looks on screen). How are you loading image, is it from PNG file? Does to problem also show up when you load from BMP or JPG?

If the problem is not visible in BMP/JPG then try fixing the PNG image. I recall have similar issues and just added a completely black layer behind the graphics, re-exported with Gimp and everything was fine afterwards. Also check if background color is saved in PNG.

Could you post the original image file that shows artifacts when scaled?
Re: SDL_RenderCopy scaling artifacts
tjpalmer


Joined: 02 Mar 2015
Posts: 8
mbabuskov wrote:
Won't or didn't?


Didn't achieve the effect I need. Default seems to be nearest (and is shown in my earlier screenshot), which is what I want, if not for the artifacts.

Here's what I want (from my manual C++ scaling code), nearest sans artifacts:



And here is what linear does: