diff --git a/Makefile b/Makefile index c1935a1..5a70dc8 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,12 @@ HEADERSDIR = $(PREFIX)/include/glazir LIBDIR = $(PREFIX)/lib64 HEADERS = src/glazir.h \ + src/types.h \ + src/window.h \ src/version.h -OBJ = src/main.o +OBJ = src/window.o \ + src/main.o libglazir.a: $(OBJ) ar rcs libglazir.a $(OBJ) @@ -27,3 +30,6 @@ uninstall/static: rm $(LIBDIR)/libglazir.a uninstall: uninstall/headers uninstall/static + +clean: + rm src/*.o diff --git a/src/glazir.h b/src/glazir.h index d60dde2..b68dcf3 100644 --- a/src/glazir.h +++ b/src/glazir.h @@ -2,5 +2,12 @@ #define GLAZIR #include "version.h" +#include "window.h" + +void gr_init(int argc, char *argv[]); + +void gr_event(gr_Event *event); + +void gr_frame(); #endif diff --git a/src/main.c b/src/main.c index e69de29..c3a2ce5 100644 --- a/src/main.c +++ b/src/main.c @@ -0,0 +1,36 @@ +#define SDL_MAIN_USE_CALLBACKS 1 +#include +#include + +#include "glazir.h" + +SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) +{ + if (!SDL_Init(SDL_INIT_VIDEO)) { + SDL_Log("Не удалось инициализировать SDL: %s", SDL_GetError()); + return SDL_APP_FAILURE; + } + + gr_init(argc, argv); + + return SDL_APP_CONTINUE; +} + +SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) +{ + gr_event(event); + + return SDL_APP_CONTINUE; +} + +SDL_AppResult SDL_AppIterate(void *appstate) +{ + gr_frame(); + + return SDL_APP_CONTINUE; +} + +void SDL_AppQuit(void *appstate, SDL_AppResult result) +{ + +} diff --git a/src/types.h b/src/types.h new file mode 100644 index 0000000..0652aaf --- /dev/null +++ b/src/types.h @@ -0,0 +1,10 @@ +#include + +struct _gr_Window { + SDL_Window* w; + SDL_Renderer* r; +}; + +typedef struct _gr_Window gr_Window; + +typedef SDL_Event gr_Event; diff --git a/src/window.c b/src/window.c new file mode 100644 index 0000000..6ee97a1 --- /dev/null +++ b/src/window.c @@ -0,0 +1,11 @@ +#include "window.h" + +int gr_createWindow(const char* title, int width, int height, gr_Window* window) +{ + return SDL_CreateWindowAndRenderer(title, width, height, 0, &window->w, &window->r); +} + +void gr_drawWindow(gr_Window* window) +{ + SDL_RenderPresent(window->r); +} diff --git a/src/window.h b/src/window.h new file mode 100644 index 0000000..e92fd1e --- /dev/null +++ b/src/window.h @@ -0,0 +1,5 @@ +#include "types.h" + +int gr_createWindow(const char* title, int width, int height, gr_Window* window); + +void gr_drawWindow(gr_Window* window);