aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgonzo <gonzo@toniatuh.com>2024-11-18 21:30:06 +0100
committergonzo <gonzo@toniatuh.com>2024-11-18 21:59:12 +0100
commit4aefdc362813c5fd5dca4f677088d374058fa4b9 (patch)
treeb715428fb94587a6ff7653d275dce7bb0b9a620d
parentc24e9c8679d43ad5960864b1e7c746b2dcf53562 (diff)
downloadgambit-raylib-4aefdc362813c5fd5dca4f677088d374058fa4b9.tar.gz
added render textures and some texture functionality
-rw-r--r--drawing.scm4
-rw-r--r--raylib.sld13
-rw-r--r--structs.scm21
-rw-r--r--texture.scm29
4 files changed, 67 insertions, 0 deletions
diff --git a/drawing.scm b/drawing.scm
index 41a4e26..2de227a 100644
--- a/drawing.scm
+++ b/drawing.scm
@@ -31,9 +31,13 @@
;; Begin drawing to render texture
;; void BeginTextureMode(RenderTexture2D target);
+(define begin-texture-mode
+ (c-lambda (render-texture) void "BeginTextureMode"))
;; Ends drawing to render texture
;; void EndTextureMode(void);
+(define end-texture-mode
+ (c-lambda () void "EndTextureMode"))
;; Begin custom shader drawing
;; void BeginShaderMode(Shader shader);
diff --git a/raylib.sld b/raylib.sld
index 44e78db..21746c7 100644
--- a/raylib.sld
+++ b/raylib.sld
@@ -2,6 +2,7 @@
(export init-window close-window)
(export with-drawing begin-drawing end-drawing)
(export in-scissor-mode begin-scissor-mode end-scissor-mode)
+ (export in-texture-mode begin-texture-mode end-texture-mode)
(import (gambit))
(pkg-config "gl" "raylib")
@@ -25,6 +26,10 @@
;;; rshapes module
;;; --------------
(include "shapes.scm")
+ ;;; ---------------
+ ;;; textures module
+ ;;; ---------------
+ (include "texture.scm")
(begin
(c-declare "#include \"raylib.h\"")
@@ -62,6 +67,14 @@
(lambda () (begin body ...))
end-drawing))))
+ (define-syntax in-texture-mode
+ (syntax-rules ()
+ ((with-drawing-to-texture (texture) body ...)
+ (dynamic-wind
+ (lambda () (begin-texture-mode texture))
+ (lambda () (begin body ...))
+ end-texture-mode))))
+
;;; less hygienic drawing context for R5RS
;; (define-macro (with-drawing . body)
;; `(dynamic-wind
diff --git a/structs.scm b/structs.scm
index 44ed30b..76cc6ca 100644
--- a/structs.scm
+++ b/structs.scm
@@ -123,3 +123,24 @@
(c-lambda (rec float) void "___arg1.width = ___arg2;"))
(define rec-height-set!
(c-lambda (rec float) void "___arg1.height = ___arg2;"))
+
+
+;; texture, 5 components, id32w32h32mipmaps32format32 (160bit)
+(c-define-type texture (struct "Texture"))
+
+;; RenderTexture, 3 components: uint id, Texture tex, Texture depth
+(c-define-type render-texture (struct "RenderTexture"))
+
+(define render-texture-id
+ (c-lambda (render-texture) int "___return(___arg1.id);"))
+(define render-texture-tex
+ (c-lambda (render-texture) texture "___return(___arg1.texture);"))
+(define render-texture-depth
+ (c-lambda (render-texture) texture "___return(___arg1.depth);"))
+
+(define load-render-texture
+ (c-lambda (int int) render-texture "LoadRenderTexture"))
+(define render-texture-ready?
+ (c-lambda (render-texture) bool "IsRenderTextureReady"))
+(define unload-render-texture
+ (c-lambda (render-texture) void "UnloadRenderTexture"))
diff --git a/texture.scm b/texture.scm
new file mode 100644
index 0000000..0de9ac3
--- /dev/null
+++ b/texture.scm
@@ -0,0 +1,29 @@
+;;; -------------------------
+;;; Texture drawing functions
+;;; -------------------------
+
+;; Draw a Texture2D
+;; void DrawTexture(Texture2D texture, int posX, int posY, Color tint)
+(define draw-texture
+ (c-lambda (texture int int color) void "DrawTexture"))
+
+;; Draw a Texture2D with position defined as Vector2
+;; void DrawTextureV(Texture2D texture, Vector2 position, Color tint)
+(define draw-texture-V
+ (c-lambda (texture vec2 color) void "DrawTextureV"))
+
+;; Draw a Texture2D with extended parameters
+;; void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint)
+
+;; Draw a part of a texture defined by a rectangle
+;; void DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint)
+(define draw-texture-rec
+ (c-lambda (texture rec vec2 color) void "DrawTextureRec"))
+
+;; Draw a part of a texture defined by a rectangle with 'pro' parameters
+;; void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint)
+(define draw-texture-pro
+ (c-lambda (texture rec rec vec2 float color) void "DrawTexturePro"))
+
+;; Draws a texture (or part of it) that stretches or shrinks nicely
+;; void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint)