SDl window resize problem
Opened this issue · 7 comments
Hello how can I fix the problem that is visualized in the picture when resizing the sdl window.
What do I need to do to make it scale with the window ?
SDL_WINDOWEVENT: if Event.window.event = SDL_WINDOWEVENT_RESIZED then begin WindowWidth := Event.window.data1; WindowHeight := Event.window.data2; UpdateDestRect(); end;
Code not working
You need to post more code.
- How do you set up the SDL window?
- What does your rendering function look like?
program project1;
{$APPTYPE GUI}
uses
sdl2, sdl2_image, Windows;
var
SDLWindow: PSDL_Window;
SDLRenderer: PSDL_Renderer;
Running: Boolean;
Event: TSDL_Event;
WindowWidth, WindowHeight: Integer;
begin
// Inicjalizacja SDL
if SDL_Init(SDL_INIT_VIDEO) < 0 then
begin
MessageBox(0, 'SDL could not initialize!', 'Error', MB_ICONERROR or MB_OK);
Halt(1);
end;
// Ustawienia początkowe okna
WindowWidth := 800;
WindowHeight := 600;
// Tworzenie okna SDL
SDLWindow := SDL_CreateWindow('SDL window', SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WindowWidth, WindowHeight, SDL_WINDOW_RESIZABLE);
if SDLWindow = nil then
begin
MessageBox(0, 'Window could not be created!', 'Error', MB_ICONERROR or MB_OK);
SDL_Quit;
Halt(1);
end;
// Tworzenie renderera
SDLRenderer := SDL_CreateRenderer(SDLWindow, -1, SDL_RENDERER_ACCELERATED or SDL_RENDERER_PRESENTVSYNC);
if SDLRenderer = nil then
begin
MessageBox(0, 'Renderer could not be created!', 'Error', MB_ICONERROR or MB_OK);
SDL_DestroyWindow(SDLWindow);
SDL_Quit;
Halt(1);
end;
// Pętla główna aplikacji
Running := True;
while Running do
begin
// Obsługa zdarzeń
while SDL_PollEvent(@Event) <> 0 do
begin
case Event.type_ of
SDL_QUITEV:
Running := False;
SDL_KEYDOWN:
if Event.key.keysym.sym = SDLK_ESCAPE then
Running := False;
SDL_WINDOWEVENT:
case Event.window.event of
SDL_WINDOWEVENT_RESIZED:
begin
end;
end;
end;
// Renderowanie tła
SDL_SetRenderDrawColor(SDLRenderer, 72, 69, 71, 255); // Szary kolor
SDL_RenderClear(SDLRenderer); // Wypełnij całe okno
// Zaktualizuj ekran
SDL_RenderPresent(SDLRenderer);
end;
// Sprzątanie zasobów
SDL_DestroyRenderer(SDLRenderer);
SDL_DestroyWindow(SDLWindow);
SDL_Quit;
end.Does anyone have any idea how this problem can be solved ?
Is this the actual code, though? It fails to compile for me because of an unclosed block.
while Running do
begin // <-- 1st block opened
while SDL_PollEvent(@Event) <> 0 do
begin // <-- 2nd block opened
case Event.type_ of // <-- 3rd block opened
SDL_QUITEV:
Running := False;
SDL_KEYDOWN:
if Event.key.keysym.sym = SDLK_ESCAPE then
Running := False;
SDL_WINDOWEVENT:
case Event.window.event of // <-- 4th block opened
SDL_WINDOWEVENT_RESIZED:
begin // <-- 5th block opened
end; // <-- close 5th block
end; // <-- close 4th block
end; // <-- close 3rd block
SDL_SetRenderDrawColor(SDLRenderer, 72, 69, 71, 255);
SDL_RenderClear(SDLRenderer);
// Zaktualizuj ekran
SDL_RenderPresent(SDLRenderer);
end; <-- close 2nd blockAfter I added another end; to the event handling bit, it works and resizes fine.
program project1;
{$APPTYPE GUI}
uses
sdl2, sdl2_image, Windows;
var
SDLWindow: PSDL_Window;
SDLRenderer: PSDL_Renderer;
Running: Boolean;
Event: TSDL_Event;
WindowWidth, WindowHeight: Integer;
begin
// Inicjalizacja SDL
if SDL_Init(SDL_INIT_VIDEO) < 0 then
begin
MessageBox(0, 'SDL could not initialize!', 'Error', MB_ICONERROR or MB_OK);
Halt(1);
end;
// Ustawienia początkowe okna
WindowWidth := 800;
WindowHeight := 600;
// Tworzenie okna SDL
SDLWindow := SDL_CreateWindow('SDL window', SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WindowWidth, WindowHeight, SDL_WINDOW_RESIZABLE);
if SDLWindow = nil then
begin
MessageBox(0, 'Window could not be created!', 'Error', MB_ICONERROR or MB_OK);
SDL_Quit;
Halt(1);
end;
// Tworzenie renderera
SDLRenderer := SDL_CreateRenderer(SDLWindow, -1, SDL_RENDERER_ACCELERATED or SDL_RENDERER_PRESENTVSYNC);
if SDLRenderer = nil then
begin
MessageBox(0, 'Renderer could not be created!', 'Error', MB_ICONERROR or MB_OK);
SDL_DestroyWindow(SDLWindow);
SDL_Quit;
Halt(1);
end;
// Pętla główna aplikacji
Running := True;
while Running do
begin
// Obsługa zdarzeń
while SDL_PollEvent(@Event) <> 0 do
begin
case Event.type_ of
SDL_QUITEV:
Running := False;
SDL_KEYDOWN:
if Event.key.keysym.sym = SDLK_ESCAPE then
Running := False;
SDL_WINDOWEVENT:
case Event.window.event of
SDL_WINDOWEVENT_RESIZED:
begin
end;
end;
end;
end;
// Renderowanie tła
SDL_SetRenderDrawColor(SDLRenderer, 72, 69, 71, 255); // Szary kolor
SDL_RenderClear(SDLRenderer); // Wypełnij całe okno
// Zaktualizuj ekran
SDL_RenderPresent(SDLRenderer);
end;
// Sprzątanie zasobów
SDL_DestroyRenderer(SDLRenderer);
SDL_DestroyWindow(SDLWindow);
SDL_Quit;
end.I mean that the window scales only the background does not scale at the same time as the window
Hmm. I'm getting the exact same behaviour with an analogue C program - SDL does not create any events while dragging the window corner, only when I finish resizing the window (i.e. let go of the dragging action). You might be better off asking about this in the SDL forums.
Thanks for the hint
