Image
An image holds raw pixel data along with its dimensions. Images are typically loaded using an image loader and shared between texture instances. Pixel data is stored as either 8-bit bytes for standard LDR images, or 32-bit floats for HDR images. To learn more see the Importing Assets Guide.
auto image = vglx::LoadImage("assets/heightmap.png");
if (image.has_value()) {
// use image.value()
} else {
std::println(stderr, "{}", image.error());
}Loading images directly is useful when you need to share the same pixel data across textures or update texture contents at runtime (see DynamicTexture2D). For one-off texture creation, prefer LoadTexture, which loads an image and creates a texture in one step.
Construction
Constructors
Image()
Constructs an image from initialization parameters.
Prefer Image::Create over direct construction to obtain a stdshared_ptr<Image> that can be shared between textures.
Image::Image(Parameters params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the image. |
Factories preferred
Creates a shared instance of Image.
static std::shared_ptr<Image> Image::Create(Parameters params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the image. |
Types
Image::Parameters struct
PixelData typedef
Pixel data storage; LDR (8-bit) or HDR (32-bit float).
using vglx::Image::PixelData = std::variant<std::vector<uint8_t>, std::vector<float>>Properties
height unsigned
Image height in pixels.
unsigned height {};width unsigned
Image width in pixels.
unsigned width {};