-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ys-zm/textures
Textures
- Loading branch information
Showing
29 changed files
with
343 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.vscode/ | ||
obj/ | ||
app | ||
app.dSYM | ||
compile_commands.json | ||
libft/build/libft.a | ||
Session.vim | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"files.associations": { | ||
"cstdlib": "c" | ||
"cstdlib": "c", | ||
"stdio.h": "c" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* :::::::: */ | ||
/* MLX42_Int.h :+: :+: */ | ||
/* MLX42_Int.h :+: :+: */ | ||
/* +:+ */ | ||
/* By: W2Wizard <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2021/12/27 23:55:34 by W2Wizard #+# #+# */ | ||
/* Updated: 2022/07/21 10:46:43 by sbos ######## odam.nl */ | ||
/* Updated: 2024/01/17 12:49:14 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -34,7 +34,7 @@ | |
# include <stdarg.h> /* va_arg, va_end, ... */ | ||
# include <assert.h> /* assert, static_assert, ... */ | ||
# ifndef MLX_SWAP_INTERVAL | ||
# define MLX_SWAP_INTERVAL 1 | ||
# define MLX_SWAP_INTERVAL 0 | ||
# endif | ||
# ifndef MLX_BATCH_SIZE | ||
# define MLX_BATCH_SIZE 12000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/**/ | ||
/* :::::::: */ | ||
/* meta.h:+::+: */ | ||
/* meta.h :+: :+: */ | ||
/*+:+ */ | ||
/* By: jboeve <[email protected]>+#+ */ | ||
/* +#+ */ | ||
/* Created: 2023/11/01 20:07:37 by jboeve#+##+# */ | ||
/* Updated: 2024/01/07 03:51:44 by joppe ######## odam.nl */ | ||
/* Updated: 2024/01/18 11:56:06 by jboeve ######## odam.nl */ | ||
/**/ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -56,8 +56,6 @@ | |
#define WINDOW_WIDTH 1280 | ||
#define WINDOW_HEIGHT 720 | ||
|
||
#define WINDOW_TITLE "Gammoe" | ||
|
||
|
||
|
||
// Game | ||
|
@@ -110,7 +108,7 @@ typedef struct s_font_atlas | |
unsigned int font_w; | ||
unsigned int font_h; | ||
unsigned int bpp; | ||
char *pixels; | ||
char *pixels; | ||
} t_font_atlas; | ||
|
||
|
||
|
@@ -128,17 +126,25 @@ typedef union s_rgba | |
|
||
|
||
typedef enum e_side { | ||
HIT_NONE, | ||
HIT_NS, | ||
HIT_EW, | ||
SIDE_N, | ||
SIDE_S, | ||
SIDE_E, | ||
SIDE_W, | ||
} t_side; | ||
|
||
typedef struct s_ray { | ||
t_vec2d direction; | ||
t_vec2d end; | ||
t_side hit_side; | ||
double length; | ||
double wall_x; | ||
t_vec2d direction; | ||
t_vec2d end; | ||
t_vec2i map_pos; | ||
t_vec2i texture_point; | ||
t_vec2i line_point; | ||
t_side hit_side; | ||
|
||
double line_height; | ||
double length; | ||
double wall_x; | ||
double texture_position; | ||
double step; | ||
} t_ray; | ||
|
||
typedef struct s_player { | ||
|
@@ -158,14 +164,21 @@ typedef struct s_map { | |
char player_start_dir; | ||
} t_map; | ||
|
||
|
||
typedef struct s_tex { | ||
char *no; | ||
char *so; | ||
char *we; | ||
char *ea; | ||
char *tex_path; | ||
mlx_texture_t *tex; | ||
} t_tex; | ||
|
||
typedef struct s_attr { | ||
t_tex n; | ||
t_tex s; | ||
t_tex e; | ||
t_tex w; | ||
t_rgba floor_c; | ||
t_rgba ceiling_c; | ||
} t_tex; | ||
} t_attr; | ||
|
||
|
||
typedef struct s_minimap { | ||
mlx_image_t *minimap_image; | ||
|
@@ -183,7 +196,8 @@ typedef struct s_meta { | |
t_player player; | ||
uint32_t fps; | ||
t_map map; | ||
t_tex tex; | ||
t_attr attributes; | ||
const char *scene_name; | ||
char *map_element; | ||
} t_meta; | ||
|
||
|
@@ -231,9 +245,17 @@ t_ray raycaster_cast(t_vec2d pp, t_vec2d dir, t_ray_hitfunc hit, const void *pa | |
|
||
// colors.c | ||
int32_t set_color(int32_t r, int32_t g, int32_t b, int32_t a); | ||
int32_t find_wall_color(t_side side); | ||
int32_t find_wall_color(t_attr atrributes, t_ray *ray, t_vec2i line_points, uint32_t h); | ||
int32_t find_color(t_rgba rgba); | ||
|
||
// free.c | ||
void meta_free(t_meta *meta); | ||
|
||
// set_textures.c | ||
int set_textures(t_attr *attributes); | ||
|
||
//pixel_picker.c | ||
uint32_t pixel_picker(mlx_texture_t *texture, int32_t x, int32_t y); | ||
void wall_texture_position(mlx_texture_t *texture, t_ray *ray, t_vec2i line_points, uint32_t h); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* cub3d.c :+: :+: :+: */ | ||
/* cub3d.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:24:47 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:25:06 by yzaim ### ########.fr */ | ||
/* Updated: 2024/01/18 10:45:29 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "MLX42/MLX42.h" | ||
#include "MLX42/MLX42_Int.h" | ||
#include "meta.h" | ||
#include "parser.h" | ||
#include <stdint.h> | ||
|
@@ -51,7 +52,7 @@ void leaks(void) | |
// change to create a different image for the minimap vs. main viewport | ||
int init_mlx_images(t_meta *meta) | ||
{ | ||
meta->mlx = mlx_init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, true); | ||
meta->mlx = mlx_init(WINDOW_WIDTH, WINDOW_HEIGHT, meta->scene_name, true); | ||
if (!meta->mlx) | ||
{ | ||
ft_error(); | ||
|
@@ -93,7 +94,7 @@ int init_mlx_images(t_meta *meta) | |
} | ||
|
||
return (EXIT_SUCCESS); | ||
} | ||
} | ||
|
||
int cub3d(int argc, char **argv) | ||
{ | ||
|
@@ -104,8 +105,15 @@ int cub3d(int argc, char **argv) | |
ft_bzero(&meta, sizeof(t_meta)); | ||
if (parser(&meta, argv[1])) | ||
return(meta_free(&meta), EXIT_FAILURE); | ||
// TODO Error check. | ||
if (set_textures(&meta.attributes)) | ||
return (EXIT_FAILURE); | ||
printf("Tex_N: %s\n", meta.attributes.n.tex_path); | ||
printf("Tex_S: %s\n", meta.attributes.s.tex_path); | ||
printf("Tex_E: %s\n", meta.attributes.e.tex_path); | ||
printf("Tex_W: %s\n", meta.attributes.w.tex_path); | ||
|
||
init_mlx_images(&meta); | ||
// TODO Error check. | ||
game_init(&meta); | ||
mlx_set_cursor_mode(meta.mlx, MLX_MOUSE_HIDDEN); | ||
mlx_loop_hook(meta.mlx, game_loop, &meta); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
/* ************************************************************************** */ | ||
/**/ | ||
/* :::::::: */ | ||
/* font_renderer.c :+::+: */ | ||
/*+:+ */ | ||
/* By: joppe <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/05 00:02:23 by joppe #+##+# */ | ||
/* Updated: 2024/01/07 03:28:05 by joppe ######## odam.nl */ | ||
/**/ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* game.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:26:51 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:29:57 by yzaim ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
/** | ||
* This file is basically a copy of the `mlx_font.c` | ||
* but with the ability to specifiy what font to draw. | ||
*/ | ||
|
||
#include "MLX42/MLX42_Int.h" | ||
// #include "MLX42/MLX42_Int.h" | ||
#include "font_dejavu_14.h" | ||
#include "font_comicsans.h" | ||
#include "font_mlx.h" | ||
|
@@ -72,7 +72,7 @@ mlx_image_t *cube_put_string(mlx_image_t *image, const char *s, const t_font_atl | |
|
||
if (image_len != image->width) | ||
{ | ||
ft_bzero(image->pixels, image->width * image->height * BPP); | ||
ft_bzero(image->pixels, image->width * image->height * sizeof(int32_t)); | ||
if (!mlx_resize_image(image, image_len, atlas->font_h)) | ||
return (NULL); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* game.c :+: :+: :+: */ | ||
/* game.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:26:51 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:29:57 by yzaim ### ########.fr */ | ||
/* Updated: 2024/01/17 13:04:46 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* player.c :+: :+: :+: */ | ||
/* player.c :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:27:23 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/08 15:27:25 by yzaim ### ########.fr */ | ||
/* Updated: 2024/01/17 15:55:18 by jboeve ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -39,6 +39,7 @@ void player_move(t_player *p, t_vec2d transform) | |
new_position.x = (p->position.x + (transform.x)); | ||
new_position.y = (p->position.y + (transform.y)); | ||
|
||
// TODO Fix. | ||
t_ray r = raycaster_cast(p->position, vec2d_normalize(transform), bound_check, p->meta); | ||
// print_ray("bound_ray", &r); | ||
|
||
|
@@ -72,6 +73,7 @@ void player_raycast(t_player *p) | |
camera_x = (2 * col / ((double) w) - 1); | ||
ray_start = vec2d_add(p->direction, vec2d_scalar_product(p->cam_plane, camera_x)); | ||
p->rays[col] = raycaster_cast(p->position, ray_start, bound_check, p->meta); | ||
// printf("wall x: %f\n", p->rays[col].wall_x); | ||
col++; | ||
} | ||
} |
Oops, something went wrong.