Browse Source

Extremely primitive rendering from atlas

master
Macoy Madson 3 months ago
parent
commit
38fc47d462
  1. 7
      .gitignore
  2. 2
      src/FontAtlas.cake
  3. 34
      src/Presentation.cake

7
.gitignore

@ -64,8 +64,6 @@ test/data/Materials/Textures/*.dds
test/data/Models/*
file-helper
imgui.ini
UserData.bin
@ -75,8 +73,7 @@ UserData_TestWrite.cakedata
# TODO Make this less general
*.txt
autoTest
.vs/
game-dev-environment
presentation
Presentation.exe

2
src/FontAtlas.cake

@ -102,7 +102,7 @@
(return 1)))
(var new-glyph-entry glyph-entry (array 0))
(set (field new-glyph-entry key) 'g')
(set (field new-glyph-entry key) character)
(set (field new-glyph-entry x) atlas-write-x)
(set (field new-glyph-entry y) atlas-write-y)
(set (field new-glyph-entry width) num-columns)

34
src/Presentation.cake

@ -27,6 +27,31 @@
(fprintf stderr (token-splice format)))))
(return true))
(defun-local render-string (renderer (* SDL_Renderer) font (* font-atlas) font-texture (* SDL_Texture)
x int y int str (* (const char)))
(var write-x int x)
(var write-y int y)
(each-char-in-string-const str current-char
(var search-key char (deref current-char))
(var glyph (* glyph-entry) (dict-ptr-at (path font > glyph-lookup-table) search-key))
(unless glyph ;; fallback
(set search-key '?')
(set glyph (dict-ptr-at (path font > glyph-lookup-table) search-key)))
(unless glyph ;; even the fallback is missing!
(continue))
(var source-rectangle SDL_Rect
(array (path glyph > x)
(path glyph > y)
(path glyph > width)
(path glyph > height)))
(var destination-rectangle SDL_Rect
(array write-x write-y
(path glyph > width)
(path glyph > height)))
(SDL_RenderCopy renderer font-texture
(addr source-rectangle) (addr destination-rectangle))
(set write-x (+ write-x (path glyph > width)))))
(defun main (&return int)
(data-bundle-load-all-resources)
@ -100,6 +125,9 @@
(sdl-print-error)
(set exit-reason "SDL failed to render font atlas")))
(render-string renderer (addr ubuntu-regular-font-atlas) ubuntu-regular-texture
200 600 "This is a test!")
(SDL_RenderPresent renderer)
(SDL_UpdateWindowSurface window)
@ -112,3 +140,9 @@
(when exit-reason
(preslog "Exited reason: %s\n" exit-reason))
(return 0))
(comptime-cond
('Windows
(set-cakelisp-option executable-output "Presentation.exe"))
(true
(set-cakelisp-option executable-output "presentation")))

Loading…
Cancel
Save