diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-30 15:26:40 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-30 15:26:40 +0100 |
| commit | 3a164bce55e173d5204c4aaa66dd4eb5bc1762f9 (patch) | |
| tree | cff350ab4cbb0c4ca6d4da45192a4cf87f2d3d5c /render.c | |
| parent | 679b5dced1d73d9284bab8965e2f3bf37b3056f4 (diff) | |
| download | cub3d-3a164bce55e173d5204c4aaa66dd4eb5bc1762f9.tar.gz cub3d-3a164bce55e173d5204c4aaa66dd4eb5bc1762f9.tar.bz2 cub3d-3a164bce55e173d5204c4aaa66dd4eb5bc1762f9.zip | |
texture kinda working
Diffstat (limited to 'render.c')
| -rw-r--r-- | render.c | 60 |
1 files changed, 26 insertions, 34 deletions
@@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/11 13:37:17 by cacharle #+# #+# */ -/* Updated: 2020/01/30 14:16:36 by cacharle ### ########.fr */ +/* Updated: 2020/01/30 15:17:49 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,6 +54,7 @@ void render_column(t_state *state, int x) if (state->map[(int)rstate.map_pos.y][(int)rstate.map_pos.x] == CELL_WALL) break ; } + rstate_perp_dist(state, &rstate); rstate_line_height(state, &rstate); rstate.draw_start = state->window.height / 2 - rstate.line_height / 2; rstate.draw_end = state->window.height / 2 + rstate.line_height / 2; @@ -75,41 +76,32 @@ void render_window_column(t_state *state, t_render_state *rstate) ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = state->ceilling_color; while (i < rstate->draw_end) ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = white; + render_texture(state, rstate); + i = rstate->draw_end; while (i < state->window.height) ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = state->floor_color; - /* while (++i < rstate->draw_start) */ - /* ((t_color*)state->window.data)[i * state->window.width + rstate->x] = */ - /* state->ceilling_color; */ - /* i = rstate->draw_end; */ - /* i = render_texture(state, rstate); */ - /* while (++i < state->window_height) */ - /* ((t_color*)state->window.data)[i * state->window.width + rstate->x] = */ - /* state->floor_color; */ } -/* int render_texture(t_state *state, t_render_state *rstate)) */ -/* { */ - /* int i; */ - /* int tex_x; */ - /* double step; */ - /* double tex_pos; */ - /* int tex_y; */ - /* t_image *texture; */ - /* */ - /* texture = get_tex(state, side); */ - /* tex_x = get_tex_x(); */ - /* */ - /* step = 1.0 * texture->height / line_height; */ - /* texPos = (start - state->window.height / 2 + line_height / 2) * step; */ - /* */ - /* i = start - 1; */ - /* while (++i < end) */ - /* { */ - /* tex_y = (int)tex_pos & (texture->height - 1); */ - /* tex_pos += step; */ - /* ((t_color*)state->window.data)[i * state->window.width + x] = */ - /* texture[texHeight * texY + texX]; */ - /* } */ - /* return (end); */ -/* } */ +void render_texture(t_state *state, t_render_state *rstate) +{ + int i; + double step; + double tex_pos; + int tex_y; + int tex_x; + t_image *texture; + + texture = get_tex(state, rstate); + tex_x = get_tex_x(state, rstate, texture); + step = 1.0 * texture->height / rstate->line_height; + tex_pos = (rstate->draw_start - state->window.height / 2 + rstate->line_height / 2) * step; + i = rstate->draw_start - 1; + while (++i < rstate->draw_end) + { + tex_y = (int)tex_pos & (texture->height - 1); + tex_pos += step; + ((t_color*)state->window.data)[i * state->window.width + rstate->x] = + ((t_color*)texture->data)[texture->height * tex_y + tex_x]; + } +} |
