draw.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* draw.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: gychoi <gychoi@student.42seoul.kr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/04/27 20:23:30 by gychoi #+# #+# */ 9 /* Updated: 2023/05/11 22:37:51 by gychoi ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include "header.h" 14 15 void my_mlx_pixel_put(t_data *data, int x, int y, int color) 16 { 17 char *dst; 18 19 dst = data->addr + (y * data->length + x * (data->bpp / 8)); 20 *(unsigned int *)dst = color; 21 } 22 23 int trgb_anti(t_color3 *color, int anti, int t) 24 { 25 double scale; 26 27 if (anti == 0) 28 anti = 1; 29 scale = 1 / (double)anti; 30 color->x = clamp((color->x * scale), 0, 0.999); 31 color->y = clamp((color->y * scale), 0, 0.999); 32 color->z = clamp((color->z * scale), 0, 0.999); 33 return (write_color(t, *color)); 34 } 35 36 // t : transparency 37 int write_color(int t, t_color3 pixel_color) 38 { 39 return (t << 24 | (int)(255 * pixel_color.x) << 16 | (int)(255 * pixel_color.y) << 8 | (int)(255 * pixel_color.z)); 40 }