Initialization
🚀 Initialization
Before we can do anything with the MacroLibX we must include the mlx.h
header given with the lib and we should execute the mlx_init
function.
This will initialize the graphical system and will return a void*
which holds the location of our current MLX instance.
To initialize the MacroLibX one could do the following :
When you run the code, you can’t help but notice that nothing pops up and that nothing is being rendered.
Well, this obviously has something to do with the fact that you are not creating a window yet, so let’s try initializing a tiny window which will stay open forever.
You can close it by pressing ctrl+\
in your terminal. To achieve this, we will simply call the mlx_new_window
function, which will return a pointer to the window we have just created.
We can give the window height, width and a title. We then will have to call mlx_loop
to initiate the window rendering. Let’s create a window with a width of 400, a height of 400 and a name of “Hello world!” :
🗑️ Cleanup
If you run your new graphical application made with the MacroLibX with Valgrind or any other leak-finding tool, you’ll notice that there are a lot of memory loss.
This is because we have initialized the MacroLibX, but we did not shutdown it. Same thing goes for the window, we did not destroyed it. To do so we can call two functions,
mlx_destroy_window
and mlx_destroy_display
.