Created the Window and Renderer and started implementing the functions

for the game loop
This commit is contained in:
abdelrahman committed 2022-09-10 22:17:58 +01:00
1 parent a0d8b75c11
commit 33066b381e
11 files changed
+280 -24

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
#include "Window.h"
#include "Renderer.h"
#include "engine_build_config.h"
#include <stdbool.h>
#ifdef DEBUG_ENGINE
#include <stdio.h>
#endif /* DEBUG_ENGINE */
bool init_window(Window *wnd, const char *title, int width, int height,
bool full_screen) {
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->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 fill_window_with_color(const Window *wnd, SDL_Color color) {
render_clear(wnd->renderer, color);
}
void swap_render_buffers(const Window *wnd) { swap_buffers(wnd->renderer); }
void destroy_window(Window *wnd) {
if (wnd->SDL_base_window) {
if (wnd->renderer) {
destroy_renderer(wnd->renderer);
}
SDL_DestroyWindow(wnd->SDL_base_window);
wnd->SDL_base_window = NULL;
wnd->width = 0;
wnd->height = 0;
#ifdef DEBUG_ENGINE
printf("Window destroyed successfully\n");
#endif /* DEBUG_ENGINE */
}
}