summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio/audio.cpp33
-rw-r--r--src/audio/audio.h4
-rw-r--r--src/gpu/gpu.cpp5
-rw-r--r--src/gpu/gpu.h6
-rw-r--r--src/gpu/shader.wgsl14
-rw-r--r--src/main.cpp20
-rw-r--r--src/platform.cpp26
-rw-r--r--src/platform.h8
-rw-r--r--src/util/math.h2
9 files changed, 118 insertions, 0 deletions
diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp
new file mode 100644
index 0000000..9e778f1
--- /dev/null
+++ b/src/audio/audio.cpp
@@ -0,0 +1,33 @@
+#define MINIAUDIO_IMPLEMENTATION
+#include "miniaudio.h"
+#include <math.h>
+
+static ma_device device;
+static float phase = 0.0f;
+
+static void audio_callback(ma_device*, void* output, const void*, ma_uint32 frames) {
+ int16_t* out = (int16_t*)output;
+ const float freq = 440.0f;
+ const float sr = 32000.0f;
+
+ for (ma_uint32 i = 0; i < frames; i++) {
+ float s = sinf(phase) * 0.2f;
+ phase += 2.0f * 3.14159265f * freq / sr;
+ if (phase > 2.0f * 3.14159265f) phase -= 2.0f * 3.14159265f;
+ out[i] = (int16_t)(s * 32767.0f);
+ }
+}
+
+void audio_init() {
+ ma_device_config cfg = ma_device_config_init(ma_device_type_playback);
+ cfg.playback.format = ma_format_s16;
+ cfg.playback.channels = 1;
+ cfg.sampleRate = 32000;
+ cfg.dataCallback = audio_callback;
+
+ ma_device_init(nullptr, &cfg, &device);
+ ma_device_start(&device);
+}
+
+void audio_update() {}
+void audio_shutdown() { ma_device_uninit(&device); }
diff --git a/src/audio/audio.h b/src/audio/audio.h
new file mode 100644
index 0000000..b3dde7f
--- /dev/null
+++ b/src/audio/audio.h
@@ -0,0 +1,4 @@
+#pragma once
+void audio_init();
+void audio_update();
+void audio_shutdown();
diff --git a/src/gpu/gpu.cpp b/src/gpu/gpu.cpp
new file mode 100644
index 0000000..4e48887
--- /dev/null
+++ b/src/gpu/gpu.cpp
@@ -0,0 +1,5 @@
+#include "gpu.h"
+
+void gpu_init(GLFWwindow*) {}
+void gpu_draw() {}
+void gpu_shutdown() {}
diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h
new file mode 100644
index 0000000..02204af
--- /dev/null
+++ b/src/gpu/gpu.h
@@ -0,0 +1,6 @@
+#pragma once
+struct GLFWwindow;
+
+void gpu_init(GLFWwindow* window);
+void gpu_draw();
+void gpu_shutdown();
diff --git a/src/gpu/shader.wgsl b/src/gpu/shader.wgsl
new file mode 100644
index 0000000..4e0ec11
--- /dev/null
+++ b/src/gpu/shader.wgsl
@@ -0,0 +1,14 @@
+@vertex
+fn vs_main(@builtin(vertex_index) i: u32) -> @builtin(position) vec4<f32> {
+ var pos = array<vec2<f32>, 3>(
+ vec2<f32>(-1.0, -1.0),
+ vec2<f32>( 3.0, -1.0),
+ vec2<f32>(-1.0, 3.0)
+ );
+ return vec4<f32>(pos[i], 0.0, 1.0);
+}
+
+@fragment
+fn fs_main() -> @location(0) vec4<f32> {
+ return vec4<f32>(0.0, 0.0, 0.0, 1.0);
+}
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..3b61e1e
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,20 @@
+#include "platform.h"
+#include "gpu/gpu.h"
+#include "audio/audio.h"
+
+int main() {
+ platform_init();
+ gpu_init(platform_get_window());
+ audio_init();
+
+ while (!platform_should_close()) {
+ platform_poll();
+ gpu_draw();
+ audio_update();
+ }
+
+ audio_shutdown();
+ gpu_shutdown();
+ platform_shutdown();
+ return 0;
+}
diff --git a/src/platform.cpp b/src/platform.cpp
new file mode 100644
index 0000000..adb41d2
--- /dev/null
+++ b/src/platform.cpp
@@ -0,0 +1,26 @@
+#include "platform.h"
+#include <GLFW/glfw3.h>
+
+static GLFWwindow* window = nullptr;
+
+void platform_init() {
+ glfwInit();
+ window = glfwCreateWindow(1280, 720, "demo64k", nullptr, nullptr);
+}
+
+void platform_shutdown() {
+ glfwDestroyWindow(window);
+ glfwTerminate();
+}
+
+void platform_poll() {
+ glfwPollEvents();
+}
+
+bool platform_should_close() {
+ return glfwWindowShouldClose(window);
+}
+
+GLFWwindow* platform_get_window() {
+ return window;
+}
diff --git a/src/platform.h b/src/platform.h
new file mode 100644
index 0000000..0ebeb59
--- /dev/null
+++ b/src/platform.h
@@ -0,0 +1,8 @@
+#pragma once
+struct GLFWwindow;
+
+void platform_init();
+void platform_shutdown();
+void platform_poll();
+bool platform_should_close();
+GLFWwindow* platform_get_window();
diff --git a/src/util/math.h b/src/util/math.h
new file mode 100644
index 0000000..084dfd1
--- /dev/null
+++ b/src/util/math.h
@@ -0,0 +1,2 @@
+#pragma once
+#define PI 3.14159265f