Skip to content
Jonathan Chan edited this page Jul 31, 2018 · 1 revision

The textures directory contains PNG files to be converted into OpenGL textures. The textures are automatically padded to powers of two to satisfy GPU requirements. Some GPUs will not display textures larger than 1024x1024, so images should be smaller or equal to this in size. The texture converter will process RGBA/RGB/Grayscale PNGs into RGBA/RGB/Alpha textures, respectively. Smaller alpha textures have the least rendering overhead.

Textures are accessible as <png name>.img in the application. For example, the texture corresponding to the image file splash.png can be referenced as splash.img in the code.

The texture <png name>.img parameters are actually lists,

(w h texturedata x1 y1 x2 y2)

where w,h are the dimensions to render in pixels, and (x1,y1)-(x2,y2) are the relative coordinates into the texture map. (x1,y1) will be (0,0) for an automatically generated texture. The texture map dimensions are powers of two, so the relative coordinates are not necessarily relative to the dimensions of the source image. The following can be used to access portions of a texture, for example to implement a sprite atlas:

(define (subtexture texture x y w h)
  (let* ((w0 (car texture))
         (h0 (cadr texture))
         (xr2 (list-ref texture 5))
         (yr2 (list-ref texture 6))
         (subxr1 (/ (* x xr2) w0))
         (subyr1 (/ (* y yr2) h0))
         (subxr2 (/ (* (+ x w) xr2) w0))
         (subyr2 (/ (* (+ y h) yr2) h0)))
    (list w h (caddr texture) subxr1 subyr1 subxr2 subyr2)))

(define sprites (list
  (subtexture atlas.img 97  17 95 78)
  (subtexture atlas.img 193 17 95 78)
  (subtexture atlas.img 289 17 95 78)
  (subtexture atlas.img 385 17 95 78)
))
Clone this wiki locally