Next: , Previous: , Up: Graphics   [Contents][Index]


5.3.2 Textures

Textures are essentially images: a 2D grid of color values. However, this is a great simplification. Textures can be used to store any kind of data that can be encoded into color channels. The (chickadee graphics texture) module provides an interface for working with texture objects.

Procedure: load-image file [#:min-filter nearest] [#:mag-filter nearest] [#:wrap-s repeat] [#:wrap-t repeat] [#:transparent-color]

Load the image data from file and return a new texture object.

min-filter and mag-filter describe the method that should be used for minification and magnification when rendering, respectively. Possible values are nearest and linear.

wrap-s and wrap-t describe how to interpret texture coordinates that are greater than 1.0. Possible values are repeat, mirrored-repeat, clamp, clamp-to-border, and clamp-to-edge.

For color-keyed images (images where a specific color should be made transparent), specify the appropriate transparent-color.

Procedure: texture? obj

Return #t if obj is a texture.

Procedure: texture-region? obj

Return #t if obj is a texture region.

Procedure: texture-parent texture

If texture is a texture region, return the full texture that it is based upon. Otherwise, return #f.

Procedure: texture-min-filter texture

Return the minification filter for texture, either nearest or linear.

Procedure: texture-mag-filter texture

Return the magnification filter for texture, either nearest or linear.

Procedure: texture-wrap-s texture

Return the method used for wrapping texture coordinates along the X axis for texture.

Possible wrapping methods:

Procedure: texture-wrap-t texture

Return the method used for wrapping texture coordinates along the Y axis for texture.

Procedure: texture-width texture

Return the width of texture in pixels.

Procedure: texture-height texture

Return the height of texture in pixels.

Procedure: current-texture-0

Return the current texture associated with texture unit 0 on the GPU.

Procedure: current-texture-1

Return the current texture associated with texture unit 1 on the GPU.

Procedure: current-texture-2

Return the current texture associated with texture unit 2 on the GPU.

Procedure: current-texture-3

Return the current texture associated with texture unit 3 on the GPU.

Procedure: current-texture-4

Return the current texture associated with texture unit 4 on the GPU.

Variable: g:texture-0

Render state for texture unit 0 (see Rendering Engine.)

Variable: g:texture-1

Render state for texture unit 1 (see Rendering Engine.)

Variable: g:texture-2

Render state for texture unit 2 (see Rendering Engine.)

Variable: g:texture-3

Render state for texture unit 3 (see Rendering Engine.)

Variable: g:texture-4

Render state for texture unit 4 (see Rendering Engine.)

5.3.2.1 Tile Atlases

It is common practice to combine multiple bitmap images into a single texture, known as a “tile atlas” or “tile set”, because it is more efficient to render many regions of a large texture than it is to render a bunch of small textures. Chickadee provides a tile atlas data type for collecting texture regions into a single vector.

Procedure: split-texture texture tile-width tile-height [#:margin 0] [#:spacing 0]

Return a new texture atlas that splits texture into a grid of tile-width by tile-height rectangles. Optionally, each tile may have spacing pixels of horizontal and vertical space between surrounding tiles and the entire image may have margin pixels of empty space around its border.

This type of texture atlas layout is very common for 2D tile maps. See Tile Maps for more information.

Procedure: load-tileset file-name tile-width tile-height [#:margin 0] [#:spacing 0] [#:min-filter nearest] [#:mag-filter nearest] [#:wrap-s repeat] [#:wrap-t repeat] [#:transparent-color]

Return a new texture atlas that splits the texture loaded from the file file-name into a grid of tile-width by tile-height rectangles. See load-image and split-texture for information about all keyword arguments.

Procedure: texture-atlas? obj

Return #t if obj is a texture atlas.

Procedure: texture-atlas-texture atlas

Return the texture that all texture regions in atlas have been created from.

Procedure: texture-atlas-ref atlas index

Return the texture region in atlas at index.

5.3.2.2 Cube Maps

A cube map is a special type of texture composed of 6 images that can be thought of as forming the 6 faces of a cube. See Skyboxes for a practical use of cube maps.

Procedure: load-cube-map #:right #:left #:top #:bottom #:front #:back [#:min-filter linear-mipmap-linear] [#:mag-filter linear]

Return a new cube map that uses the image data in the files right, left, top, bottom, front, and back for the 6 faces of the cube.

Procedure: cube-map? obj

Return #t if obj is a cube map.


Next: , Previous: , Up: Graphics   [Contents][Index]