diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6524201 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +*.a +*.so +*.exe diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..a8a9ad9 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +Egor Baranovsky (egorgeek) +baranovsky.egorka@yandex.ru + +Denis Butorin (dekabu) +dyonya0.0@gmail.com diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5a70dc8 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +PREFIX = /usr +HEADERSDIR = $(PREFIX)/include/glazir +LIBDIR = $(PREFIX)/lib64 + +HEADERS = src/glazir.h \ + src/types.h \ + src/window.h \ + src/version.h + +OBJ = src/window.o \ + src/main.o + +libglazir.a: $(OBJ) + ar rcs libglazir.a $(OBJ) + +install/headers: + mkdir -p $(HEADERSDIR) + cp $(HEADERS) $(HEADERSDIR) + +install/static: libglazir.a + mkdir -p $(LIBDIR) + cp libglazir.a $(LIBDIR) + +install: install/headers install/static + +uninstall/headers: + rm -r $(HEADERSDIR) + +uninstall/static: + rm $(LIBDIR)/libglazir.a + +uninstall: uninstall/headers uninstall/static + +clean: + rm src/*.o diff --git a/README.md b/README.md index f1a4ca9..9101134 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ # glazir +## Описание +C-библиотека для математических и физических визуализаций, основанная на [SDL3](https://www.libsdl.org/) + +## Инструкция по сборке +1. Склонируйте репозиторий и перейдите в директорию +```sh +git clone https://git.kpfu.su/GLAZIR/glazir +cd glazir +``` +2. Соберите библиотеку +```sh +make +``` +3. Установите библиотеку +```sh +make install +``` diff --git a/src/glazir.h b/src/glazir.h new file mode 100644 index 0000000..b68dcf3 --- /dev/null +++ b/src/glazir.h @@ -0,0 +1,13 @@ +#ifndef GLAZIR +#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 new file mode 100644 index 0000000..c3a2ce5 --- /dev/null +++ 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/version.h b/src/version.h new file mode 100644 index 0000000..d62b70b --- /dev/null +++ b/src/version.h @@ -0,0 +1,3 @@ +#define PIE_VERSION_MAJOR 0 +#define PIE_VERSION_MINOR 1 +#define PIE_VERSION_PATCH 0 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);