Started from buttom go to the sky

This commit is contained in:
Raphaël 2024-04-28 19:59:01 +02:00
parent 96215449bd
commit f811e55dea
4781 changed files with 10121 additions and 1743 deletions

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_image.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/21 22:43:04 by maiboyer #+# #+# */
/* Updated: 2023/12/31 15:20:24 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/blx/blx.h"
#include "me/blx/colors.h"
#include "me/blx/sprite.h"
#include <mlx.h>
void blx_draw_sprite_raw(t_blx *ctx, t_vi2d pos, t_sprite *img)
{
mlx_put_image_to_window(ctx->mlx, ctx->win, img->img, pos.x, pos.y);
}

View file

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_pixel_onto.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/23 16:32:19 by maiboyer #+# #+# */
/* Updated: 2023/12/31 15:21:33 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/blx/blx.h"
#include "me/blx/sprite.h"
#include <stdio.h>
#include <stdlib.h>
void sprite_draw_other_bpp(t_sprite *spr, t_vi2d pos, t_color col)
{
(void)(spr);
(void)(pos);
(void)(col);
return ;
}
void sprite_draw(t_sprite *spr, t_vi2d pos, t_color col)
{
t_u8 *addr;
if (!(pos.x >= 0 && pos.x < spr->width && pos.y >= 0
&& pos.y < spr->height))
return ;
if (spr->bpp != 32)
return (sprite_draw_other_bpp(spr, pos, col));
addr = &(spr->data)[pos.y * spr->line_size + pos.x * 4];
if (!spr->big_endian)
{
addr[0] = col.b;
addr[1] = col.g;
addr[2] = col.r;
addr[3] = col.a;
}
else
{
addr[0] = col.a;
addr[1] = col.r;
addr[2] = col.g;
addr[3] = col.b;
}
}
/*
addr = &(img->data)[y * img->line_size + (x << 2)];
if (!img->big_endian)
out = ((unsigned long)addr[0] << 24 | (unsigned long)addr[1] << 16 |
(unsigned long)addr[2] << 8 | addr[3]);
else
out = ((unsigned long)addr[3] << 24 | (unsigned long)addr[2] << 16 |
(unsigned long)addr[1] << 8 | addr[0]);
return (out);
*/
void sprite_clear(t_sprite *img, t_color col)
{
t_vi2d pos;
pos.y = 0;
while (pos.y < img->height)
{
pos.x = 0;
while (pos.x < img->width)
{
sprite_draw(img, pos, col);
pos.x++;
}
pos.y++;
}
}

View file

@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboxy[1]er <maiboxy[1]er@student.42.fr> +#+ +:+ +#+
*/
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/27 18:29:56 by maiboxy[1]er #+# #+# */
/* Updated: 2023/12/27 18:43:57 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/blx/blx.h"
#include "me/blx/colors.h"
#include "me/blx/sprite.h"
#include "me/types.h"
static inline void inner(t_sprite *spr, char c, t_vi2d pixel_pos, t_color col)
{
t_vi2d o;
t_color texel;
t_vi2d offset;
o.x = (c - 32) % 16;
o.y = (c - 32) / 16;
texel = new_color(0, 0, 0);
offset.y = 0;
while (offset.y < 8)
{
offset.x = 0;
while (offset.x < 8)
{
if (!sprite_get_pixel(&spr->ctx->_data.font, vi2d(offset.x + o.x
* 8, offset.y + o.y * 8), &texel) && texel.a == 0)
sprite_draw(spr, vi2d_add(pixel_pos, offset), col);
offset.x++;
}
offset.y++;
}
}
static inline t_draw_mode handle_draw_mode(t_blx *app, t_color col)
{
t_draw_mode m;
m = get_draw_mode(app);
if (col.a != 0x00)
set_draw_mode(app, ALPHA);
else
set_draw_mode(app, MASK);
return (m);
}
void sprite_draw_string(t_sprite *spr, t_vi2d pos, t_const_str sText,
t_color col)
{
t_vi2d s;
t_draw_mode m;
char c;
s.x = 0;
s.y = 0;
m = handle_draw_mode(spr->ctx, col);
while (*sText)
{
c = *sText++;
if (c == '\n')
{
s.x = 0;
s.y += 8;
}
else if (c == '\t')
s.x += 8 * 4;
else
{
inner(spr, c, vi2d(pos.x + s.x, pos.y + s.y), col);
s.x += 8;
}
}
set_draw_mode(spr->ctx, m);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_image.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/21 22:40:12 by maiboyer #+# #+# */
/* Updated: 2023/12/26 15:39:04 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/blx/blx.h"
#include "me/blx/sprite.h"
#include <mlx.h>
void blx_sprite_free(t_sprite img)
{
mlx_destroy_image(img.ctx->mlx, img.img);
}

View file

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_pixel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 00:48:23 by maiboyer #+# #+# */
/* Updated: 2023/12/31 15:27:55 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/blx/colors.h"
#include "me/blx/sprite.h"
static bool sprite_get_pixel_other_bpp(t_sprite *spr, t_vi2d pos, t_color *out)
{
(void)(spr);
(void)(pos);
(void)(out);
return (true);
}
bool sprite_get_pixel(t_sprite *spr, t_vi2d pos, t_color *out)
{
t_u8 *addr;
t_color col;
if (!(pos.x >= 0 && pos.x < spr->width && pos.y >= 0
&& pos.y < spr->height))
return (true);
if (spr->bpp != 32)
return (sprite_get_pixel_other_bpp(spr, pos, out));
addr = &(spr->data)[pos.y * spr->line_size + pos.x * 4];
if (spr->big_endian)
{
col.a = addr[0];
col.r = addr[1];
col.g = addr[2];
col.b = addr[3];
}
else
{
col.a = addr[3];
col.r = addr[2];
col.g = addr[1];
col.b = addr[0];
}
*out = col;
return (false);
}

View file

@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* new_image.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/21 21:59:04 by maiboyer #+# #+# */
/* Updated: 2023/12/26 15:40:08 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/blx/blx.h"
#include "me/blx/colors.h"
#include "me/blx/sprite.h"
#include <mlx.h>
bool blx_sprite_from_xpm(t_blx *ctx, t_str path, t_sprite *out)
{
t_sprite spr;
t_i32 bpp;
t_i32 size_line;
t_i32 endian;
spr.ctx = ctx;
spr.img = mlx_xpm_file_to_image(ctx->mlx, path, &spr.width, &spr.height);
if (spr.img == NULL)
return (false);
spr.data = (t_u8 *)mlx_get_data_addr(spr.img, &bpp, &size_line, &endian);
spr.bpp = bpp;
spr.line_size = (t_usize)size_line;
spr.big_endian = endian == 1;
*out = spr;
return (true);
}
bool blx_sprite_new(t_blx *ctx, t_i32 width, t_i32 height, t_sprite *out)
{
t_sprite spr;
t_i32 bpp;
t_i32 size_line;
t_i32 endian;
spr.ctx = ctx;
spr.img = mlx_new_image(ctx->mlx, width, height);
if (spr.img == NULL)
return (false);
spr.data = (t_u8 *)mlx_get_data_addr(spr.img, &bpp, &size_line, &endian);
spr.bpp = bpp;
spr.line_size = (t_usize)size_line;
spr.big_endian = endian == 1;
spr.width = width;
spr.height = height;
*out = spr;
return (true);
}

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sprite_draw_onto_sprite.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/26 19:33:22 by maiboyer #+# #+# */
/* Updated: 2023/12/31 15:26:41 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/blx/blx.h"
#include "me/blx/colors.h"
#include "me/blx/sprite.h"
#include "me/types.h"
#include "me/vec2/vec2.h"
void sprite_draw_onto(t_sprite *dest, t_vi2d pos, t_sprite *source)
{
t_vi2d p;
t_color col;
p.y = 0;
while (p.y < source->height)
{
p.x = 0;
while (p.x < source->width)
{
sprite_get_pixel(source, p, &col);
sprite_draw(dest, vi2d_add(pos, p), col);
p.x++;
}
p.y++;
}
}