Loop hook
Now that you’ve understood the basics of MacroLibX, we’ll start by drawing a little animation in the window.
To do this, we’ll be using two new functions: mlx_loop
and mlx_loop_hook
.
Loops are a MacroLibX feature that allows you to keep calling your hook stored in mlx_loop_hook
to render new frames,
which you must, of course, transmit to the window yourself.
🔄 Hook an update function
To initiate a loop, we call the mlx_loop
function with the mlx instance as only parameter, you should have seen it before :
This will do nothing of course as we have no loop hook registered, therefore we will not be able to write anything to our frame. And without any event hook, this will just be an infinite loop :sadge:
To make our application more ‘dynamic’, we need to hook an update function to be able to change what’s rendered. An example of dynamic application could be :