Skip to content

Images and Textures

Fjodor Schelichow edited this page Nov 17, 2017 · 2 revisions

Images

Supported formats

sgltk supports loading images from following file formats: BMP, GIF, JPEG, LBM, PCX, PNG, PNM, TGA, TIFF, WEBP, XCF, XPM, XV.

Loading and saving images

To load an image from a file you can either use the appropriate constructor or the load function.

sgltk::Image image;
image.load("path/to/image");
If you don’t use an absolute path, this function will look for files in the current working directory first and then in all the directories added to the list of image file paths by calls to add_path in the order they were added.
sgltk::Image::add_path("../Pictures");
image.load("my_picture.png"); //will try to open "./my_picture.png" and if that fails "../Pictures/my_picture.png"
The data contained in an image object is accessible through its data member variable. If you call the load function again, the data that was stored in the Image object will be lost

To save an image you can simply use the save function.

image.save("path/to/image"); //relative to the current working directory

#

Textures

Types of textures

sgltk provides different texture subclasses that are all derived from the Texture class.

Loading textures

Textures can be loaded from objects of the Image class.

sgltk::Image img("path/to/image");
sgltk::Texture_2d(img);
alternatively you can do it like this
sgltk::Texture_2d("path/to/image");

Clone this wiki locally