summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkkard2 <[email protected]>2025-09-06 15:59:51 +0200
committerkkard2 <[email protected]>2025-09-06 15:59:51 +0200
commitc451018c17ce4953a7011fce6cafa55e362e0005 (patch)
treec2140b4e8a68ef0607f18d5c868698ae8e1e97d4
parentee158180231bafb2d41bd1c6aa5de545556faed8 (diff)
rainbow
-rw-r--r--examples/rainbow.c25
-rw-r--r--platform_win32.c23
-rw-r--r--run.bat1
-rw-r--r--sponge.h1
4 files changed, 48 insertions, 2 deletions
diff --git a/examples/rainbow.c b/examples/rainbow.c
new file mode 100644
index 0000000..33cbb2d
--- /dev/null
+++ b/examples/rainbow.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <math.h>
+
+
+
+#include "../sponge.h"
+
+#define PI ((float)3.14159265358979323846)
+#define SPEED (2.0f / 360.0f * 2 * PI)
+static float angle = 0.0f;
+
+void draw_frame(sponge_Texture c) {
+ angle += SPEED;
+
+ float rf = (sinf(angle) + 1.0f) * 255.0f / 2.0f;
+ float gf = (sinf(angle + (PI * 2.0f / 3.0f)) + 1.0f) * 255.0f / 2.0f;
+ float bf = (sinf(angle + (PI * 4.0f / 3.0f)) + 1.0f) * 255.0f / 2.0f;
+
+ int r = (((int)rf) & 0xFF) << 16;
+ int g = (((int)gf) & 0xFF) << 8;
+ int b = (((int)bf) & 0xFF) << 0;
+
+ uint32_t color = 0xFF000000 | r | g | b;
+ sponge_clear(c, color);
+}
diff --git a/platform_win32.c b/platform_win32.c
index 1d7ff57..620b8a2 100644
--- a/platform_win32.c
+++ b/platform_win32.c
@@ -1,13 +1,16 @@
#define UNICODE
#include <windows.h>
#include <assert.h>
+#include <stdio.h>
+#include <io.h>
+
+#include <fcntl.h>
#define SPONGE_IMPLEMENTATION
#include "sponge.h"
#include "example.h"
-// TODO(kard): ofc some resizing stuff
#define DEFAULT_WIDTH 256
#define DEFAULT_HEIGHT 256
@@ -36,6 +39,22 @@ int update_canvas(sponge_Texture *canvas, uint32_t new_width, uint32_t new_heigh
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
+ return 1;
+}
+
+// TODO(kard): MSVC complains about freopen (should be freopen_s apparently)
+void redirect_io_to_console() {
+ AllocConsole();
+ FILE *fp;
+
+ fp = freopen("CONOUT$", "w", stdout);
+ setvbuf(stdout, NULL, _IONBF, 0);
+
+ fp = freopen("CONOUT$", "w", stderr);
+ setvbuf(stderr, NULL, _IONBF, 0);
+
+ fp = freopen("CONIN$", "r", stdin);
+ setvbuf(stdin, NULL, _IONBF, 0);
}
LRESULT WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
@@ -61,6 +80,8 @@ int WinMain(
LPSTR lpCmdLine,
int nShowCmd
) {
+ redirect_io_to_console();
+
const wchar_t CLASS_NAME[] = L"sponge";
WNDCLASS wc = { 0 };
diff --git a/run.bat b/run.bat
index 913a542..0eb177d 100644
--- a/run.bat
+++ b/run.bat
@@ -1,3 +1,4 @@
del out.exe
+del *.obj
cl platform_win32.c "examples\%1" user32.lib gdi32.lib /W3 /Fe:out.exe
out.exe
diff --git a/sponge.h b/sponge.h
index 6255236..2978e0e 100644
--- a/sponge.h
+++ b/sponge.h
@@ -10,7 +10,6 @@ typedef struct {
void sponge_clear(sponge_Texture c, uint32_t color);
void sponge_draw_rect(sponge_Texture c, uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t color);
-void sponge_draw_texture(sponge_Texture c, uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, sponge_Texture texture);
// TODO(kard): prefix stripping