fractol/mlx/main.c
2023-03-01 04:36:42 +01:00

43 lines
941 B
C

#include "include/MLX42/MLX42.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <memory.h>
#define WIDTH 256
#define HEIGHT 256
mlx_image_t *g_img;
void hook(void *param)
{
mlx_t *mlx;
mlx = param;
if (mlx_is_key_down(mlx, MLX_KEY_ESCAPE))
mlx_close_window(mlx);
if (mlx_is_key_down(mlx, MLX_KEY_UP))
g_img->instances[0].y -= 5;
if (mlx_is_key_down(mlx, MLX_KEY_DOWN))
g_img->instances[0].y += 5;
if (mlx_is_key_down(mlx, MLX_KEY_LEFT))
g_img->instances[0].x -= 5;
if (mlx_is_key_down(mlx, MLX_KEY_RIGHT))
g_img->instances[0].x += 5;
}
int32_t main(void)
{
mlx_t *mlx;
mlx = mlx_init(WIDTH, HEIGHT, "MLX42", true);
if (!mlx)
exit(EXIT_FAILURE);
g_img = mlx_new_image(mlx, 128, 128);
memset(g_img->pixels, 255, g_img->width * g_img->height * sizeof(int));
mlx_image_to_window(mlx, g_img, 0, 0);
mlx_loop_hook(mlx, &hook, mlx);
mlx_loop(mlx);
mlx_terminate(mlx);
return (EXIT_SUCCESS);
}