new-engine/main.c
Warwick 86d57ade14 Initial SDL window test.
As an aside if you're on debian stable rn you will need sdl2 libs from
the testing branch.
2024-02-06 14:51:43 +00:00

47 lines
1.1 KiB
C

#include <SDL2/SDL.h>
#include <stdbool.h>
int main() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("Failed to initialize the SDL2 library\n");
return -1;
}
SDL_Window *window = SDL_CreateWindow("SDL2 Window", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 680, 480, 0);
if (!window) {
printf("Failed to create window\n");
return -1;
}
SDL_Surface *window_surface = SDL_GetWindowSurface(window);
if (!window_surface) {
printf("Failed to get the surface from the window\n");
return -1;
}
bool running = true;
while (running) {
// Create event handling struct
SDL_Event input;
while (SDL_PollEvent(&input) > 0) {
// Handle SDL quit event
if (input.type == SDL_QUIT) {
running = false;
}
switch (input.type) {
case SDL_QUIT:
running = false;
case SDL_KEYDOWN: {
const Uint8 *keys = SDL_GetKeyboardState(NULL);
if (keys[SDL_SCANCODE_ESCAPE])
running = false;
}
}
}
}
SDL_UpdateWindowSurface(window);
}