Texture
micro::texture is a GPU-side texture for use with a renderer.
Textures are immutable after creation. Ownership is shared: copying a texture
shares the underlying handle, and the texture is freed only when the last owner
is destroyed.
Loading from file
The most common workflow — load an image and upload it to the GPU in one call:
auto tex = micro::texture::load_png(rend, "assets/hero.png");
auto tex = micro::texture::load_bmp(rend, "assets/tile.bmp");
Loading from memory
extern const std::uint8_t hero_png[];
extern const std::size_t hero_png_size;
auto tex = micro::texture::load_png(rend, {hero_png, hero_png_size});
Creating from an image
Use this path when you need to manipulate pixel data before uploading — for example, to set a color key for transparency:
auto img = micro::image::load_png("assets/hero.png");
img.set_color_key(micro::color::magenta); // treat magenta as transparent
micro::texture tex{rend, img};
The source image can be destroyed after the constructor returns; the texture holds its own GPU copy.
Dimensions
int w = tex.width();
int h = tex.height();
Drawing
Pass the texture to renderer::draw(). See Renderer and
Draw options for full details.
rend.draw(tex, {50.f, 30.f});
rend.draw(tex, {50.f, 30.f}, draw_options{}.scale(2.f).tint(color::red));