Overview
A Texture represents raw image data, in GPU memory, ready for drawing. A TextureManager can load and cache Textures, index them by name, and make sure they are all destroyed at once. It can also load Texture resource-packs.
Types
TextureInfo = object filename*: string ## filename used to load the Texture name*: string ## name of the Texture description*: string ## a description of the Texture authors*: seq[string] ## authors of the Texture
- Meta-data describing a Texture
Texture = ref object info*: TextureInfo ## meta-data describing the Texture width*: int ## width of the Texture in pixels height*: int ## height of the Texture in pixels handle: TexturePtr ## Pointer to actual Texture
- Used for rendering image data
TextureManager = ref object window: WindowPtr ## window for loading image files display: RendererPtr ## display for rendering Textures registry: Table[string, Texture] ## Loaded Textures by name
- Used for loading and managing Textures
Procs
proc destroy(tm: TextureManager) {.raises: [], tags: [].}
- Destroy references to each loaded texture. The TextureManager will have no loaded Textures after calling this.
proc newTextureManager(window: WindowPtr; display: RendererPtr): TextureManager {. raises: [], tags: [].}
proc contains(tm: TextureManager; name: string): bool {.raises: [], tags: [].}
proc load(tm: TextureManager; name, filename: string; description: string = nil; authors: seq[string] = nil): Texture {. raises: [KeyError, NoSuchResourceError, ValueError, InvalidResourceError], tags: [ReadDirEffect].}
proc loadPack(tm: TextureManager; filename: string) {.raises: [ValueError, IOError, Exception, JsonParsingError, IndexError, InvalidResourceError, KeyError, NoSuchResourceError], tags: [ReadIOEffect, RootEffect, ReadDirEffect].}
-
Load a resource-pack of Textures. Assets inside of a Texture resource-pack should be objects with at least a filename field.
Example TextureAsset JSON
"example_texture": { "filename": "textures/example_texture.png", # required "description": "A texture used as an example", "authors": ["foo", "bar"] }
proc get(tm: TextureManager; name: string): Texture {. raises: [NoSuchResourceError, KeyError], tags: [].}
proc render(display: RendererPtr; texture: Texture; x, y: int) {.raises: [], tags: [].}
- Blit the entire Texture to the target renderer as the specifed coordinates.
proc render(display: RendererPtr; texture: Texture; sx, sy, dx, dy, width, height: int) {.raises: [], tags: [].}
- Blit a specific region of the Texture to the target renderer as the specified coordinates.