-
Notifications
You must be signed in to change notification settings - Fork 72
Images
Images are essentially just OpenGL textures with a simple to use interface. They store a buffer of pixels and are then displayed to the window.
An image on its own is very simple:
typedef struct s_mlx_image
{
const uint16_t width;
const uint16_t height;
uint8_t *pixels;
t_mlx_instance *instances;
uint16_t count;
void *context;
} t_mlx_image;It holds the width, height and pixels. However images can have instances, that is, copies of itself that share the same pixel buffer.
This makes it easy to make for instance, a row of trees. They all hold the same pixel information, just different locations.
instances is simply an array of each individual instance, they hold the x, y and z positions of the instance,count tells us the element count of this array.
All that is needed it call the mlx_image_to_window function to create a new copy. However its also possible to move the location
of individual images quite easily:
// Modify the x & y position of an already existing instance.
img->instances[0].x += 5;
img->instances[0].y += 5;All that is needed is to simply change the values and MLX will handle the rest of updating the position.
// Creates a whole new image.
t_mlx_image *mlx_new_image(t_mlx *mlx, uint16_t width, uint16_t height)// Creates a new instance/copy of an already existing image.
void mlx_image_to_window(t_mlx_image *img, int32_t x, int32_t y, int32_t z)MLX42 works similarly to minilibx in regards to how images are drawn onto the window.
TODO