|
|
@ -61,7 +61,7 @@ |
|
|
|
(SDL_GL_SetAttribute SDL_GL_CONTEXT_MINOR_VERSION 6) |
|
|
|
(SDL_SetHint SDL_HINT_RENDER_VSYNC "1") |
|
|
|
(var window (addr SDL_Window) null) |
|
|
|
(unless (sdl-initialize-for-2d (addr window) "Presentation" 1920 1080) |
|
|
|
(unless (sdl-initialize-for-2d (addr window) "Vector Puppet Show" 1920 1080) |
|
|
|
(vpslog "Failed to initialize SDL\n") |
|
|
|
(return 1)) |
|
|
|
(defer (sdl-shutdown window)) |
|
|
@ -145,6 +145,8 @@ |
|
|
|
;; SVGs |
|
|
|
;; |
|
|
|
(var svg-image-texture (addr SDL_Texture) null) |
|
|
|
(var puppet-image (addr NSVGimage) null) |
|
|
|
(defer (when puppet-image (nsvgDelete puppet-image))) |
|
|
|
(var svg-image-width int 0) |
|
|
|
(var svg-image-height int 0) |
|
|
|
(defer |
|
|
@ -152,36 +154,46 @@ |
|
|
|
(SDL_DestroyTexture svg-image-texture))) |
|
|
|
(scope |
|
|
|
(var filename (addr (const char)) "data/TestPuppet.svg") |
|
|
|
(var image (addr NSVGimage) (nsvgParseFromFile filename "px" 96.0f)) |
|
|
|
(unless image |
|
|
|
(set puppet-image (nsvgParseFromFile filename "px" 96.0f)) |
|
|
|
(unless puppet-image |
|
|
|
(vpslog "Failed to load SVG %s\n" filename) |
|
|
|
(return 1)) |
|
|
|
(defer (nsvgDelete image)) |
|
|
|
(var rasterizer (addr NSVGrasterizer) (nsvgCreateRasterizer)) |
|
|
|
(unless rasterizer |
|
|
|
(vpslog "Failed to create NanoSVG rasterizer\n") |
|
|
|
(return 1)) |
|
|
|
(defer (nsvgDeleteRasterizer rasterizer)) |
|
|
|
(var-cast-to image-buffer (addr (unsigned char)) |
|
|
|
(malloc (* (path image > width) (path image > height) 4))) |
|
|
|
(malloc (* (path puppet-image > width) (path puppet-image > height) 4))) |
|
|
|
(defer (free image-buffer)) |
|
|
|
|
|
|
|
(nsvgRasterize rasterizer image 0 0 1 image-buffer (path image > width) (path image > height) |
|
|
|
(* 4 (path image > width))) |
|
|
|
(each-shape-in-svg-image puppet-image shape |
|
|
|
;; (when (= 0 (strncmp (path shape > id) "Head" (sizeof (path shape > id)))) |
|
|
|
;; (set (path shape > flags) |
|
|
|
;; (bit-xor (path shape > flags) NSVG_FLAGS_VISIBLE))) |
|
|
|
(vpslog "Shape %s\n\tBounds: %.2f %.2f -> %.2f %.2f\n" (path shape > id) |
|
|
|
(at 0 (path shape > bounds)) |
|
|
|
(at 1 (path shape > bounds)) |
|
|
|
(at 2 (path shape > bounds)) |
|
|
|
(at 3 (path shape > bounds)))) |
|
|
|
|
|
|
|
(nsvgRasterize rasterizer puppet-image 0 0 1 image-buffer |
|
|
|
(path puppet-image > width) (path puppet-image > height) |
|
|
|
(* 4 (path puppet-image > width))) |
|
|
|
(var image-surface (addr SDL_Surface) |
|
|
|
(SDL_CreateRGBSurfaceWithFormatFrom |
|
|
|
image-buffer |
|
|
|
(path image > width) |
|
|
|
(path image > height) |
|
|
|
(path puppet-image > width) |
|
|
|
(path puppet-image > height) |
|
|
|
32 ;; bit depth of each pixel (RGBA) |
|
|
|
(* (path image > width) 4) ;; pitch (width of a row in bytes) |
|
|
|
(* (path puppet-image > width) 4) ;; pitch (width of a row in bytes) |
|
|
|
;; Because of how SDL reads pixels in, this does seem to be endian-dependent |
|
|
|
;; I don't fully understand why |
|
|
|
SDL_PIXELFORMAT_RGBA32)) |
|
|
|
(defer (SDL_FreeSurface image-surface)) ;; We don't need this after making the texture |
|
|
|
(set svg-image-texture (SDL_CreateTextureFromSurface renderer image-surface)) |
|
|
|
(set svg-image-width (path image > width)) |
|
|
|
(set svg-image-height (path image > height)) |
|
|
|
(set svg-image-width (path puppet-image > width)) |
|
|
|
(set svg-image-height (path puppet-image > height)) |
|
|
|
(unless svg-image-texture |
|
|
|
(sdl-print-error) |
|
|
|
(return 1))) |
|
|
@ -240,12 +252,6 @@ |
|
|
|
(SDL_SetRenderDrawColor renderer 11 11 11 255) |
|
|
|
(SDL_RenderClear renderer) |
|
|
|
|
|
|
|
(render-string |
|
|
|
renderer (addr (field (at body-font-index font-atlases) atlas)) |
|
|
|
(field (at body-font-index font-atlases) texture) |
|
|
|
(/ true-window-width 9) (- true-window-height 10) |
|
|
|
"This is a test string") |
|
|
|
|
|
|
|
(scope |
|
|
|
(var source-rectangle SDL_Rect |
|
|
|
(array 0 |
|
|
@ -261,30 +267,45 @@ |
|
|
|
(SDL_RenderCopy renderer svg-image-texture |
|
|
|
(addr source-rectangle) (addr destination-rectangle))) |
|
|
|
|
|
|
|
|
|
|
|
;; (when s-enable-debug-overlay |
|
|
|
;; (var buffer (array 256 char) (array 0)) |
|
|
|
;; (var mouse-x int 0) |
|
|
|
;; (var mouse-y int 0) |
|
|
|
;; (SDL_GetMouseState (addr mouse-x) (addr mouse-y)) |
|
|
|
;; (snprintf buffer (- (array-size buffer) 1) "Mouse: %4d %4d Percent of window: %.2f %.2f Wizard relative: %4d %4d" |
|
|
|
;; mouse-x mouse-y |
|
|
|
;; (/ mouse-x (type-cast true-window-width float)) (/ mouse-y (type-cast true-window-height float)) |
|
|
|
;; (- mouse-x (field g-wizard-hero x)) (- mouse-y (field g-wizard-hero y))) |
|
|
|
;; (render-string |
|
|
|
;; renderer (addr (field (at body-code-font-index font-atlases) atlas)) |
|
|
|
;; (field (at body-code-font-index font-atlases) texture) |
|
|
|
;; 10 (- true-window-height 20) |
|
|
|
;; buffer)) |
|
|
|
;; ;; #"# |
|
|
|
;; ;; result= FT_Set_Char_Size(typeface, 0, (16 * 64), 300, 300); |
|
|
|
;; ;; if (!((result== FT_Err_Ok))) |
|
|
|
;; ;; { |
|
|
|
;; ;; fprintf(stderr, "error: encountered error %d while %s\n", result, "setting character size"); |
|
|
|
;; ;; FT_Done_Face(typeface); |
|
|
|
;; ;; FT_Done_FreeType(freetypeLibrary); |
|
|
|
;; ;; return 1; |
|
|
|
;; ;; }#"#) |
|
|
|
(var mouse-x int 0) |
|
|
|
(var mouse-y int 0) |
|
|
|
(SDL_GetMouseState (addr mouse-x) (addr mouse-y)) |
|
|
|
(each-shape-in-svg-image puppet-image shape |
|
|
|
(var shape-bounds SDL_Rect |
|
|
|
(array (type-cast (at 0 (path shape > bounds)) int) |
|
|
|
(type-cast (at 1 (path shape > bounds)) int) |
|
|
|
(type-cast (- (at 2 (path shape > bounds)) |
|
|
|
(at 0 (path shape > bounds))) |
|
|
|
int) |
|
|
|
(type-cast (- (at 3 (path shape > bounds)) |
|
|
|
(at 1 (path shape > bounds))) |
|
|
|
int))) |
|
|
|
(SDL_SetRenderDrawColor renderer 230 10 10 255) |
|
|
|
(when (and (>= mouse-x (type-cast (at 0 (path shape > bounds)) float)) |
|
|
|
(>= mouse-y (type-cast (at 1 (path shape > bounds)) float)) |
|
|
|
(< mouse-x (type-cast (at 2 (path shape > bounds)) float)) |
|
|
|
(< mouse-y (type-cast (at 3 (path shape > bounds)) float))) |
|
|
|
(SDL_SetRenderDrawColor renderer 10 230 10 255) |
|
|
|
(render-string |
|
|
|
renderer (addr (field (at body-font-index font-atlases) atlas)) |
|
|
|
(field (at body-font-index font-atlases) texture) |
|
|
|
(/ true-window-width 9) (- true-window-height 10) |
|
|
|
(path shape > id))) |
|
|
|
(SDL_RenderDrawRect renderer (addr shape-bounds))) |
|
|
|
|
|
|
|
(when true |
|
|
|
(var buffer (array 256 char) (array 0)) |
|
|
|
(var mouse-x int 0) |
|
|
|
(var mouse-y int 0) |
|
|
|
(SDL_GetMouseState (addr mouse-x) (addr mouse-y)) |
|
|
|
(snprintf buffer (- (array-size buffer) 1) "Mouse: %4d %4d Percent of window: %.2f %.2f" |
|
|
|
mouse-x mouse-y |
|
|
|
(/ mouse-x (type-cast true-window-width float)) (/ mouse-y (type-cast true-window-height float))) |
|
|
|
(render-string |
|
|
|
renderer (addr (field (at body-code-font-index font-atlases) atlas)) |
|
|
|
(field (at body-code-font-index font-atlases) texture) |
|
|
|
10 (- true-window-height 50) |
|
|
|
buffer)) |
|
|
|
|
|
|
|
(SDL_RenderPresent renderer) |
|
|
|
(SDL_UpdateWindowSurface window) |
|
|
|