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
Logical scale pixel imprecision
M-374 LX


Joined: 05 May 2015
Posts: 7
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?
Christian Knudsen


Joined: 14 Nov 2009
Posts: 37
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.)
M-374 LX


Joined: 05 May 2015
Posts: 7
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.
M-374 LX


Joined: 05 May 2015
Posts: 7
The problem with linear scale quality seems to affect mostly the borders of white and grey images.
Logical scale pixel imprecision
Pallav Nawani


Joined: 19 May 2011
Posts: 122
Location: Dehradun, India
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: 9997478768



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

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

M-374 LX


Joined: 05 May 2015
Posts: 7
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.
Christian Knudsen


Joined: 14 Nov 2009
Posts: 37
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.