Skip to content

Commit

Permalink
Finish example
Browse files Browse the repository at this point in the history
  • Loading branch information
W2Wizard committed Aug 2, 2022
1 parent de0e2c1 commit a6907bf
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions docs/Basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ In order to achieve this we use [hooks](./Hooks.md).
#define WIDTH 256
#define HEIGHT 256

// Exit the program as failure.
static void ft_error(void)
{
fprintf(stderr, "%s", mlx_strerror(mlx_errno));
exit(EXIT_FAILURE);
}

// Print the window width and height.
static void ft_hook(void* param)
{
Expand All @@ -107,17 +114,19 @@ int32_t main(void)

// MLX allows you to define its core behaviour before startup.
mlx_set_setting(MLX_MAXIMIZED, true);
mlx_set_setting(MLX_STRETCH_IMAGE, true);
mlx_t* mlx = mlx_init(WIDTH, HEIGHT, "42Balls", true);
if (!mlx)
return (EXIT_FAILURE);
ft_error();

/* Do stuff */


// Create and display the image.
mlx_image_t* img = mlx_new_image(mlx, 256, 256);
if
if (!img || (mlx_image_to_window(mlx, img, 0, 0) < 0))
ft_error();

// Even after the image is being displayed, we can still modify the buffer.
mlx_put_pixel(img, 0, 0, 0xFF0000FF);

// Register a hook and pass mlx as an optional param.
// NOTE: Do this before calling mlx_loop!
Expand Down

0 comments on commit a6907bf

Please sign in to comment.