Skip to content

.MLX Fundamentals

Alessandro Metta edited this page Nov 16, 2021 · 1 revision

mlx_init(): create the connection to the 'graphic interface' and returns address of it.

Window Creation

mlx_new_window(void *CONNECTION_ID, int WIDTH, int HEIGHT, char *NAME): open a window of the set width and height, setting the specified name to it. It returns the address.

image handlers

mlx_new_image(void *CONNECTION_ID, int WIDTH, int HEIGHT): create an image, that will be than printed on the screen. It returns the address.

mlx_put_image_to_window(void *CONNECTION_ID, void *WINDOW_ID, void *IMAGE_ID, int ORIGIN_X, int ORIGIN_Y): this will put the image on the specified window.

mlx_get_data_addr(void *CONNECTION_ID, int *BITS_PER_PIXEL, int *SIZE_LINE, int *ENDIAN): this will get the image datas, that will allow us to draw on the window.

The function to put pixels on the window implemented by library is obsolete, here is the working:

void            my_mlx_pixel_put(t_data *data, int x, int y, int color)
{
    char    *dst;

    dst = data->addr + (y * data->line_length + x * (data->bits_per_pixel / 8));
    *(unsigned int*)dst = color;
}

Loops

mlx_loop(void *CONNECTION_ID): it keeps the connection works. without this, the window will be destroyed. For a correct close of the program:

  • clean the memory
  • destroy the window with mlx_destroy_window(void *CONNECTION_ID, void *WINDOW_ID)
  • exit(0)

Event

mlx_hook(void *CONNECTION_ID, int EVENT, int MASK, int *(int FUNCTION()), void *PARAMETER): setting the EVENT and MASK (check this page), it execute the code inside FUNCTION.

Clone this wiki locally