Răsfoiți Sursa

Adding basic sdl3 prog

Vinicius Teshima 1 an în urmă
părinte
comite
573ceb3d8f
2 a modificat fișierele cu 69 adăugiri și 1 ștergeri
  1. 4 1
      Makefile
  2. 65 0
      src/sdl3.c

+ 4 - 1
Makefile

@@ -8,7 +8,10 @@ CFLAGS=-ansi -m64 -Og -fsanitize=address -ggdb \
 -Wmissing-declarations \
 -Wmissing-prototypes -Wnested-externs -Werror
 
-cint: ${SRCS} ${HDRS}
+sdl3: src/sdl3.c ${HDRS}
+	gcc $(shell pkg-config --cflags sdl3) $(shell pkg-config --libs sdl3) -ggdb ${CFLAGS} $^ -o $@
+
+cint: src/cint.c ${HDRS}
 	gcc -ggdb ${CFLAGS} $^ -o $@
 
 tags: ${SRCS} ${HDRS}

+ 65 - 0
src/sdl3.c

@@ -0,0 +1,65 @@
+#include <stdbool.h>
+
+
+#include <SDL3/SDL.h>
+
+
+struct app {
+	int win_w;
+	int win_h;
+	SDL_Window *win;
+	SDL_Renderer *ren;
+	bool running;
+};
+
+int
+main(int argc, char *argv[])
+{
+	struct app app = {0};
+
+	app.win_w = 800;
+	app.win_h = 600;
+	app.running = true;
+
+	SDL_Init(SDL_INIT_VIDEO);
+
+	SDL_CreateWindowAndRenderer("Title", app.win_w, app.win_h, 0, &app.win, &app.ren);
+
+	while ( app.running ) {
+		SDL_Event e;
+
+event_loop:
+		if ( ! SDL_PollEvent(&e) ) {
+			goto event_loop_out;
+		}
+		switch( e.type ) {
+		case SDL_EVENT_QUIT: 
+			app.running = false;
+			goto event_loop_out;
+		}
+		goto event_loop;
+event_loop_out:	;
+		
+		SDL_SetRenderDrawColor(app.ren, 0xFF, 0, 0, 0xFF);
+		SDL_RenderClear(app.ren);
+
+		{
+			SDL_FRect rect = {0, 0, 10, 10};
+			rect.x = (((float)app.win_w) - rect.w) / 2.0f;
+			rect.y = (((float)app.win_h) - rect.h) / 2.0f;
+
+			SDL_SetRenderDrawColor(app.ren, 0x00, 0xFF, 0, 0xFF);
+			SDL_RenderFillRect(app.ren, &rect);
+		}
+
+
+		SDL_RenderPresent(app.ren);
+	}
+
+	SDL_DestroyWindow(app.win);
+	SDL_DestroyRenderer(app.ren);
+
+	SDL_Quit();
+	(void) argc; (void) argv;
+	return 0;
+}