When I start this demo, the window briefly appears in black at the top left, then it centers itself. Then wait 2 seconds. Then it disappears again briefly and only then does it turn yellow.
Shouldn’t it appear centered from the start and then fade gently to yellow after 2 seconds?
That can be resolved by starting the window in a hidden state, it’s trying to show content before the window is fully initialized.
SDL_RenderClear/SDL_RenderPresent doesn’t work on a hidden window, but starting in a hidden state does at least stop the flickering window position.
The window then gets to start with that little “grow” animation on gnome in which it is given a couple of frames worth of time to draw the screen content so that it looks correct in time.
Side note: I’m using ctrl-e to wrap code in tags, it puts 3 back-ticks (```) instead of just one, that’s my guess why my post has different syntax highlighting…?
I changed it a little with the SDL_WINDOW_HIDDEN. I also removed the first delay.
Now the window still flashes black briefly before turning yellow. But when recoloring the window changes position.
I still remember when I was tinkering with native X11. The window manager positions the window in the position that suits it.
I was trying to say something that Peter stated much more clearly then edited out from his own post; the renderer should be created before the window is shown. Creating the renderer is part of the initialization that I was trying to refer to.
Please see my post above, where I edited in an example.
I was trying to explain my thoughts on the order of functions that I think you would probably want to follow (like don’t render to the screen before it is shown because it won’t draw on a hidden window).
I kind of fumbled that explanation, sorry.
In the Wiki it is also wrong in the description above. But I have just corrected this. The demo below is ok, except for the window pos shifting problem.
The demo is not ok because the main loop does not process all pending events in a single iteration, but only pops one event from the queue. There should be two while loops — the main one and the nested one, emptying the entire event queue before rendering the frame.
Yes — this is a correct way to process SDL events queue in the game loop. Maybe it does not fix your problem but the SDL wiki should contain correct examples. If someone C-oriented have a minute, please update the SDL wiki.