#include "Window.h" #include "Renderer.h" #include "engine_build_config.h" #include #ifdef DEBUG_ENGINE #include #endif /* DEBUG_ENGINE */ bool init_window(Window *wnd, const char *title, int width, int height, SDL_Color color, bool full_screen) { if (!wnd) { return false; } Uint32 window_flags = SDL_WINDOW_ALLOW_HIGHDPI; if (full_screen) { window_flags |= SDL_WINDOW_FULLSCREEN; } wnd->SDL_base_window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags); if (!wnd->SDL_base_window) { return false; } SDL_GetWindowSize(wnd->SDL_base_window, &(wnd->width), &(wnd->height)); wnd->background_color = color; wnd->renderer = create_renderer(); if (!wnd->renderer || !init_renderer(wnd->renderer, wnd->SDL_base_window)) { destroy_window(wnd); return false; } #ifdef DEBUG_ENGINE printf("Renderer initialised successfully\n"); printf("Window initialised successfully with width %d and height %d\n", wnd->width, wnd->height); #endif /* DEBUG_ENGINE */ return true; } void clear_window(const Window *wnd) { if (!wnd) { return; } render_clear(wnd->renderer, wnd->background_color); } void swap_render_buffers(const Window *wnd) { if (!wnd) { return; } swap_buffers(wnd->renderer); } void destroy_window(Window *wnd) { if (!wnd) { return; } if (wnd->SDL_base_window) { if (wnd->renderer) { destroy_renderer(wnd->renderer); wnd->renderer = NULL; } SDL_DestroyWindow(wnd->SDL_base_window); wnd->SDL_base_window = NULL; wnd->width = 0; wnd->height = 0; wnd->background_color = (SDL_Color){0, 0, 0, 255}; #ifdef DEBUG_ENGINE printf("Window destroyed successfully\n"); #endif /* DEBUG_ENGINE */ } }