c++windowsdlsdl-3

White bars when resizing the window


enter image description here

I am trying to create a window with SDL3 using the following code

#include "SDL3/SDL.h"
#include "SDL3/SDL_system.h"

int main(){
    unsigned int sdlFlags = 0;
    sdlFlags |= SDL_WINDOW_RESIZABLE;
    sdlFlags |= SDL_WINDOW_BORDERLESS;
    sdlWindow = SDL_CreateWindow(InTitle, InWidth, InHeight, sdlFlags);
    while(true){
        SDL_PollEvent(&sdlEvent);
        switch (sdlEvent.type)
        {
            case SDL_EVENT_WINDOW_CLOSE_REQUESTED:  break;
        }

    }
}

But when you try to resize the window, white stripes appear that do not disappear

The problem arose when switching from SDL2 to SDL3


Solution

  • Clear the window contents. This could be done with a rendering API like Vulkan or indirectly with SDL's own abstract rendering features, expanding the original question's code something like this:

    #include "SDL3/SDL.h"
    #include "SDL3/SDL_system.h"
    
    int main(){
        unsigned int sdlFlags = 0;
        sdlFlags |= SDL_WINDOW_RESIZABLE;
        sdlFlags |= SDL_WINDOW_BORDERLESS;
        SDL_Window* sdlWindow = SDL_CreateWindow(InTitle, InWidth, InHeight, sdlFlags);
        SDL_Renderer* sdlRenderer = SDL_CreateRenderer(sdlwindow, NULL);
        SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255); // opaque black
    
        while(true){
            SDL_PollEvent(&sdlEvent);
            switch (sdlEvent.type)
            {
                case SDL_EVENT_WINDOW_CLOSE_REQUESTED:  break;
            }
            // Draw the window contents, starting by clearing it:
            SDL_RenderClear(sdlRenderer);
            // Draw stuff...
            // Show the rendered contents in the window:
            SDL_RenderPresent(sdlRenderer);
    
        }
    }
    

    Untested example derived from OP's code and from this official example: https://wiki.libsdl.org/SDL3/SDL_RenderClear