summary refs log tree commit diff
diff options
context:
space:
mode:
authoriurii plugatarov <[email protected]>2024-08-16 10:43:03 +0200
committeriurii plugatarov <[email protected]>2024-08-16 10:43:03 +0200
commit586369b63cdede5fa09f5f9ed73abde6c8264425 (patch)
tree41e47e4dedfa9abebd3eacca4f035c38dcce62d6
downloadfunhalla-586369b63cdede5fa09f5f9ed73abde6c8264425.tar.gz
start
Diffstat (limited to '')
-rw-r--r--.gitignore1
-rw-r--r--Makefile29
-rw-r--r--src/main.odin60
3 files changed, 90 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1fcb152
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+out
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..5f97b46
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,29 @@
+# Define the compiler and flags
+ODIN = odin
+SRC_DIR = src
+OUT_DIR_DEBUG = out/debug
+OUT_DIR_RELEASE = out/release
+PROGRAM_NAME = funhalla
+
+# Define the build targets
+all: debug release
+
+debug: $(OUT_DIR_DEBUG)/$(PROGRAM_NAME)
+
+release: $(OUT_DIR_RELEASE)/$(PROGRAM_NAME)
+
+# Rule for building the debug version
+$(OUT_DIR_DEBUG)/$(PROGRAM_NAME): $(SRC_DIR)/*.odin
+	@mkdir -p $(OUT_DIR_DEBUG)
+	$(ODIN) build $(SRC_DIR) -out:$(OUT_DIR_DEBUG)/$(PROGRAM_NAME) --debug
+
+# Rule for building the release version
+$(OUT_DIR_RELEASE)/$(PROGRAM_NAME): $(SRC_DIR)/*.odin
+	@mkdir -p $(OUT_DIR_RELEASE)
+	$(ODIN) build $(SRC_DIR) -out:$(OUT_DIR_RELEASE)/$(PROGRAM_NAME)
+
+# Clean up build artifacts
+clean:
+	rm -rf $(OUT_DIR_DEBUG) $(OUT_DIR_RELEASE)
+
+.PHONY: all debug release clean
diff --git a/src/main.odin b/src/main.odin
new file mode 100644
index 0000000..75bd82e
--- /dev/null
+++ b/src/main.odin
@@ -0,0 +1,60 @@
+package main
+import gl "vendor:OpenGL"
+import "vendor:glfw"
+
+import "base:intrinsics"
+import "base:runtime"
+import "core:fmt"
+
+GL_MAJOR_VERSION :: 3
+GL_MINOR_VERSION :: 3
+
+framebuffer_size_callback :: proc "cdecl" (window: glfw.WindowHandle, width, height: i32) {
+	gl.Viewport(0, 0, width, height)
+}
+
+process_input :: proc(window: ^glfw.WindowHandle) {
+	if glfw.GetKey(window^, glfw.KEY_ESCAPE) == glfw.PRESS {
+		glfw.SetWindowShouldClose(window^, true)
+	}
+}
+
+
+main :: proc() {
+	glfw.Init()
+
+	glfw.WindowHint(glfw.CONTEXT_VERSION_MAJOR, GL_MAJOR_VERSION)
+	glfw.WindowHint(glfw.CONTEXT_VERSION_MINOR, GL_MINOR_VERSION)
+	glfw.WindowHint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
+
+	when ODIN_OS == .Darwin {
+		glfw.WindowHint(glfw.OPENGL_FORWARD_COMPAT, gl.TRUE)
+	}
+
+	window := glfw.CreateWindow(800, 600, "Funhalla Engine", nil, nil)
+
+	defer glfw.Terminate()
+	defer glfw.DestroyWindow(window)
+
+
+	if window == nil {
+		fmt.eprintln("Failed to create GLFW window")
+		return
+	}
+
+	glfw.MakeContextCurrent(window)
+	gl.load_up_to(GL_MAJOR_VERSION, GL_MINOR_VERSION, glfw.gl_set_proc_address)
+
+	gl.Viewport(0, 0, 800, 600)
+	glfw.SetFramebufferSizeCallback(window, framebuffer_size_callback)
+
+	for !glfw.WindowShouldClose(window) {
+		process_input(&window)
+
+		gl.ClearColor(0.2, 0.3, 0.3, 1.0)
+		gl.Clear(gl.COLOR_BUFFER_BIT)
+
+		glfw.SwapBuffers(window)
+		glfw.PollEvents()
+	}
+}