Android window resizing problem

Hello! I have a problem with window resizing on an android device (Samsung s9) resolution 2220x1080. Below is a list with my attempts to make it work:

  • SDL_DisplayMode mode;
    SDL_GetCurrentDisplayMode(0,&mode);
    SCREEN_WIDTH = mode.h;
    SCREEN_HEIGHT = mode.w;
    m_Format = mode.format;
    SDL_WindowFlags w_flags = (SDL_WindowFlags)(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN_DESKTOP);
    m_Window = SDL_CreateWindow
    (“ZombieMania”,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,SCREEN_HEIGHT,SCREEN_WIDTH,w_flags);

  • SDL_RenderSetLogicalSize(m_Renderer,mode.h,mode.w);

  • SDL_SetWindowSize(m_Window,mode.w,mode.h);

  • SDL_SetRenderTarget(renderer,texture);
    SDL_RenderCopy(renderer,texture,NULL,NULL);
    SDL_SetRenderTarget(renderer,NULL);

  • SDL_GetDesktopDisplayMode(0,&mode);

  • SDL_RenderGetScale(m_Renderer,&xsc,&ysc);
    SDL_RenderSetScale(m_Renderer,37.0f,18.0f);

This is the result after all of the attempts. One line on the left part of the screen which is left blank.


Thank you.

I don’t know what the problem is, but, one way for the above x,y position of the rectangle containing your game to happen is to apply the offset twice.

(xoff==2*a, yoff==2*0==0)

I find curious in the screen below there’s a little square icon at top left.

1 Like

In Android, the window is always the same, so:

  1. Just open a window the size of a display
  2. Don’t change mode.w from mode.h
  • SDL_SetRenderTarget(renderer,texture);
    now you draw …
    SDL_SetRenderTarget(renderer,NULL);
    SDL_RenderCopy(renderer,texture,NULL,NULL);
    SDL_RenderPresent(SDLRenderer);
1 Like

Thank you for the fast response. I found that the problem was with the camera positioning. The camera viewport width is initialized with the size of the first level and the first level size is 1920X1080, so the other 300 pixels are left blank. Because of this on the left corner of the second picture appears a box which is on a right place.
Sizes of the renderer and the window were fine. Also I changed display mode.w and mode.h.

1 Like