mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
starting to re-learn mlx
This commit is contained in:
parent
c2d23b9dc3
commit
6669bad8fe
1 changed files with 30 additions and 1 deletions
31
src/main.c
31
src/main.c
|
|
@ -6,15 +6,44 @@
|
|||
/* By: freddy </var/spool/mail/freddy> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/05 16:59:32 by freddy #+# #+# */
|
||||
/* Updated: 2025/05/06 09:29:41 by freddy ### ########.fr */
|
||||
/* Updated: 2025/05/06 09:54:39 by freddy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/libft.h"
|
||||
#include "../includes/mlx.h"
|
||||
|
||||
typedef struct s_mlx_data
|
||||
{
|
||||
void *img;
|
||||
char *addr;
|
||||
int bits_per_pixel;
|
||||
int line_length;
|
||||
int endian;
|
||||
} t_mlx_data;
|
||||
|
||||
void my_mlx_pixel_put(t_mlx_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(int argc, char **argv)
|
||||
{
|
||||
void *mlx;
|
||||
void *mlx_win;
|
||||
t_mlx_data data;
|
||||
|
||||
if (argc < 2)
|
||||
return (ft_printf("Error: Missing cub3d filename\n"), 1);
|
||||
(void)argv;
|
||||
mlx = mlx_init();
|
||||
mlx_win = mlx_new_window(mlx, 800, 600, "Cub3d");
|
||||
data.img = mlx_new_image(mlx, 800, 600);
|
||||
data.addr = mlx_get_data_addr(data.img, &data.bits_per_pixel, &data.line_length, &data.endian);
|
||||
my_mlx_pixel_put(&data, 5, 5, 0x00FF0000);
|
||||
mlx_put_image_to_window(mlx, mlx_win, data.img, 0, 0);
|
||||
mlx_loop(mlx);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue