I have the following code to create a window, fill it with red, and display it. This was mostly taken directly from some other answer on here, so should be perfectly fine.
// test.cpp
#include <SDL2/SDL.h>
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = NULL;
window = SDL_CreateWindow(
"Title",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_SHOWN
);
SDL_Renderer* renderer = NULL;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(5000);
SDL_DestroyWindow(window);
SDL_Quit();
return EXIT_SUCCESS;
}
I compile with g++ -std=c++20 test.cpp -lSDL2
, no errors are raised.
Then I run the resulting executable, and all I see is this:
for 5 seconds.
The basic entity of a window is shown I guess, but neither are its dimensions nor its contents.
Anyone have any idea what might be happening? I'm on Ubuntu Studio 22.04.
EDIT:
I have now changed the SDL_RenderPresent(renderer);
to a code block containing an event loop:
SDL_bool quit = SDL_FALSE;
while(!quit)
{
SDL_RenderPresent(renderer);
SDL_Event event;
SDL_WaitEvent(&event);
if(event.type == SDL_QUIT)
quit = SDL_TRUE;
}
Now a red window is shown if the mouse is in the window, but the window is black if the mouse is outside of it. Which is a whole new problem, because nowhere does my code state that it should do that.