textures are working at snail speed
This commit is contained in:
parent
87eb97b21c
commit
7194cbfc83
4
Makefile
4
Makefile
@ -6,13 +6,13 @@
|
|||||||
# By: houtworm <codam@houtworm.net> +#+ #
|
# By: houtworm <codam@houtworm.net> +#+ #
|
||||||
# +#+ #
|
# +#+ #
|
||||||
# Created: 2023/10/26 10:46:29 by houtworm #+# #+# #
|
# Created: 2023/10/26 10:46:29 by houtworm #+# #+# #
|
||||||
# Updated: 2023/10/29 15:24:58 by houtworm ######## odam.nl #
|
# Updated: 2023/10/31 15:58:18 by houtworm ######## odam.nl #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
NAME =cub3d
|
NAME =cub3d
|
||||||
CC =gcc
|
CC =gcc
|
||||||
FC =-Wall -Werror -Wextra -Wunreachable-code -Ofast# -g -fsanitize=address
|
FC =-Wall -Werror -Wextra -Wunreachable-code -Ofast -g -fsanitize=address
|
||||||
HEAD =-I ./include -I $(MLX)/include
|
HEAD =-I ./include -I $(MLX)/include
|
||||||
RM =rm -rf
|
RM =rm -rf
|
||||||
LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
|
LIB =libft/libft.a getnextline/get_next_line.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
|
||||||
|
7
cub3d.h
7
cub3d.h
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
|
/* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/10/29 17:04:28 by houtworm ######## odam.nl */
|
/* Updated: 2023/10/31 15:22:33 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,12 +19,14 @@
|
|||||||
# include "libft/libft.h"
|
# include "libft/libft.h"
|
||||||
# include "getnextline/get_next_line.h"
|
# include "getnextline/get_next_line.h"
|
||||||
# include "mlx/include/MLX42/MLX42.h"
|
# include "mlx/include/MLX42/MLX42.h"
|
||||||
|
# include <stdio.h>
|
||||||
|
|
||||||
typedef struct s_varlist
|
typedef struct s_varlist
|
||||||
{
|
{
|
||||||
mlx_t *mlx;
|
mlx_t *mlx;
|
||||||
mlx_image_t *img;
|
mlx_image_t *img;
|
||||||
mlx_image_t *fps;
|
mlx_image_t *fps;
|
||||||
|
mlx_texture_t *curtext;
|
||||||
int fpsrefresh;
|
int fpsrefresh;
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
@ -38,6 +40,7 @@ typedef struct s_varlist
|
|||||||
double planey;
|
double planey;
|
||||||
double camerax;
|
double camerax;
|
||||||
double cameray;
|
double cameray;
|
||||||
|
int hoffset;
|
||||||
double raydirx;
|
double raydirx;
|
||||||
double raydiry;
|
double raydiry;
|
||||||
double movespeed;
|
double movespeed;
|
||||||
@ -49,6 +52,7 @@ typedef struct s_varlist
|
|||||||
double deltadistx;
|
double deltadistx;
|
||||||
double deltadisty;
|
double deltadisty;
|
||||||
double perpwalldist;
|
double perpwalldist;
|
||||||
|
int lineheight;
|
||||||
int stepx;
|
int stepx;
|
||||||
int stepy;
|
int stepy;
|
||||||
int hit;
|
int hit;
|
||||||
@ -58,6 +62,7 @@ typedef struct s_varlist
|
|||||||
double oldmouseposy; // only needed if we do vertical aiming
|
double oldmouseposy; // only needed if we do vertical aiming
|
||||||
int32_t fcolor;
|
int32_t fcolor;
|
||||||
int32_t ccolor;
|
int32_t ccolor;
|
||||||
|
uint32_t sbuffer; //??
|
||||||
char *northwt;
|
char *northwt;
|
||||||
char *eastwt;
|
char *eastwt;
|
||||||
char *southwt;
|
char *southwt;
|
||||||
|
43
src/draw.c
43
src/draw.c
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */
|
/* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/10/29 12:28:28 by houtworm ######## odam.nl */
|
/* Updated: 2023/10/31 16:17:59 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,14 +17,43 @@ void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend)
|
|||||||
int y;
|
int y;
|
||||||
|
|
||||||
y = 1;
|
y = 1;
|
||||||
|
while (y < drawstart)
|
||||||
|
{
|
||||||
|
mlx_put_pixel(vl->img, x, y, vl->ccolor);
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
double wallx;
|
||||||
|
if (vl->side == 0)
|
||||||
|
wallx = vl->posy + vl->perpwalldist * vl->raydiry;
|
||||||
|
else
|
||||||
|
wallx = vl->posx + vl->perpwalldist * vl->raydirx;
|
||||||
|
wallx -= floor(wallx);
|
||||||
|
int textx;
|
||||||
|
textx = wallx * 64.0;
|
||||||
|
if (vl->side == 0 && vl->raydirx > 0)
|
||||||
|
textx = 64 - textx - 1;
|
||||||
|
if (vl->side == 1 && vl->raydiry < 0)
|
||||||
|
textx = 64 - textx - 1;
|
||||||
|
double step;
|
||||||
|
step = 1.0 * 64 / vl->lineheight;
|
||||||
|
double textpos;
|
||||||
|
textpos = (drawstart - vl->hoffset - vl->h / 2 + vl->lineheight / 2) * step;
|
||||||
|
vl->curtext = mlx_load_png(vl->southwt);
|
||||||
|
while (y < drawend)
|
||||||
|
{
|
||||||
|
int texty;
|
||||||
|
texty = (int)textpos & (64 - 1);
|
||||||
|
textpos += step;
|
||||||
|
uint8_t *texel;
|
||||||
|
uint32_t color;
|
||||||
|
texel = &vl->curtext->pixels[(vl->curtext->width * texty + textx) * vl->curtext->bytes_per_pixel];
|
||||||
|
color = texel[0] << 24 | texel[1] << 16 | texel[2] << 8 | texel[3];
|
||||||
|
mlx_put_pixel(vl->img, x, y, color);
|
||||||
|
y++;
|
||||||
|
}
|
||||||
while (vl->h > y)
|
while (vl->h > y)
|
||||||
{
|
{
|
||||||
if (y < drawstart)
|
mlx_put_pixel(vl->img, x, y, vl->fcolor);
|
||||||
mlx_put_pixel(vl->img, x, y, vl->ccolor);
|
|
||||||
else if (y < drawend)
|
|
||||||
mlx_put_pixel(vl->img, x, y, 0x440000FF);
|
|
||||||
else
|
|
||||||
mlx_put_pixel(vl->img, x, y, vl->fcolor);
|
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */
|
/* Created: 2023/10/26 16:49:12 by houtworm #+# #+# */
|
||||||
/* Updated: 2023/10/29 17:17:54 by houtworm ######## odam.nl */
|
/* Updated: 2023/10/31 14:24:17 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ t_varlist initvarlist(void)
|
|||||||
|
|
||||||
vl.w = 800;
|
vl.w = 800;
|
||||||
vl.h = 600;
|
vl.h = 600;
|
||||||
|
vl.hoffset = 50;
|
||||||
vl.ccolor = 0;
|
vl.ccolor = 0;
|
||||||
vl.fcolor = 0;
|
vl.fcolor = 0;
|
||||||
vl.northwt = NULL;
|
vl.northwt = NULL;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: djonker <codam@houtworm.net> +#+ */
|
/* By: djonker <codam@houtworm.net> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2023/10/27 14:36:42 by djonker #+# #+# */
|
/* Created: 2023/10/27 14:36:42 by djonker #+# #+# */
|
||||||
/* Updated: 2023/10/29 14:23:45 by houtworm ######## odam.nl */
|
/* Updated: 2023/10/31 15:30:06 by houtworm ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,7 +15,6 @@
|
|||||||
void ft_raycast(t_varlist *vl)
|
void ft_raycast(t_varlist *vl)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
int lineheight;
|
|
||||||
int drawstart;
|
int drawstart;
|
||||||
int drawend;
|
int drawend;
|
||||||
|
|
||||||
@ -71,11 +70,11 @@ void ft_raycast(t_varlist *vl)
|
|||||||
vl->perpwalldist = (vl->sidedistx - vl->deltadistx);
|
vl->perpwalldist = (vl->sidedistx - vl->deltadistx);
|
||||||
else
|
else
|
||||||
vl->perpwalldist = (vl->sidedisty - vl->deltadisty);
|
vl->perpwalldist = (vl->sidedisty - vl->deltadisty);
|
||||||
lineheight = (int)vl->h / vl->perpwalldist;
|
vl->lineheight = vl->h / vl->perpwalldist;
|
||||||
drawstart = -lineheight / 2 + vl->h / 2;
|
drawstart = -vl->lineheight / 2 + vl->h / 2 + vl->hoffset;
|
||||||
if (drawstart < 0)
|
if (drawstart < 0)
|
||||||
drawstart = 0;
|
drawstart = 0;
|
||||||
drawend = lineheight / 2 + vl->h / 2;
|
drawend = vl->lineheight / 2 + vl->h / 2 + vl->hoffset;
|
||||||
if (drawend >= vl->h)
|
if (drawend >= vl->h)
|
||||||
drawend = vl->h - 1;
|
drawend = vl->h - 1;
|
||||||
ft_drawline(x, vl, drawstart, drawend);
|
ft_drawline(x, vl, drawstart, drawend);
|
||||||
|
Loading…
Reference in New Issue
Block a user