Problem with scaling?

Hi all,

I’m porting a game from SDL 1.2 to SDL 2. The original resolution is
256x192, in SDL 1.2 I use rotozoom to make 2x/3x/etc zoom working
without problems.

It’s very simple: I load a big PNG (Surface in 1.2, Texture in 2) and
take tiles (size 8x8) and blit to the screen (SDL_BlitSurface in 1.2,
SDL_RenderCopy in SDL 2).

In SDL2: I make a SDL_Window 256x192 and SDL_Renderer at the same
size, no problems,

The problem comes when the window resolution is bigger than Renderer,
some black lines appears between two tiles (look at red rects).

How to solve this problem ?

SDL_Window***
SDL_Window *screen = SDL_CreateWindow(“Abbaye des Morts
v2.0”,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,512,384,SDL_WINDOW_OPENGL);


SDL_Renderer


SDL_Renderer *renderer = SDL_CreateRenderer(screen, -1,
SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 1);
SDL_RenderSetLogicalSize(renderer, 256, 192);


Thanks for your help.


Un saludo,

David Lara

Most likely this is due to scaling. When scaling a textured poly, the
graphics card has to decide from which location on texture to pick the
color for the current pixel. Since your tiles are closely packed in the
PNG, it might end up sampling the next tile for the data, or
interpolating from two texture pixels, one of which is from the adjacent
tile.

One solution is to SDL_SetHint(“SDL_HINT_RENDER_SCALE_QUALITY”, “0”)
before loading the PNG. This will prevent any kind of interpolation of
texture pixels.
Other solution is to adjust the data in your PNG to prevent any overlap.
What you can do is to increase the tile size to 10x10 and fill the extra
space in the tile by replicating the border pixels. Then, when you draw
them, take the inner 8x8 & blit it as always.

Alternatively, you can put each tile into its own separate image.On 8/22/2013 12:47 AM, David Lara wrote:

Hi all,

I’m porting a game from SDL 1.2 to SDL 2. The original resolution is
256x192, in SDL 1.2 I use rotozoom to make 2x/3x/etc zoom working
without problems.

It’s very simple: I load a big PNG (Surface in 1.2, Texture in 2) and
take tiles (size 8x8) and blit to the screen (SDL_BlitSurface in 1.2,
SDL_RenderCopy in SDL 2).

In SDL2: I make a SDL_Window 256x192 and SDL_Renderer at the same
size, no problems,
http://imageshack.us/f/38/04ki.png/

The problem comes when the window resolution is bigger than Renderer,
some black lines appears between two tiles (look at red rects).
http://imageshack.us/f/853/ctqi.png/

How to solve this problem ?

SDL_Window


SDL_Window *screen = SDL_CreateWindow(“Abbaye des Morts
v2.0”,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,512,384,SDL_WINDOW_OPENGL);


SDL_Renderer


SDL_Renderer *renderer = SDL_CreateRenderer(screen, -1,
SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 1);
SDL_RenderSetLogicalSize(renderer, 256, 192);


Thanks for your help.


Pallav Nawani
Game Designer/CEO
http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming