From b331907fa07d9b183f48b65328d8d51943572a56 Mon Sep 17 00:00:00 2001 From: mehbark Date: Fri, 22 Dec 2023 00:40:33 -0500 Subject: [PATCH] BITMAP. BLITTED --- flake.lock | 10 ++++----- main.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.scm | 28 ++++++++++++++++++++--- 3 files changed, 96 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index a2249b1..3a30164 100644 --- a/flake.lock +++ b/flake.lock @@ -16,12 +16,12 @@ }, "nixpkgs": { "locked": { - "lastModified": 1702780907, - "narHash": "sha256-blbrBBXjjZt6OKTcYX1jpe9SRof2P9ZYWPzq22tzXAA=", - "rev": "1e2e384c5b7c50dbf8e9c441a9e58d85f408b01f", - "revCount": 553366, + "lastModified": 1703068421, + "narHash": "sha256-WSw5Faqlw75McIflnl5v7qVD/B3S2sLh+968bpOGrWA=", + "rev": "d65bceaee0fb1e64363f7871bc43dc1c6ecad99f", + "revCount": 553492, "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2311.553366%2Brev-1e2e384c5b7c50dbf8e9c441a9e58d85f408b01f/018c7bfd-11b9-73fc-856e-ffc78346f98e/source.tar.gz" + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2311.553492%2Brev-d65bceaee0fb1e64363f7871bc43dc1c6ecad99f/018c8bd1-00df-7455-9e45-7867e2da314a/source.tar.gz" }, "original": { "type": "tarball", diff --git a/main.c b/main.c index da53a2b..8c0683f 100644 --- a/main.c +++ b/main.c @@ -21,3 +21,69 @@ int main() { return 0; } + +void a(const char* path) { + printf("%s\n", path); + printf("%s\n", path); +} + +Image b(const char* path) { + printf("%s\n", path); + Image img = LoadImage(path); + printf("%s\n", path); + return img; +} + +const char *id(const char* str) { + return str; +} + +FILE* fopen_wrapper(const char* path) { + FILE* file = fopen(path, "rb"); + printf("file = %p and NULL = %p\n", file, NULL); + return file; +} + +void println(const char* str) { + if (str == NULL) { + printf("got a null str :(\n"); + return; + } + printf("%c\n", str[0]); + printf("%c\n", str[1]); + printf("%p\n", str); + printf("%c\n", str[0]); + printf("%c\n", str[1]); + printf("%c\n", str[2]); + printf("%c\n", str[3]); + printf("%c\n", str[4]); + printf("%c\n", str[5]); + printf("%s\n", str); + printf("%s\n", str); +} + +// doesn't work. nice! +Image load_image(const char* path) { + // YES! the string is empty + // but why? + printf("%p: '%s'\n", path, path); + printf("'%c'\n", path[0]); + printf("'%c'\n", path[1]); + printf("'%c'\n", path[2]); + printf("'%c'\n", path[3]); + printf("'%c'\n", path[4]); + return LoadImage(path); +} + +Image load_image2(const char* str) { + // YES! the string is empty + // but why? + printf("%s\n", str); + //printf("%p: '%s'\n", str, str); + /* printf("'%c'\n", str[0]); */ + /* printf("'%c'\n", str[1]); */ + /* printf("'%c'\n", str[2]); */ + /* printf("'%c'\n", str[3]); */ + /* printf("'%c'\n", str[4]); */ + return LoadImage(str); +} diff --git a/main.scm b/main.scm index 9debe0d..0ad9115 100644 --- a/main.scm +++ b/main.scm @@ -95,6 +95,7 @@ ; texture ; shouldn't really need to use these structs, just pass them around +; which is what we could use void* for... oops. (define-ftype Image (struct [data void*] @@ -151,11 +152,32 @@ (set-vector2-y! vec2 y) vec2) +; adapted from https://github.com/Yunoinsky/chez-raylib/blob/main/src/raylib.sls (define load-image - (foreign-procedure #f "LoadImage" (string) (* Image))) + (let ([f (foreign-procedure #f "LoadImage" + (string) + (& Image))]) + (case-lambda + [(file-name) + (let ([ret (make-ftype-pointer + Image + (foreign-alloc (ftype-sizeof Image)))]) + (f ret file-name) + ret)] + [(struct file-name) (f struct file-name) struct]))) (define load-texture - (foreign-procedure #f "LoadTexture" (string) (* Texture2D))) + (let ([f (foreign-procedure #f "LoadTexture" + (string) + (& Texture))]) + (case-lambda + [(file-name) + (let ([ret (make-ftype-pointer + Texture + (foreign-alloc (ftype-sizeof Texture)))]) + (f ret file-name) + ret)] + [(struct file-name) (f struct file-name) struct]))) (define unload-texture (foreign-procedure #f "UnloadTexture" ((& Texture2D)) void)) @@ -225,5 +247,5 @@ (unload-texture skin) (close-window))) -;; (main) +(main)