I came across a behavior in SDL3 that concerns me. In SDL3, the standard position of the origin of the screen's coordinate system is in the upper left corner.
I tried rendering a simple 100x100 rectangle in the origin of a maximized window:
#include <SDL3/SDL.h>
int main()
{
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Init(SDL_INIT_VIDEO);
SDL_CreateWindowAndRenderer("win",800,600,SDL_WINDOW_RESIZABLE,&window,&renderer);
SDL_MaximizeWindow(window);
SDL_FRect r({0,0,100,100});
while(true)
{
//SDL_Event event;
//SDL_PollEvent(&event); <--Only when this line is included will the rendering position be correct
SDL_SetRenderDrawColorFloat(renderer,1,1,1,1);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColorFloat(renderer,0,0,0,1);
SDL_RenderFillRect(renderer,&r);
SDL_RenderPresent(renderer);
}
return 0;
}
To my surprise, the rectangle appeared in on the left side, but in middle height of the screen.
However, only when I added the event polling, would it be rendered correctly in the upper left corner of the screen.
I am very confused about this interaction of the function SDL_PollEvent() and the rendering. Why is this happening?
SDL_PollEventfor SDL to internally process OS events and handle them to correctly center your drawing area.