Skip to content

Commit 64dd4e1

Browse files
first commit based on my old fdf project
0 parents  commit 64dd4e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2389
-0
lines changed

Makefile

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: yboudoui <[email protected]> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2022/06/19 14:53:15 by yboudoui #+# #+# #
9+
# Updated: 2023/04/24 17:12:16 by yboudoui ### ########.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
NAME = cub3D
14+
15+
CC = cc
16+
17+
EXTRA_FLAG = -Ofast -flto=full -DBONUS
18+
19+
CFLAGS = -Wall -Wextra -Werror
20+
21+
RM = rm -f
22+
23+
MLX_DIR = mlx_linux
24+
25+
LINK = -L $(MLX_DIR) -lmlx_Linux -lmlx -lXext -lX11 -lm
26+
27+
28+
# **************************************************************************** #
29+
30+
SRCS =\
31+
./utils/str/ft_strtrim.c\
32+
./utils/str/ft_strncmp.c\
33+
./utils/str/ft_strlen.c\
34+
./utils/str/ft_substr.c\
35+
./utils/str/ft_split.c\
36+
./utils/lst/source/ft_lst_remove_one.c\
37+
./utils/lst/source/ft_lstclear.c\
38+
./utils/lst/source/ft_lstmap.c\
39+
./utils/lst/source/add.c\
40+
./utils/lst/source/create.c\
41+
./utils/lst/source/ft_lstlast.c\
42+
./utils/is_charset/is_charset.c\
43+
./utils/atoi_to.c\
44+
./utils/file/file.c\
45+
./utils/memory/ft_memcpy.c\
46+
./utils/memory/ft_calloc.c\
47+
./utils/memory/ft_memset.c\
48+
./utils/int_array/int_array.c\
49+
./utils/get_next_line/get_next_line_utils.c\
50+
./utils/get_next_line/get_next_line.c\
51+
./cub3D.c\
52+
./main.c\
53+
./mlx_utils/color/color.c\
54+
./mlx_utils/vec2/vec2.c\
55+
./mlx_utils/event/window/window.c\
56+
./mlx_utils/event/event.c\
57+
./mlx_utils/event/keyboard/keyboard.c\
58+
./mlx_utils/event/mouse/mouse.c\
59+
./mlx_utils/line/line.c\
60+
./mlx_utils/screen/screen.c\
61+
./mlx_utils/mlx_utils.c\
62+
./mlx_utils/image/quad.c\
63+
./mlx_utils/image/triangle.c\
64+
./mlx_utils/image/image.c\
65+
./mlx_utils/image/line.c\
66+
./draw/event_state.c\
67+
./draw/draw.c\
68+
69+
INCS =\
70+
./utils/str\
71+
./utils/lst/include\
72+
./utils/is_charset\
73+
./utils\
74+
./utils/file\
75+
./utils/memory\
76+
./utils/int_array\
77+
./utils/get_next_line\
78+
.\
79+
./mlx_linux\
80+
./mlx_linux\
81+
./mlx_utils/color\
82+
./mlx_utils/vec2\
83+
./mlx_utils/event\
84+
./mlx_utils/event/window\
85+
./mlx_utils/event/keyboard\
86+
./mlx_utils/event/mouse\
87+
./mlx_utils/line\
88+
./mlx_utils/screen\
89+
./mlx_utils\
90+
./mlx_utils/image\
91+
92+
# **************************************************************************** #
93+
94+
OBJS = $(SRCS:.c=.o)
95+
96+
all: $(NAME)
97+
98+
$(OBJS): %.o : %.c
99+
@$(CC) $(CFLAGS) \
100+
$(addprefix -I , $(INCS)) -I $(MLX_DIR) \
101+
-c $<\
102+
-o $(<:.c=.o)
103+
@echo $(CC) $(CFLAGS) $@
104+
105+
$(NAME): $(OBJS)
106+
@$(MAKE) -si all -C $(MLX_DIR)
107+
@$(CC) $(CFLAGS) $(OBJS) $(LINK) -o $(NAME)
108+
@echo $(CC) $(CFLAGS) $(NAME)
109+
110+
clean:
111+
@$(MAKE) -si clean -C $(MLX_DIR)
112+
@$(RM) $(OBJS)
113+
114+
fclean: clean
115+
@$(RM) $(NAME)
116+
117+
re: fclean all
118+
119+
valgrind: fclean
120+
@$(MAKE) all -C . EXTRA_FLAG="-g3"
121+
@valgrind \
122+
-s \
123+
--leak-check=full \
124+
--show-leak-kinds=all \
125+
--track-origins=yes \
126+
./$(NAME) \
127+
128+
.PHONY: all clean fclean re bonus

cub3D.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* cub3D.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: yboudoui <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/04/24 14:16:09 by yboudoui #+# #+# */
9+
/* Updated: 2023/04/24 17:09:05 by yboudoui ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "cub3D.h"
14+
15+

cub3D.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* cub3D.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: yboudoui <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/04/24 14:14:30 by yboudoui #+# #+# */
9+
/* Updated: 2023/04/24 17:08:53 by yboudoui ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef CUB3D_H
14+
# define CUB3D_H
15+
16+
# include "screen.h"
17+
# include "image.h"
18+
# include <math.h>
19+
20+
void draw_image(t_screen *data);
21+
bool update_state(t_screen *data);
22+
23+
#endif

draw/draw.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* draw.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: yboudoui <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/11/14 18:21:13 by yboudoui #+# #+# */
9+
/* Updated: 2023/04/24 17:26:02 by yboudoui ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "cub3D.h"
14+
15+
static inline void drawer(t_screen *screen, t_quad quad)
16+
{
17+
int mode;
18+
19+
mode = 1;
20+
if (mode == 1)
21+
image_put_quad(screen->img, quad);
22+
else
23+
image_put_empty_quad(screen->img, quad);
24+
}
25+
26+
void draw_image(t_screen *screen)
27+
{
28+
t_quad quad;
29+
t_color a;
30+
t_color b;
31+
32+
quad = (t_quad){0};
33+
a = create_trgb(1, 255, 0, 0);
34+
b = create_trgb(1, 0, 0, 255);
35+
36+
quad.point[0][0] = (t_pixel){
37+
.coord = (t_vec2){50, 50},
38+
.color.raw = 0x00FF00
39+
};
40+
quad.point[0][1] = (t_pixel){
41+
.coord = (t_vec2){50, 590},
42+
.color = b
43+
};
44+
quad.point[1][0] = (t_pixel){
45+
.coord = (t_vec2){750, 50},
46+
.color = b
47+
};
48+
quad.point[1][1] = (t_pixel){
49+
.coord = (t_vec2){750, 590},
50+
.color = a
51+
};
52+
53+
const t_color g_BLACK = (t_color){.raw = 0};
54+
image_clear(screen->img, g_BLACK);
55+
drawer(screen, quad);
56+
}

draw/event_state.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* event_state.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: yboudoui <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/11/26 14:22:47 by yboudoui #+# #+# */
9+
/* Updated: 2023/04/24 17:19:44 by yboudoui ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "cub3D.h"
14+
15+
/*
16+
static bool update_control(t_screen *screen)
17+
{
18+
if (screen->mlx->event.mouse.scrol_up)
19+
if (screen->mlx->event.mouse.scrol_down)
20+
screen->mlx->event.mouse.scrol_up = false;
21+
screen->mlx->event.mouse.scrol_down = false;
22+
return (true);
23+
}
24+
*/
25+
26+
/*
27+
static bool update_scrol(t_screen *screen)
28+
{
29+
if (screen->mlx->event.mouse.scrol_up)
30+
if (screen->mlx->event.mouse.scrol_down)
31+
if (screen->pad < 1.0f)
32+
screen->mlx->event.mouse.scrol_up = false;
33+
screen->mlx->event.mouse.scrol_down = false;
34+
return (true);
35+
}
36+
*/
37+
bool update_state(t_screen *screen)
38+
{
39+
/*
40+
if (screen->mlx->event.keyboard.enter)
41+
{
42+
screen->mlx->event.keyboard.enter = false;
43+
return (true);
44+
}
45+
*/
46+
if (screen->mlx->event.keyboard.escape == true)
47+
return (mlx_loop_end(screen->mlx->mlx), false);
48+
if (screen->mlx->event.window.destroy == true)
49+
return (mlx_loop_end(screen->mlx->mlx), false);
50+
/*
51+
if (screen->mlx->event.keyboard.control_key)
52+
return (update_control(screen));
53+
else
54+
return (update_scrol(screen));
55+
*/
56+
return (true);
57+
}

main.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* main.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: yboudoui <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/06/19 14:51:33 by yboudoui #+# #+# */
9+
/* Updated: 2023/04/24 17:19:50 by yboudoui ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "cub3D.h"
14+
15+
#define WIDTH 800
16+
#define HEIGHT 640
17+
18+
int draw(t_screen *screen)
19+
{
20+
screen->center = screen->mlx->event.mouse.pos;
21+
if (false == update_state(screen))// here update mouse + keyboard state
22+
return (-1);
23+
draw_image(screen);
24+
mlx_put_image_to_window(screen->mlx->mlx, screen->mlx->win,
25+
screen->img->data, 0, 0);
26+
return (0);
27+
}
28+
29+
int main(void)
30+
{
31+
t_screen *screen;
32+
33+
screen = screen_create("cub3D", WIDTH, HEIGHT);
34+
if (NULL == screen)
35+
return (-2);
36+
mlx_loop_hook(screen->mlx->mlx, draw, screen);
37+
mlx_loop(screen->mlx->mlx);
38+
return (screen_destroy(screen), 0);
39+
}

mlx_linux

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 7dc53a411a7d4ae286c60c6229bd1e395b0efb82

mlx_utils/color/color.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* color.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: yboudoui <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/11/20 13:28:23 by yboudoui #+# #+# */
9+
/* Updated: 2022/11/20 19:16:54 by yboudoui ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "color.h"
14+
15+
t_color create_trgb(t_chanel t, t_chanel r, t_chanel g, t_chanel b)
16+
{
17+
t_color out;
18+
19+
out.chanel[BLUE] = b;
20+
out.chanel[GREEN] = g;
21+
out.chanel[RED] = r;
22+
out.chanel[TRANSPARENCY] = t;
23+
return (out);
24+
}
25+
26+
t_color interpolate_color(t_color a, float t, t_color b)
27+
{
28+
t_color out;
29+
30+
out.chanel[0] = a.chanel[0] + (b.chanel[0] - a.chanel[0]) * t ;
31+
out.chanel[1] = a.chanel[1] + (b.chanel[1] - a.chanel[1]) * t ;
32+
out.chanel[2] = a.chanel[2] + (b.chanel[2] - a.chanel[2]) * t ;
33+
out.chanel[3] = a.chanel[3] + (b.chanel[3] - a.chanel[3]) * t ;
34+
return (out);
35+
}

mlx_utils/color/color.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* color.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: yboudoui <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/11/20 13:28:32 by yboudoui #+# #+# */
9+
/* Updated: 2023/04/24 17:08:49 by yboudoui ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef COLOR_H
14+
# define COLOR_H
15+
16+
typedef enum e_chanel_name {
17+
BLUE,
18+
GREEN,
19+
RED,
20+
TRANSPARENCY,
21+
} t_chanel_name;
22+
23+
typedef unsigned char t_chanel;
24+
25+
typedef union u_color {
26+
unsigned char chanel[4];
27+
unsigned int raw;
28+
} t_color;
29+
30+
t_color create_trgb(t_chanel t, t_chanel r, t_chanel g, t_chanel b);
31+
t_color interpolate_color(t_color a, float t, t_color b);
32+
33+
#endif

0 commit comments

Comments
 (0)