From 9422d9d0b99332d73b44968f4779fed7058d9f16 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Sat, 7 Sep 2024 12:17:41 -0400 Subject: [PATCH] Use Makefile --- .gitignore | 4 ++++ Makefile | 26 ++++++++++++++++++++++++++ demo/atlas.inl => atlas.inl | 0 demo/build.sh | 16 ---------------- keys.c | 35 +++++++++++++++++++++++++++++++++++ demo/main.c => main.c | 0 demo/renderer.c => renderer.c | 8 +++++++- demo/renderer.h => renderer.h | 0 8 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile rename demo/atlas.inl => atlas.inl (100%) delete mode 100755 demo/build.sh create mode 100644 keys.c rename demo/main.c => main.c (100%) rename demo/renderer.c => renderer.c (93%) rename demo/renderer.h => renderer.h (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..029cf7f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.d +main +tags +*.o diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..caff817 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +CFLAGS ?= -Wall -Wextra -pedantic -std=c99 +LDLIBS = -lm +SOURCES := main.c renderer.c microui.c +OBJECTS := $(SOURCES:%.c=%.o) +DEPS := $(SOURCES:%.c=%.d) +CFLAGS += -MMD + +main: $(OBJECTS) + +-include $(DEPS) + +ifeq ($(OS),Windows_NT) + LDLIBS += -lgdi32 +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Darwin) + LDLIBS += -framework Cocoa + else + LDLIBS += -lX11 + endif +endif + +clean: + rm -f main $(OBJECTS) $(DEPS) + +.PHONY: clean diff --git a/demo/atlas.inl b/atlas.inl similarity index 100% rename from demo/atlas.inl rename to atlas.inl diff --git a/demo/build.sh b/demo/build.sh deleted file mode 100755 index db686f9..0000000 --- a/demo/build.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -OS_NAME=`uname -o 2>/dev/null || uname -s` - -if [ $OS_NAME == "Msys" ]; then - GLFLAG="-lgdi32" -elif [ $OS_NAME == "Darwin" ]; then - GLFLAG="-framework Cocoa" -else - GLFLAG="-lX11" -fi - -CFLAGS="-I../ -Wall -std=c11 -pedantic $GLFLAG -lm -O2 -g" - -gcc main.c renderer.c ../microui.c $CFLAGS - diff --git a/keys.c b/keys.c new file mode 100644 index 0000000..e2dc84d --- /dev/null +++ b/keys.c @@ -0,0 +1,35 @@ +#include "fenster.h" +int main() { + struct fenster window = {.title = "A window", .width = 800, .height = 600}; + window.buf = malloc(window.width * window.height * sizeof(*window.buf)); + memset(window.buf, 0, window.width * window.height * sizeof(*window.buf)); + + fenster_open(&window); + + for (;;) { + int key_pressed = 0; + if (window.keys[0x1b]) { + break; + } + for (int i = 0; i < 256; i++) { + if (window.keys[i]) { + printf("Key '%c' is pressed\n", i); + key_pressed = 1; + } + fenster_loop(&window); + } + // if (key_pressed) { + // if (window.mod & 1) { + // printf("ctrl\n"); + // } + // if (window.mod & 2) { + // printf("shift\n"); + // } + // if (window.mod & 4) { + // printf("alt\n"); + // } + // } + } + + fenster_close(&window); +} diff --git a/demo/main.c b/main.c similarity index 100% rename from demo/main.c rename to main.c diff --git a/demo/renderer.c b/renderer.c similarity index 93% rename from demo/renderer.c rename to renderer.c index 4fccb12..8454650 100644 --- a/demo/renderer.c +++ b/renderer.c @@ -86,8 +86,14 @@ static void flush(void) { assert(within_rect(*src, x, y)); assert(within_rect(clip_rect, x, y)); // read color from texture + mu_Color existing_color = color_buf[i]; + // mu_Color existing_color = mu_color_argb(fenster_pixel(&window, x, y)); byte tc = texture_color(tex, x-src->x, y-src->y); - fenster_pixel(&window, x, y) |= greyscale(tc); + existing_color.r *= tc/255.0; + existing_color.g *= tc/255.0; + existing_color.b *= tc/255.0; + // mu_Color result = blend_pixel(existing_color, mu_color(0, 0, 0, tc)); + fenster_pixel(&window, x, y) = r_color(existing_color); } } } else { diff --git a/demo/renderer.h b/renderer.h similarity index 100% rename from demo/renderer.h rename to renderer.h -- 2.11.4.GIT