aboutsummaryrefslogtreecommitdiff
path: root/graphics.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-19 17:51:40 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-19 17:51:40 +0100
commit2875f205e24f19964d44ddce2470659d21fe902d (patch)
treee5daf691cdd87fb036f2d90e9b9ee59de360dfa6 /graphics.c
parent264676907b55f429e65b4de523eeb729fb64e9f9 (diff)
downloadcub3d-2875f205e24f19964d44ddce2470659d21fe902d.tar.gz
cub3d-2875f205e24f19964d44ddce2470659d21fe902d.tar.bz2
cub3d-2875f205e24f19964d44ddce2470659d21fe902d.zip
Removed duplicate man, modify window buffer instead of writting each pixels
Diffstat (limited to 'graphics.c')
-rw-r--r--graphics.c65
1 files changed, 49 insertions, 16 deletions
diff --git a/graphics.c b/graphics.c
index 5655aa6..02b326d 100644
--- a/graphics.c
+++ b/graphics.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* graphics.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/19 16:39:57 by cacharle #+# #+# */
+/* Updated: 2019/11/19 17:50:51 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "cub3d.h"
t_state *create_state(void *mlx_ptr, void *window_ptr, t_parsing *parsing)
@@ -6,10 +18,28 @@ t_state *create_state(void *mlx_ptr, void *window_ptr, t_parsing *parsing)
if ((state = (t_state*)malloc(sizeof(t_state))) == NULL)
return (NULL);
- if ((state->window_img = mlx_new_image(mlx_ptr, parsing->resolution_width, parsing->resolution_height)) == NULL)
+ state->window_img.id = mlx_new_image(mlx_ptr, parsing->resolution_width, parsing->resolution_height);
+ state->window_img.width = parsing->resolution_width;
+ state->window_img.height = parsing->resolution_height;
+ state->window_img.data = mlx_get_data_addr(state->window_img.id,
+ &state->window_img.depth, &state->window_img.size_line, &state->window_img.endian);
+ printf("%d\n", state->window_img.width);
+ printf("%d\n", state->window_img.height);
+ printf("%d\n", state->window_img.depth);
+ printf("%d\n", state->window_img.size_line);
+ printf("%d\n", state->window_img.endian);
+
+ state->north_texture.id = mlx_xpm_file_to_image(mlx_ptr,
+ parsing->north_texture_path, &state->north_texture.width, &state->north_texture.height);
+ if (state->north_texture.id == NULL)
return (NULL);
- state->window_buf = mlx_get_data_addr(state->window_img,
- &state->window_img_depth, &state->window_img_line_size, &state->window_img_endian);
+ state->north_texture.data = mlx_get_data_addr(state->north_texture.id, &state->north_texture.depth,
+ &state->north_texture.size_line, &state->north_texture.endian);
+ /* printf("%d\n", state->north_texture.endian); */
+ /* state->south_texture = ; */
+ /* state->west_texture = ; */
+ /* state->east_texture = ; */
+
state->mlx_ptr = mlx_ptr;
state->window_ptr = window_ptr;
state->window_width = parsing->resolution_width;
@@ -46,15 +76,15 @@ int graphics_update(void *param)
while (++x < state->window_width)
draw_column(state, x);
+ /* for (int i = 0; i < 200000; i++) */
+ /* state->window_img.data[i] = 127; */
+ mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, state->window_img.id, 0, 0);
+ /* mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, state->north_texture.id, 0, 0); */
+ /* for (int i = 0; i < 200; i++) */
+ /* printf("%d ", state->window_img.data[i]); */
return (0);
}
-typedef enum
-{
- SIDE_NORTH_SOUTH,
- SIDE_WEST_EAST
-} t_side;
-
void draw_column(t_state *state, int x)
{
/*
@@ -139,15 +169,18 @@ void draw_column(t_state *state, int x)
if (draw_end >= state->window_height)
draw_end = state->window_height - 1;
+ int tex_x;
+
+ /* int wall_x = side == SIDE_WEST_EAST ? pos */
+
int i;
i = 0;
- while (i < draw_start )
- state->window_buf[i * state->window_width + x] = state->ceilling_color.hexcode;
- /* mlx_pixel_put(state->mlx_ptr, state->window_ptr, x, i++, state->ceilling_color.hexcode); */
+ t_color white;
+ white.hexcode = 0x00ffffff;
+ while (i < draw_start)
+ ((t_color*)state->window_img.data)[i++ * state->window_img.width + x] = state->ceilling_color;
while (i < draw_end)
- state->window_buf[i * state->window_width + x] = 0x00ffffff;
- /* mlx_pixel_put(state->mlx_ptr, state->window_ptr, x, i++, 0x00ffffff); */
+ ((t_color*)state->window_img.data)[i++ * state->window_img.width + x] = white;
while (i < state->window_height)
- state->window_buf[i * state->window_width + x] = state->floor_color.hexcode;
- /* mlx_pixel_put(state->mlx_ptr, state->window_ptr, x, i++, state->floor_color.hexcode); */
+ ((t_color*)state->window_img.data)[i++ * state->window_img.width + x] = state->floor_color;
}