NAME=lrts
TEST_NAME=test$(NAME)
-DBGCFLAGS=-g -fsanitize=address
-DBGLDFLAGS=-fsanitize=address
+DBGCFLAGS=-g
+DBGLDFLAGS=
CFLAGS=-Wall -pedantic $(DBGCFLAGS) -std=c89
LIBS=-lSDL3
LDFLAGS=$(DBGLDFLAGS) $(LIBS)
$(CC) -o $(NAME) main.o $(OBJS) $(CFLAGS) $(LDFLAGS)
test: test.o $(OBJS)
- $(CC) -o $(TEST_NAME) test.o $(OBJS) $(CFLAGS) $(LDFLAGS)
+ $(CC) -o $(TEST_NAME) test.o $(OBJS) $(CFLAGS) $(LDFLAGS) -fsanitize=address
.PHONY: clean
clean:
p_render_init();
+ while (!lrts_cfg()->exit) {
+ p_poll_events();
+ }
+
p_renderer_finish();
p_io_finish();
*/
int p_renderer_finish(void);
+/**
+ * polls input events
+ * should be called once a frame
+ */
+int p_poll_events();
+
#endif
}
}
+ cfg->name = argv[0];
+
cfg->argc = argc - optind;
cfg->argv = argv + optind;
}
#include "../p_platform.h"
#include <SDL3/SDL.h>
+#include "p_window.h"
+#include "../u_defs.h"
+
+#include "p_window.c"
int p_render_init(void) {
if (!SDL_Init(SDL_INIT_VIDEO)) {
SDL_GetError());
exit(-1);
}
+
+ p_main_window = SDL_CreateWindow(lrts_cfg()->name, 640, 640, 0);
+ if (p_main_window == LRTS_NULL) {
+ u_fprintf(u_stderr, "Failed to create window: %s\n", SDL_GetError());
+ exit(-1);
+ }
+
return 0;
}
int p_renderer_finish(void) {
+ SDL_DestroyWindow(p_main_window);
+ SDL_Quit();
return 0;
}
--- /dev/null
+SDL_Window *p_main_window;
+
+#include "../u_defs.h"
+
+int p_poll_events() {
+ SDL_Event e;
+ while (SDL_PollEvent(&e)) {
+ if (e.type == SDL_EVENT_QUIT) {
+ lrts_cfg()->exit = LRTS_TRUE;
+ }
+ }
+ return 0;
+}
--- /dev/null
+#ifndef P_WINDOW_H__
+#define P_WINDOW_H__
+
+#include <SDL3/SDL.h>
+
+extern SDL_Window *p_main_window;
+
+#endif
*
*/
-
/* args without value */
#define LRTS_OPTS "hvV"
* generic typedefs
*/
+
+typedef unsigned char u8;
+typedef char i8;
+typedef unsigned short u16;
+typedef short i16;
+typedef unsigned int u32;
+typedef int i32;
+
typedef unsigned char lrts_bool;
#define LRTS_TRUE 1
#define LRTS_FALSE 0
struct lrts_config {
lrts_bool verbose;
+ i8 exit;
+
+ const char *name;
+
char **argv;
int argc;
};
-typedef unsigned char u8;
-typedef char i8;
-typedef unsigned short u16;
-typedef short i16;
-typedef unsigned int u32;
-typedef int i32;
struct lrts_config* lrts_cfg();
void lrts_help(int argc, char **argv);
void lrts_getopt(int argc, char **argv, struct lrts_config *cfg);
int lrts_main(int argc, char **argv);
+#define U_RENDER_W 640
+#define U_RENDER_H 640
+
#endif