aboutsummaryrefslogtreecommitdiff
path: root/lib/init.c
diff options
context:
space:
mode:
authoriceyrazor <iceyrazor@mailfence.com>2026-05-28 18:49:05 -0500
committericeyrazor <iceyrazor@mailfence.com>2026-05-28 18:49:05 -0500
commit53664714b9a693391054d1c0c601b285f2b1a577 (patch)
tree0a9f9e6d6dcf61f9f8d13f1e8c45e8ab6b361a9c /lib/init.c
init
Diffstat (limited to 'lib/init.c')
-rw-r--r--lib/init.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/lib/init.c b/lib/init.c
new file mode 100644
index 0000000..9321038
--- /dev/null
+++ b/lib/init.c
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include <time.h>
+#include <init.h>
+
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_video.h>
+#include <SDL2/SDL_ttf.h>
+
+int main(int argc, char *argv[])
+{
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
+ SDL_Log("SDL fails to initialize! %s\n", SDL_GetError());
+
+ if (TTF_Init() < 0)
+ SDL_Log("SDL fails to initialize ttf! %s\n", SDL_GetError());
+
+ int startw=600;
+ int starth=600;
+
+ SDL_Window *window = SDL_CreateWindow(PROJECT_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, startw, starth, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
+ if (!window) {
+ printf("Failed to create window: %s\n", SDL_GetError());
+ }
+ SDL_Renderer *renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_SOFTWARE);
+ if (!renderer) {
+ printf("Failed to create renderer: %s\n", SDL_GetError());
+ }
+
+ srand(time(NULL));
+ OBJECT_INER obj_storage[obj_n];
+
+ STUFFS stuff = {
+ startw,
+ starth,
+ false,
+ 0,
+ 0,
+ NULL,
+ NULL,
+ (OBJECT){},
+ };
+
+ stuff.renderer = renderer;
+
+ stuff.font = TTF_OpenFont("/usr/share/fonts/TTF/JetBrainsMono-Regular.ttf" , 10);
+
+ init_stuffs(startw,starth,obj_storage,&stuff);
+
+
+
+ for (int i = 0; i < obj_n; i++)
+ stuff.obj.objs[i] = &obj_storage[i];
+
+ SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
+
+ bool quit = false;
+ SDL_Event e;
+ while (!quit) {
+ while (SDL_PollEvent(&e)) {
+ if (e.type == SDL_QUIT) {
+ quit = true;
+ }
+ else if(e.type == SDL_MOUSEBUTTONDOWN){
+ if(e.button.button==SDL_BUTTON_LEFT){
+ stuff.mousedown=true;
+ } else if(e.button.button==SDL_BUTTON_RIGHT){
+ }
+ } else if(e.type==SDL_MOUSEBUTTONUP){
+ stuff.mousedown=false;
+ }
+ stuff.mx=e.button.x;
+ stuff.my=e.button.y;
+ }
+ draw(window,&stuff);
+ SDL_Delay(10);
+ }
+
+ on_end(&stuff);
+ TTF_CloseFont(stuff.font);
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
+
+ SDL_Quit();
+
+ return 0;
+}