commit b4bfab4cd6a2beb405be1c51352bc184ead798ec
Author: Samdal <samdal@protonmail.com>
Date: Thu, 26 Aug 2021 22:30:59 +0200
anders tale room editor initial commit
Diffstat:
10 files changed, 118 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1 @@
+bin/*
diff --git a/.gitmodules b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "src/hs"]
+ path = src/hs
+ url = git@github.com:Samdal/hs.git
diff --git a/Makefile b/Makefile
@@ -0,0 +1,18 @@
+CFLAGS = -std=gnu99 -O0 -g3 -pthread
+
+LDFLAGS = -ldl -lX11 -lXi -lm
+
+build: src/main.c
+ gcc -o bin/app $(CFLAGS) src/*.c $(LDFLAGS)
+
+linux-win: src/main.c
+ x86_64-w64-mingw32-gcc -o bin/app -Os -pthread src/*.c -static -lkernel32 -luser32 -lshell32 -lgdi32 -lwinmm -lopengl32
+
+.PHONY: run clean
+
+run: build
+ ./bin/app
+
+clean:
+ rm -rf bin/
+ mkdir bin/
diff --git a/assets/base_tiles.png b/assets/base_tiles.png
Binary files differ.
diff --git a/assets/chad.jpg b/assets/chad.jpg
Binary files differ.
diff --git a/assets/p1.png b/assets/p1.png
Binary files differ.
diff --git a/assets/roll-safe.png b/assets/roll-safe.png
Binary files differ.
diff --git a/src/hs b/src/hs
@@ -0,0 +1 @@
+Subproject commit 9e77179681afdec5ce799e48cdcfd6ec00e20c4b
diff --git a/src/main.c b/src/main.c
@@ -0,0 +1,87 @@
+#define HS_IMPL
+#define HS_NUKLEAR
+#include "hs/hs_graphics.h"
+
+hs_game_data gd = {
+ .width = 960,
+ .height = 540
+};
+
+#define MAX_VERTEX_BUFFER 512 * 1024
+#define MAX_ELEMENT_BUFFER 128 * 1024
+
+struct nk_context *ctx;
+struct nk_colorf bg;
+struct nk_glfw glfw = {0};
+
+static inline void
+init()
+{
+ hs_init(&gd, "Anders tale room editor", NULL, 0);
+ bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
+
+ ctx = nk_glfw3_init(&glfw, gd.window, NK_GLFW3_INSTALL_CALLBACKS);
+ /* Load Fonts: if none of these are loaded a default font will be used */
+ /* Load Cursor: if you uncomment cursor loading please hide the cursor */
+ {
+ struct nk_font_atlas *atlas;
+ nk_glfw3_font_stash_begin(&glfw, &atlas);
+ nk_glfw3_font_stash_end(&glfw);
+ }
+}
+
+static inline void
+loop()
+{
+ if (nk_begin(ctx, "Test", nk_rect(0, 0, 230, 250), 0))
+ {
+ enum {EASY, HARD};
+ static int op = EASY;
+
+ nk_layout_row_static(ctx, 30, 80, 1);
+ if (nk_button_label(ctx, "button"))
+ fprintf(stdout, "button pressed\n");
+
+ nk_layout_row_dynamic(ctx, 30, 2);
+ if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
+ if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
+
+ nk_layout_row_dynamic(ctx, 20, 1);
+ nk_label(ctx, "background:", NK_TEXT_LEFT);
+ nk_layout_row_dynamic(ctx, 25, 1);
+ if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) {
+ nk_layout_row_dynamic(ctx, 120, 1);
+ bg = nk_color_picker(ctx, bg, NK_RGBA);
+ nk_layout_row_dynamic(ctx, 25, 1);
+ bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
+ bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
+ bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
+ bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
+ nk_combo_end(ctx);
+ }
+ } nk_end(ctx);
+
+ /* Draw */
+ glfwGetWindowSize(gd.window, (int*)&gd.width, (int*)&gd.height);
+ glViewport(0, 0, gd.width, gd.height);
+
+ hs_clear(bg.r, bg.g, bg.b, bg.a, 0);
+
+ /* IMPORTANT: `nk_glfw_render` modifies some global OpenGL state
+ * with blending, scissor, face culling, depth test and viewport and
+ * defaults everything back into a default state.
+ * Make sure to either a.) save and restore or b.) reset your own state after
+ * rendering the UI. */
+ nk_glfw3_render(&glfw, NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
+}
+
+int
+main()
+{
+ init();
+ hs_loop(gd, nk_glfw3_new_frame(&glfw); loop());
+
+ nk_glfw3_shutdown(&glfw);
+ glfwTerminate();
+ return 0;
+}
diff --git a/todo.org b/todo.org
@@ -0,0 +1,8 @@
+#+AUTHOR: Halvard Samdal
+
+* Options
+** Change between upscale and native resolution
+having upscale makes stuff align pixel perfectly, which makes stuff *not* smooth
+but the performance gain is so large that the option should definetly be there
+
+You could also possibly combine them to make the background upscaled (and translated) and entities native res