@fcu: you are processing the SDL event queue incorrectly. In each frame of the game, you should process all events that exist in the queue, i.e. use a loop:
{$mode objfpc}
{$apptype gui}
program Demo;
uses
SDL2;
var
Window: PSDL_Window;
Renderer: PSDL_Renderer;
Event: TSDL_Event;
Done: Boolean = False;
begin
SDL_Init(SDL_INIT_VIDEO);
Window := SDL_CreateWindow ('Demo', 50, 50, 800, 600, SDL_WINDOW_SHOWN);
Renderer := SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED);
while not Done do
begin
while SDL_PollEvent(@Event) = 1 do
case Event.Type_ of
SDL_QUITEV: Done := True;
end;
SDL_SetRenderDrawColor(Renderer, 32, 38, 42, 255);
SDL_RenderClear (Renderer);
SDL_RenderPresent (Renderer);
end;
SDL_DestroyRenderer(Renderer);
SDL_DestroyWindow (Window);
SDL_Quit();
end.
Instead of the Done flag, you can simply jump to the label. After all, rendering the frame when the loop is about to end is unnecessary:
{$mode objfpc}
{$apptype gui}
program Demo;
uses
SDL2;
label
Cleanup;
var
Window: PSDL_Window;
Renderer: PSDL_Renderer;
Event: TSDL_Event;
begin
SDL_Init(SDL_INIT_VIDEO);
Window := SDL_CreateWindow ('Demo', 50, 50, 800, 600, SDL_WINDOW_SHOWN);
Renderer := SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED);
repeat
while SDL_PollEvent(@Event) = 1 do
case Event.Type_ of
SDL_QUITEV: goto Cleanup;
end;
SDL_SetRenderDrawColor(Renderer, 32, 38, 42, 255);
SDL_RenderClear (Renderer);
SDL_RenderPresent (Renderer);
until False;
Cleanup:
SDL_DestroyRenderer(Renderer);
SDL_DestroyWindow (Window);
SDL_Quit();
end.
Pro tip: start using the
Shift key and format your code properly. I know it's a test program, but that's how you can recognize a professional, that they always write readable and formatted code.
By the way,
SDL3 is already available (preview version) — take an interest in it, because it is much better than SDL2 and soon it will be the standard. Of course, if you can write your own headers, because you won't find them on the net for a long time (I wrote these myself, for my own game — nothing difficult).