AtlatestRepositorysigil-studio

sigil-studio / tree / testtest-draw-texture.sgl

1;;; test-draw-texture.sgl - Test texture rendering
2;;;
3;;; Opens a window and draws a test image to the screen.
4
5(import (sigil core)
6 (sigil app)
7 (sigil graphics))
8
9(display "Loading test image...\n")
11;; Load image (we'll load it before the app starts, then create texture in init)
12(define test-image-path "test/test-image.png")
13(define img (load-image test-image-path))
15(if (not img)
16 (begin
17 (display "ERROR: Could not load test image at: ")
18 (display test-image-path)
19 (display "\n")
20 (display "Please ensure test/test-image.png exists.\n")
21 1)
22 (begin
23 (display "Image loaded: ")
24 (display (image-width img))
25 (display "x")
26 (display (image-height img))
27 (display "\n")
29 ;; Variables to hold texture (will be set in init)
30 (define tex #f)
31 (define angle 0.0)
33 ;; Init callback - create GPU texture
34 (define (on-init)
35 (display "Initializing texture...\n")
36 (set! tex (load-texture img))
37 (if tex
38 (begin
39 (display "Texture created successfully!\n")
40 ;; Free CPU image data since we have GPU texture now
41 (image-free! img))
42 (display "ERROR: Failed to create texture!\n")))
44 ;; Frame callback - render
45 (define (on-frame)
46 (begin-frame)
47 (clear-screen 0.2 0.2 0.3) ;; Dark blue-gray background
48 (when tex
49 ;; Draw texture at fixed position (100, 100)
50 (draw-texture tex 100 100))
51 (end-frame))
53 ;; Cleanup callback
54 (define (on-cleanup)
55 (display "Cleaning up...\n"))
57 ;; Run the app
58 (display "Starting app...\n")
59 (app-run on-init
60 on-frame
61 on-cleanup
62 "Texture Test"
63 800 600)))