En sois la vie tu né, tu fais rien et tu meurs

This commit is contained in:
Etienne Rey-bethbeder 2023-05-10 13:56:34 +02:00
parent 63eca2ab8e
commit 5c5d23c5f7
3 changed files with 3 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 631 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 631 B

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/02 15:49:00 by erey-bet #+# #+# */ /* Created: 2023/05/02 15:49:00 by erey-bet #+# #+# */
/* Updated: 2023/05/09 15:05:37 by erey-bet ### ########.fr */ /* Updated: 2023/05/10 13:40:52 by erey-bet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -116,8 +116,7 @@ static uint32_t switch_color_bytes(uint32_t bad)
} }
uint32_t get_pixel_color(mlx_texture_t *texture, uint32_t x, uint32_t y) { uint32_t get_pixel_color(mlx_texture_t *texture, uint32_t x, uint32_t y) {
uint32_t *pixel_ptr = (uint32_t*)(texture->pixels + (y * texture->width + x) * texture->bytes_per_pixel); return switch_color_bytes(*(uint32_t*)(texture->pixels + (y * texture->width + x) * texture->bytes_per_pixel));
return switch_color_bytes(*pixel_ptr);
} }
int get_texture_side(t_dda *dda) int get_texture_side(t_dda *dda)
@ -151,12 +150,10 @@ void draw_texture(t_game *game, t_dda *dda, double x)
|| (dda->side == 1 && game->ray.dir_y < 0)) || (dda->side == 1 && game->ray.dir_y < 0))
tex.x = tex.texture->width - tex.x - 1; tex.x = tex.texture->width - tex.x - 1;
tex.step = 1.0 * tex.texture->height / dda->line_height; tex.step = 1.0 * tex.texture->height / dda->line_height;
tex.pos = (dda->draw_start - tex.texture->height / 2 + dda->line_height / 2) * tex.step; tex.pos = (dda->draw_start - game->window->height / 2 + dda->line_height / 2) * tex.step;
y = dda->draw_start - 1; y = dda->draw_start - 1;
//printf("tex.x: %d\n", tex.x);
while (++y < dda->draw_end) while (++y < dda->draw_end)
{ {
//printf("tex.y: %d\n", tex.y);
tex.y = (int)tex.pos & (tex.texture->height - 1); tex.y = (int)tex.pos & (tex.texture->height - 1);
tex.pos += tex.step; tex.pos += tex.step;
mlx_put_pixel(game->window, x, y, get_pixel_color(tex.texture, tex.x, tex.y)); mlx_put_pixel(game->window, x, y, get_pixel_color(tex.texture, tex.x, tex.y));