Logical scale pixel imprecision

When using a large window and a small render logical size and trying to draw a section of a texture, pixels out of the section to be drawn are sometimes grabbed. This is especially noticeable when drawing:
?Text from a bitmap font stored as a 16x6 ASCII matrix;
?Individual sections of a background image with different scrolling amounts to create a parallax scrolling effect.

Am I doing anything wrong or it is a bug in the library?

You need to always have a 1 pixel wide empty border around each separate sprite on your texture atlas. (This isn’t an SDL specific thing.)

One more problem happens when the hint SDL_HINT_RENDER_SCALE_QUALITY is set to “linear”: the font, stored in white over a magenta background, is drawn with a blend between the two colors. Magenta is set as the color key.

The problem with linear scale quality seems to affect mostly the borders of white and grey images.

  1. Create a render texture with same size as your logical size.
  2. Set the render texture as the target and draw all your stuff into it.
  3. remove the render texture as the target.
  4. Now use SDL logical scaling to draw the render texture to the window

This avoids the issue you are facing, and is the recommended way to go.

Now, as to why logical scale pixel imprecision is happening. This is normal
and actually not a bug. When you draw a texture with a size different from
its original size, then the underlying graphics such as OpenGL has to
generate the extra pixels by a process known as sampling. The smaller the
original texture is, the bigger the problem.

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: 9997478768On Wed, May 6, 2015 at 5:37 AM, M-374 LX wrote:

When using a large window and a small render logical size and trying to
draw a section of a texture, pixels out of the section to be drawn are
sometimes grabbed. This is especially noticeable when drawing:
?Text from a bitmap font stored as a 16x6 ASCII matrix;
?Individual sections of a background image with different scrolling
amounts to create a parallax scrolling effect.

Am I doing anything wrong or it is a bug in the library?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

This solves my problems, Pallav Nawani. Thanks.

Another problem has happened: random images from the desktop were shown on the mattes created by the letterboxing effect. However, this can be solved by using SDL_RenderClear() to clear the screen before setting the render target back to the buffer texture. This may be a useful tip in case someone has a similar problem.

You should always clear render targets if you aren’t going to fill them in completely with draw calls or you’ll end up with undefined areas.