Skip to content

Commit

Permalink
Add compile_flags, merge engine code into working emscripten build
Browse files Browse the repository at this point in the history
  • Loading branch information
alidiusk committed Sep 15, 2023
1 parent 54801c2 commit a215205
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
29 changes: 21 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
TARGET=vestige

CC=clang
TARGET?=native

BUILD_DIR:=./build
SRC_DIRS:=./src
Expand All @@ -12,16 +10,31 @@ DEPS:=$(OBJS:.o=.d)
INC_DIRS:=./include $(shell find $(SRC_DIRS) -type d)
INC_FLAGS:=$(addprefix -I,$(INC_DIRS))

CFLAGS:=$(INC_FLAGS) -std=c17 -Wall -Wpedantic -Werror -O2 -MMD -MP

LDFLAGS:=-lglfw -lGL
CFLAGS:=$(INC_FLAGS) -std=c17 -Wall -Wpedantic -Werror -O2 -MMD -MP -g

ifeq ($(TARGET),web)
CC:=emcc
LDFLAGS:=$(LDFLAGS) -O2 --emrun -s USE_GLFW=3 -s FULL_ES3
TARGET_EXEC=vestige.html
else
CC:=clang
TARGET_EXEC=vestige
endif

.PHONY: clean

all: $(BUILD_DIR)/$(TARGET)
all: $(BUILD_DIR)/$(TARGET_EXEC)

run: $(BUILD_DIR)/$(TARGET_EXEC)
ifeq ($(TARGET),web)
emrun $(BUILD_DIR)/$(TARGET_EXEC)
else
./$(BUILD_DIR)/$(TARGET_EXEC)
endif

$(BUILD_DIR)/$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o $@

$(BUILD_DIR)/%.c.o: %.c
mkdir -p $(dir $@)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Vestige Engine

## Building

### Dependencies

* [Emscripten=3.1.45](https://emscripten.org/docs/getting_started/downloads.html#sdk-download-and-install)
6 changes: 6 additions & 0 deletions compile_flags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-std=c17
-Wall
-Wpedantic
-Werror
-I./src
-I./include
37 changes: 29 additions & 8 deletions src/vestige.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
#include <stdio.h>

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#include <GLFW/glfw3.h>

#include "window.h"
#include "engine.h"
#include <stdio.h>

GLFWwindow* APP = NULL;

static void main_loop(void) {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(APP);
glfwPollEvents();
}

int main(int argc, char* argv[]) {
engine_start();

if (!glfwInit()) {
printf("Failed to initialize GLFW!\n");
return 1;
}

GLFWwindow* app = glfwCreateWindow(640, 480, "Hello, Window!", NULL, NULL);
if (!app) {
APP = glfwCreateWindow(640, 480, "Hello, Window!", NULL, NULL);
if (!APP) {
glfwTerminate();
return 1;
}

glfwMakeContextCurrent(app);
glfwMakeContextCurrent(APP);

glfwSwapInterval(1);

glClearColor(255, 0, 0, 255);

while (!glfwWindowShouldClose(app)) {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(app);
glfwPollEvents();
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(main_loop, 0, 1);
#else
while (!glfwWindowShouldClose(APP)) {
main_loop();
}
#endif

glfwTerminate();

Expand Down

0 comments on commit a215205

Please sign in to comment.