(SOLVED)[SDL2] - Keep Aspect Ratio Of Resized Window?

Hi,

Working on a new SDL2 project.
Is there a simple method to keep aspect ratio of a resized window?
Let us know, thanks!

Jesse

Hi,

We figured out keeping aspect ratio of resized windows:
SDL_RenderSetLogicalSize(Renderer, 1024, 640);

Problem now is our test sprite image is not correctly scaling on window resize?
(code is below)

//-------------------------------------------------------------------------------------------------
void VisualsCore::DrawSprite(void)
{
    int windowWidth;
    int windowHeight;
    float winWidthFixed;
    float winHeightFixed;

    SDL_GetWindowSize(Window, &windowWidth, &windowHeight);

    winWidthFixed = (float)windowWidth / 1024;
    winHeightFixed = (float)windowHeight / 640;

    SDL_Rect dstrect;
    dstrect.x = 0;
    dstrect.y = 0;
    dstrect.w = 256 * winWidthFixed;
    dstrect.h = 256 * winHeightFixed;

printf("W=%i / H=%i / WW=%i / WH=%i \n", dstrect.w, dstrect.h, windowWidth, windowHeight);

    SDL_RenderCopyEx(Renderer, texture, NULL, &dstrect, 0, NULL, SDL_FLIP_NONE);

}

Hi,

I scale the window by an factor of 2.
SDL_RenderSetScale(Renderer, 2.0f, 2.0f);

When I comment out the above command, the window resize works properly?
(test sprite also resizes properly)

Any ideas?

Ok, got it working now.

Had to place:
SDL_RenderSetScale(Renderer, 2.0f, 2.0f);
before:
SDL_RenderSetLogicalSize(Renderer, 1024, 640);