Skip to content

Instantly share code, notes, and snippets.

@caio-vinicius
Created June 7, 2021 14:28
Show Gist options
  • Save caio-vinicius/cfc01dd1bad7986ada841404c29455d0 to your computer and use it in GitHub Desktop.
Save caio-vinicius/cfc01dd1bad7986ada841404c29455d0 to your computer and use it in GitHub Desktop.
ciro
#include <mlx.h>
typedef struct s_data {
void *img;
char *addr;
int bits_per_pixel;
int line_length;
int endian;
} t_data;
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;
}
int main(void)
{
void *mlx;
void *mlx_win;
t_data img;
mlx = mlx_init();
mlx_win = mlx_new_window(mlx, 100, 100, "Hello world!");
img.img = mlx_new_image(mlx, 100, 100);
img.addr = mlx_get_data_addr(img.img, &img.bits_per_pixel, &img.line_length,
&img.endian);
my_mlx_pixel_put(&img, 5, 5, 0x00FFFFFF);
my_mlx_pixel_put(&img, 5, 6, 0x00FFFFFF);
my_mlx_pixel_put(&img, 6, 5, 0x00FFFFFF);
my_mlx_pixel_put(&img, 6, 6, 0x00FFFFFF);
mlx_put_image_to_window(mlx, mlx_win, img.img, 0, 0);
mlx_loop(mlx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment