ona/src/main.zig

45 lines
1.0 KiB
Zig
Raw Normal View History

2022-08-10 15:52:16 +02:00
const c = @cImport({
@cInclude("SDL2/SDL.h");
});
const std = @import("std");
pub fn main() anyerror!void {
if (c.SDL_Init(c.SDL_INIT_EVERYTHING) != 0) {
c.SDL_LogCritical(c.SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize SDL2");
return error.SystemFailure;
}
defer c.SDL_Quit();
const sdl_window = create_sdl_window: {
const pos = c.SDL_WINDOWPOS_UNDEFINED;
var flags = @as(u32, 0);
break: create_sdl_window c.SDL_CreateWindow("Ona", pos, pos, 640, 480, flags);
};
if (sdl_window == null) {
c.SDL_LogCritical(c.SDL_LOG_CATEGORY_APPLICATION, "Failed to create window");
return error.SystemFailure;
}
defer c.SDL_DestroyWindow(sdl_window);
var is_running = true;
while (is_running) {
var sdl_event = std.mem.zeroes(c.SDL_Event);
while (c.SDL_PollEvent(&sdl_event) != 0) {
switch (sdl_event.type) {
c.SDL_QUIT => is_running = false,
else => {},
}
}
}
}