(define (atlas-fit! image #!optional (position (v2 0 0))) (unless *current-atlas* (reset-atlas)) (let* ((atlas (car *current-atlas*)) (textures (cadr *current-atlas*)) (overlaps (find (lambda (t) (contains? position (texture-offset t) (texture-size t))) textures))) (cond ((overlaps (print overlaps) ; prints #f (atlas-fit! image (v2-add position (texture-size overlaps))))) ((not (contains? (v2-add position (image-size image)) (v2 0 0) *atlas-page-size*)) (reset-atlas) (atlas-fit! image)) (else (set-texture atlas) (gl:TexSubImage2D gl:TEXTURE_2D 0 (v2-x position) (v2-y position) (image-width image) (image-height image) gl:RGBA gl:UNSIGNED_BYTE (make-locative (u8vector->blob/shared (image-pixels image)))) (make-texture (texture-id atlas) (image-size image) position)))))