Skip to content

texture

anthony.samms edited this page May 28, 2026 · 1 revision

This document will outline the texture system used in the simulator. The texture system is robust but has a lot of quirks, so read carefully.

A texture is stored as a TextureObject. This means by default it has these attributes:

  • std::string name
  • int width (the real width of the texture)
  • int height (the real height of the texture)
  • std::vector<int> x (the list of associated x values)
    • 0 by default
  • std::vector<int> y (the list of associated y values)
    • 0 by default
  • std::vector<int> x2 (the list of associated values that adjust the width)
    • equal to the real width by default
  • std::vector<int> y2 (the list of associated values that adjust the height)
    • equal to the real height by default

A TextureObject generally isn't used directly either: it's stored into one of two types:

A SingleTexture, which contains one TextureObject A FramedTexture, which contains multiple TextureObjects, generally ones that are animated. This will not work if the frames do not share the same width and height.

Mipmaps and filtering occur upon initialization of either of these objects.

Textures should not be initialized on their own; it should be done through the texture wrapper. There are three texture wrappers available:

  • tex: the general case texture wrapper. textures are loaded on a per screen basis.
  • global_tex: the global texture wrapper. textures persist until closing the game.
  • script_manager.tex: for use with script.

The TextureWrapper has this interface:

The skin_config, options, screen_width, screen_height, and screen_scale can be accessed as attributes. The screen_scale is a multiplier of the default screen size, 1280x720.

void unload_textures();

Unloads any textures in the wrapper.

BaseAnimation* get_animation(const int id, bool is_copy = false);

Returns a pointer to an animation based on an id. This only applies to animations in the current screen. To get a full animation object instead of a pointer, set is_copy to true.

void load_screen_textures(const std::string& screen_name);

Loads all the textures of a given screen, including its animations.

uint32_t get_enum(const std::string& name);

Textures are now accessed via enums that are generated during compilation. If a texture name is needed and it is dynamic, you can use this function to get the enum based on a string.

void draw_texture(uint32_t id, const DrawTextureParams& = {});

Draws a texture to the screen based on the enum id. The parameters that can be used with this function are the following:

  • ray::Color color: controls the tint
  • frame: for FramedTextures only. controls the frame displayed
  • float scale: scales the width and height
  • bool center: centers the origin. Often paired with scale
  • x, y, x2, y2: This value will be added to the default value.
  • ray::Vector2 origin control the origin directly. rarely used
  • rotation: control rotation. This will rotation from the top left and not from the center.
  • fade: control the opacity
  • index: If a texture has multiple entries for positioning information, this index can be used to select an entry
  • std::optional<ray::Rectangle> src the source rectangle of the texture. rarely used

Clone this wiki locally