-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextures_pixel.c
More file actions
61 lines (53 loc) · 2.24 KB
/
textures_pixel.c
File metadata and controls
61 lines (53 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* textures_pixel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bkarlida <bkarlida@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/26 19:24:11 by bkarlida #+# #+# */
/* Updated: 2023/09/02 20:18:06 by bkarlida ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
unsigned int get_pixel_in_tex(t_texture tex, int x, int y)
{
char *dst;
dst = tex.data + (y * tex.sizeline + x * (tex.bpp / 8));
return (*((unsigned int *)dst));
}
int create_trgb(int t, int r, int g, int b)
{
return (t << 24 | r << 16 | g << 8 | b);
}
void put_px_img(t_cub3d *f, int x, int y, int color)
{
char *dst;
dst = f->img.data + (y * f->img.sizeline + x * (f->img.bpp / 8));
*(unsigned int *)dst = color;
}
void calc_texture_pixel_color(t_cub3d *game)
{
int color;
int tex_y;
if (game->y < game->draw_start)
put_px_img(game, game->x, game->y, create_trgb(0, game->sky.r,
game->sky.g, game->sky.b));
else if (game->y >= game->draw_start && game->y <= game->draw_end)
{
tex_y = (int)game->tex_pos & (TEX_H - 1);
game->tex_pos += game->step;
if (game->side == 0 && game->ray_dir_x > 0)
color = get_pixel_in_tex(game->north, game->tex_x, tex_y);
else if (game->side == 0 && game->ray_dir_x < 0)
color = get_pixel_in_tex(game->south, game->tex_x, tex_y);
else if (game->side == 1 && game->ray_dir_y > 0)
color = get_pixel_in_tex(game->west, game->tex_x, tex_y);
else if (game->side == 1 && game->ray_dir_y < 0)
color = get_pixel_in_tex(game->east, game->tex_x, tex_y);
put_px_img(game, game->x, game->y, color);
}
else
put_px_img(game, game->x, game->y, create_trgb(0, game->floor.r,
game->floor.g, game->floor.b));
}