To make your SDL window respond to close events, you need to modify your event handling loop to detect when the SDL_QUIT event is triggered, which occurs when the window's close button is clicked. Here's how you can incorporate this into your code:
#include <SDL.h>
#include "Window.h"
int main(int argc, char** argv) {
Window GameWindow;
SDL_Event event;
bool running = true;
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = false;
}
}
GameWindow.RenderFrame();
}
SDL_Quit();
return 0;
}
This modification introduces a boolean flag running
that controls the main loop. The loop continues as long as running
is true, but sets running
to false when an SDL_QUIT event is detected, effectively closing the window.
Answers to questions are automatically generated and may not have been reviewed.
Learn how to create and customize windows, covering initialization, window management, and rendering