This commit is contained in:
victor 2025-06-03 12:07:17 +02:00
parent afa223b09f
commit 3021eea6b9
1361 changed files with 12267700 additions and 6304 deletions

2
.gitignore vendored
View File

@ -1,3 +1 @@
/target
kernel-hd
*.o

View File

@ -33,26 +33,40 @@ services:
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/certs:/certs
- ./nginx/site:/var/www/html
- novnc:/opt/noVNC/
networks:
website_net:
ports:
- 5080:80
- 5443:443
website:
container_name: "site"
minirt:
container_name: "minirt-site"
restart: always
build:
context: ./vvsite
dockerfile: Dockerfile
build: ./miniRT
environment:
- DISPLAY=:1
ports:
- 6080:6080
- 5901:5901
networks:
website_net:
volumes:
- novnc:/opt/noVNC/
volumes:
novnc:
networks:
website_net:
external: true
# internal: true
driver: bridge

52
miniRT/.gitignore vendored Normal file
View File

@ -0,0 +1,52 @@
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

194
miniRT/Dockerfile Normal file
View File

@ -0,0 +1,194 @@
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
# Update with future time fix and install build dependencies
RUN apt-get -o Acquire::Max-FutureTime=86400 update -y --fix-missing
RUN apt-get install -y build-essential xorg libx11-dev libxext-dev libbsd-dev libpthread-stubs0-dev libasound2-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev
# Build the miniRT project
WORKDIR /best_rt
COPY . .
RUN make
# Install VNC and graphics dependencies
RUN apt-get update && apt-get install -y \
tigervnc-standalone-server \
python3 \
python3-pip \
wget \
git \
openbox \
x11-utils \
libgl1-mesa-dev \
libglu1-mesa-dev \
net-tools \
procps \
lsof \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install websockify
RUN pip3 install websockify --break-system-packages
# Install noVNC
RUN git clone https://github.com/novnc/noVNC.git /opt/noVNC
# Create VNC directory and set password
RUN mkdir -p /root/.vnc && \
echo "password" | vncpasswd -f > /root/.vnc/passwd && \
chmod 600 /root/.vnc/passwd
RUN rm /opt/noVNC/*.html
RUN mv /best_rt/vnc/minimal.html /opt/noVNC/vnc.html
RUN echo '<!DOCTYPE html>\n\
<html>\n\
<head>\n\
<title>miniRT</title>\n\
<style>\n\
body { margin: 0; padding: 0; background: #000; overflow: hidden; }\n\
iframe { width: 100vw; height: 100vh; border: none; }\n\
</style>\n\
</head>\n\
<body>\n\
<iframe src="/clean.html"></iframe>\n\
</body>\n\
</html>' > /opt/noVNC/minimal.html
# Create VNC startup script that keeps session alive
RUN echo '#!/bin/bash\n\
export USER=root\n\
export HOME=/root\n\
xsetroot -solid grey\n\
# Start openbox to keep session alive\n\
openbox-session &\n\
# Keep the session running\n\
while true; do sleep 3600; done\n\
' > /root/.vnc/xstartup && chmod +x /root/.vnc/xstartup
# Create connection monitor script
RUN echo '#!/bin/bash\n\
\n\
APP_PID=""\n\
CLIENT_TIMEOUT=30 # Stop app after 30 seconds of no clients\n\
CHECK_INTERVAL=5 # Check every 5 seconds\n\
\n\
log() {\n\
echo "[$(date "+%H:%M:%S")] $1"\n\
}\n\
\n\
has_vnc_clients() {\n\
# Check for active VNC connections\n\
netstat -tn 2>/dev/null | grep -q ":5901.*ESTABLISHED"\n\
}\n\
\n\
has_websocket_clients() {\n\
# Check for active WebSocket connections (noVNC)\n\
netstat -tn 2>/dev/null | grep -q ":6080.*ESTABLISHED"\n\
}\n\
\n\
start_app() {\n\
if [ -z "$APP_PID" ] || ! kill -0 "$APP_PID" 2>/dev/null; then\n\
log "Starting miniRT application..."\n\
cd /best_rt\n\
/best_rt/miniRT /best_rt/scenes/multilight.rt &\n\
APP_PID=$!\n\
log "miniRT started with PID: $APP_PID"\n\
fi\n\
}\n\
\n\
stop_app() {\n\
if [ -n "$APP_PID" ] && kill -0 "$APP_PID" 2>/dev/null; then\n\
log "Stopping miniRT application (PID: $APP_PID)..."\n\
kill "$APP_PID" 2>/dev/null\n\
wait "$APP_PID" 2>/dev/null\n\
APP_PID=""\n\
log "miniRT stopped"\n\
fi\n\
}\n\
\n\
# Main monitoring loop\n\
last_client_time=0\n\
\n\
while true; do\n\
current_time=$(date +%s)\n\
\n\
if has_vnc_clients || has_websocket_clients; then\n\
# Client connected\n\
last_client_time=$current_time\n\
start_app\n\
else\n\
# No clients\n\
if [ "$last_client_time" -gt 0 ]; then\n\
time_since_last_client=$((current_time - last_client_time))\n\
if [ "$time_since_last_client" -gt "$CLIENT_TIMEOUT" ]; then\n\
stop_app\n\
last_client_time=0\n\
fi\n\
fi\n\
fi\n\
\n\
sleep "$CHECK_INTERVAL"\n\
done\n\
' > /monitor-clients.sh && chmod +x /monitor-clients.sh
# Create a simple mime.types file for websockify
RUN echo 'text/html html htm shtml;\n\
application/javascript js;\n\
text/css css;\n\
image/png png;\n\
image/jpeg jpg jpeg;\n\
image/gif gif;\n\
image/svg+xml svg;\n\
' > /opt/noVNC/mime.types
# Create smart startup script
RUN echo '#!/bin/bash\n\
export USER=root\n\
export HOME=/root\n\
export DISPLAY=:1\n\
\n\
log() {\n\
echo "[$(date "+%H:%M:%S")] $1"\n\
}\n\
\n\
log "Starting VNC server..."\n\
vncserver :1 -geometry 1920x1080 -depth 24 -localhost no\n\
sleep 5\n\
\n\
log "Starting noVNC web interface..."\n\
cd /opt/noVNC\n\
python3 -m websockify 6080 localhost:5901 &\n\
NOVNC_PID=$!\n\
\n\
sleep 3\n\
xhost + 2>/dev/null || true\n\
\n\
log "VNC ready at http://localhost:6080/vnc.html"\n\
log "Starting client monitor..."\n\
log "miniRT will start automatically when a client connects"\n\
log "miniRT will stop automatically when no clients for 30 seconds"\n\
\n\
# Start the client monitor\n\
/monitor-clients.sh &\n\
MONITOR_PID=$!\n\
\n\
# Handle cleanup on exit\n\
cleanup() {\n\
log "Shutting down..."\n\
kill $NOVNC_PID 2>/dev/null\n\
kill $MONITOR_PID 2>/dev/null\n\
vncserver -kill :1 2>/dev/null\n\
exit 0\n\
}\n\
\n\
trap cleanup SIGTERM SIGINT\n\
\n\
# Wait for processes\n\
wait\n\
' > /start.sh && chmod +x /start.sh
EXPOSE 6080 5901
CMD ["/start.sh"]

123
miniRT/Makefile Normal file
View File

@ -0,0 +1,123 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: bszilas <bszilas@student.42vienna.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/08 16:30:33 by victor #+# #+# #
# Updated: 2025/06/02 12:04:19 by victor ### ########.fr #
# #
# **************************************************************************** #
CC := cc
CFLAGS := -Wall -Werror -Wextra -g3
LDFLAGS := -lm
NAME := miniRT
SRCDIR := src
SRC := minirt.c
SCENEDIR := scene
SRCSCENE := $(addprefix $(SCENEDIR)/, $(addsuffix .c,\
camera camera_info camera_ray_define \
light scene scene_create sphere sphere_calc \
cylinder cylinder_info cylinder_calc cylinder_uv \
disk disk_calc plane plane_calc add_body \
cone_tracing cone_utils cone_info))
RENDERDIR := rendering
SRCRENDER := $(addprefix $(RENDERDIR)/, $(addsuffix .c,\
rendering image pixel ray_utils color drawing threads \
color2 light_shadow phong))
IODIR := io
SRCIO := $(addprefix $(IODIR)/, $(addsuffix .c,\
ppm id bump mouse_press mouse key_press keys parsing2 parsing glyph \
item_value_manip items_create menu slider container \
key_change_scene buffer menu_body_create menu_body_map \
menu_value_add menu_value_map explorer explorer_helper \
explorer_load_file menu_file_map))
UTILDIR := utils
SRCUTIL := $(addprefix $(UTILDIR)/, $(addsuffix .c,\
minirt_utils vector_math2 vector_math vector \
detect_overflow_utils detect_overflow))
LIBS := libft/libft.a memory/memory.a raylib/src/libraylib.a
MAP := mapgen
OBJDIR := obj
OBJ := $(SRC:%.c=$(OBJDIR)/%.o)
OBJRENDER := $(SRCRENDER:%.c=$(OBJDIR)/%.o)
OBJSCENE := $(SRCSCENE:%.c=$(OBJDIR)/%.o)
OBJIO := $(SRCIO:%.c=$(OBJDIR)/%.o)
OBJUTIL := $(SRCUTIL:%.c=$(OBJDIR)/%.o)
ifdef DEBUG
CFLAGS += -D VALGRIND
CFLAGS += -g3
else
CFLAGS += -O3
endif
all: $(OBJDIR) $(NAME)
$(NAME): $(OBJ) $(LIBS) minirt.h $(OBJIO) $(OBJSCENE) $(OBJUTIL) $(OBJRENDER)
$(CC) $(CFLAGS) -o $@ $(OBJ) $(OBJIO) $(OBJSCENE) $(OBJUTIL) $(OBJRENDER) $(LIBS) $(LDFLAGS)
$(OBJDIR)/%.o: $(SRCDIR)/$(SCENEDIR)/%.c minirt.h
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/$(RENDERDIR)/%.c minirt.h
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/$(UTILDIR)/%.c minirt.h
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/$(IODIR)/%.c minirt.h
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.c minirt.h
$(CC) $(CFLAGS) -c $< -o $@
$(MAP): src/mapgeb/map_gen_buffer.c src/mapgeb/map.c
make all
$(CC) $(CFLAGS) $^ src/io/buffer.c $(LIBS) -o $@ -lm
$(LIBS):
make -C libft
make -C memory
make -C libft/printf
make -C raylib/src PLATFORM=PLATFORM_DESKTOP
$(OBJDIR):
mkdir -p $(OBJDIR) $(OBJDIR)/$(SRCDIR) $(OBJDIR)/$(RENDERDIR) $(OBJDIR)/$(IODIR) $(OBJDIR)/$(UTILDIR) $(OBJDIR)/$(SCENEDIR)
docker-build: all
docker build -t miniRT .
docker-run: docker-build
docker run -d -p 6080:6080 -p 5901:5901 miniRT:latest
clean:
rm -rf $(OBJDIR)
make clean -C libft
make clean -C memory
make clean -C libft/printf
make clean -C raylib/src
fclean: clean
rm -rf $(NAME) $(MAP)
make fclean -C libft
make fclean -C memory
make fclean -C libft/printf
re: fclean all
.PHONY: all clean fclean re debug

121
miniRT/README.md Normal file
View File

@ -0,0 +1,121 @@
This minimalistic raytracing engine is a school project which is still ongoing.
It is using the [Minilibx library](https://github.com/42Paris/minilibx-linux).
All code besides the directory minilibx-linux is our work.
Big thanks to my teammate [vman101](https://github.com/vman101) for implementing many fantastic creative ideas that go way beyond the scope of what is required by the school.
Credits go to him for his libft and his garbage collector in the memory directory.
We are still working on this fun raytracing engine so there is more to come!
# Run in a Docker container:
```bash
git clone git@github.com:Fapad/miniRT.git
cd miniRT
docker build -t minirt .
docker run --rm -e DISPLAY="$DISPLAY" -v /tmp/.X11-unix:/tmp/.X11-unix minirt
```
If you get the error "Authorization required, but no authorization protocol specified", you might need to enable X11 forwarding locally
```bash
xhost + local:
docker run --rm -e DISPLAY="$DISPLAY" -v /tmp/.X11-unix:/tmp/.X11-unix minirt
```
# Or compile with make
## 1. Required Dependencies
```bash
sudo apt-get update
sudo apt-get install build-essential libpthread-stubs0-dev xorg libx11-dev libxext-dev libbsd-dev
```
## 2. clone the repo and compile
```bash
git clone git@github.com:Fapad/miniRT.git
cd miniRT
make
```
## 3. launch the executable
either without arguments,
```bash
./miniRT
```
or with the path to a specific scene file as argument
```bash
./miniRT scenes/eclipse.rt
```
# Navigation:
change resolution/anti-aliasing: numpad + or -
move camera or object: WASDQE
rotate camera or object: arrow keys
change object color, reflection, texture: use object menu
object menu: right click
undo object selection: left click
move object on xy axis: lmb + drag
add object: click menu item
change field of view: mouse wheel
# the .rt file describes a 3d scene
◦ Each type of information from an element can be separated by one or more
space(s).
◦ Each type of element can be set in any order in the file.
◦ Elements which are defined by a capital letter can only be declared once in
the scene.
Each element firsts information is the type identifier (composed by one or two character(s)), followed by all specific information for each object in a strict order such as:
◦ Ambient lightning:
identifier: A
ambient lighting ratio in range [0.0,1.0]: 0.2 R,G,B colors in range [0-255]: 255, 255, 255
◦ Camera:
identifier: C
x,y,z coordinates of the view point: -50.0,0,20
orientation vector for each x,y,z axis:
0.0,0.0,1.0
FOV : Horizontal field of view in degrees in range [0,180]: 70
◦ Light:
identifier: L
x,y,z coordinates of the light point: -40.0,50.0,0.0
the light brightness ratio in range [0.0,1.0]: 0.6
(unused in mandatory part)R,G,B colors in range [0-255]: 10, 0, 255
◦ Sphere:
identifier: sp
x,y,z coordinates of the sphere center: 0.0,0.0,20.6 the sphere diameter: 12.6
R,G,B colors in range [0-255]: 10, 0, 255
◦ Plane:
identifier: pl
x,y,z coordinates of a point in the plane: 0.0,0.0,-10.0
3d vector perpendicular to the plane. for each x,y,z axis: 0.0,1.0,0.0 R,G,B colors in range [0-255]: 0,0,225
◦ Cylinder:
identifier: cy
x,y,z coordinates of the center of the cylinder: 50.0,0.0,20.6
3D vector x,y,z of axis of cylinder
the cylinder diameter: 14.2
the cylinder height: 21.42
R,G,B colors in range [0,255]: 10, 0, 255
Cone:
identifier: cn
x,y,z coordinates of the vertex of the cone: 50.0,0.0,20.6
3D vector x,y,z of axis of cone
the diameter of the bottom disk of the cone: 14.2
the cone height: 21.42
R,G,B colors in range [0,255]: 10, 0, 255

View File

@ -0,0 +1,647 @@
000000
000000
000000
000000
000000
000000
000000
000000
001000
001000
001000
001000
000000
001000
000000
010100
010100
000000
000000
000000
000000
000000
010100
111110
010100
111110
010100
010100
001000
011110
101000
011100
001010
111100
001000
000000
110010
110100
001000
010110
100110
000000
000000
011000
100100
101000
010100
100010
011100
000000
001000
001000
000000
000000
000000
000000
000000
000100
001000
001000
001000
001000
000100
000000
001000
000100
000100
000100
000100
001000
000000
000000
010100
001000
111110
001000
010100
000000
000000
001000
001000
111110
001000
001000
000000
000000
000000
000000
001000
001000
010000
000000
000000
000000
111110
000000
000000
000000
000000
000000
000000
000000
000000
001100
001100
000000
000010
000100
001000
010000
100000
000000
000000
011100
100010
100110
101010
110010
011100
000000
001000
011000
001000
001000
001000
011100
000000
011100
100010
000010
001100
010000
111110
000000
011100
100010
000100
000010
100010
011100
000000
000100
001100
010100
100100
111110
000100
000000
111110
100000
111100
000010
000010
111100
000000
011110
100000
111100
100010
100010
011100
000000
111110
000010
000100
001000
001000
001000
000000
011100
100010
011100
100010
100010
011100
000000
011100
100010
100010
011110
000010
111100
000000
011100
100010
100010
111110
100010
100010
000000
111100
100010
111100
100010
100010
111100
000000
011110
100000
100000
100000
100000
011110
000000
111100
100010
100010
100010
100010
111100
000000
111110
100000
111100
100000
100000
111110
000000
111110
100000
111100
100000
100000
100000
000000
011110
100000
100000
100110
100010
011110
000000
100010
100010
111110
100010
100010
100010
000000
011100
001000
001000
001000
001000
011100
000000
000110
000010
000010
000010
100010
011100
000000
100010
100100
111000
100100
100010
100010
000000
100000
100000
100000
100000
100000
111110
000000
100010
110110
101010
100010
100010
100010
000000
100010
110010
101010
100110
100010
100010
000000
011100
100010
100010
100010
100010
011100
000000
111100
100010
111100
100000
100000
100000
000000
011100
100010
100010
100010
101010
011100
000000
111100
100010
111100
100100
100010
100010
000000
011110
100000
011100
000010
000010
111100
000000
111110
001000
001000
001000
001000
001000
000000
100010
100010
100010
100010
100010
011100
000000
100010
100010
100010
100010
010100
001000
000000
100010
100010
100010
101010
110110
100010
000000
100010
010100
001000
010100
100010
100010
000000
100010
010100
001000
001000
001000
001000
000000
111110
000010
000100
001000
010000
111110
000000
000000
011110
000010
011110
100010
011110
000000
100000
100000
111100
100010
100010
111100
000000
000000
011100
100010
100000
100010
011100
000000
000010
000010
011110
100010
100010
011110
000000
000000
011100
100010
111110
100000
011110
000000
011100
100010
100000
111100
100000
100000
000000
000000
011110
100010
011110
000010
011100
000000
100000
100000
101100
110010
100010
100010
000000
110000
000000
111000
100000
100000
100000
000000
001100
000000
001100
000100
100100
011000
000000
100100
101000
110000
111000
100100
100010
000000
100000
100000
100000
100000
100010
011100
000000
000000
110100
101010
101010
101010
101010
000000
000000
101100
110010
100010
100010
100010
000000
000000
011100
100010
100010
100010
011100
000000
000000
111100
100010
111100
100000
100000
000000
000000
011110
100010
011110
000010
000010
000000
000000
101100
110010
100000
100000
100000
000000
000000
011110
100000
011100
000010
111100
000000
000000
010000
111100
010000
010010
001100
000000
000000
100010
100010
100010
100010
011100
000000
000000
100010
100010
100010
010100
001000
000000
000000
100010
100010
101010
101010
010100
000000
000000
100010
010100
001000
010100
100010
000000
000000
100010
011110
000010
100010
011100
000000
000000
111110
000100
001000
010000
111110
000000
000000
000000
000000
000000
000000
111110
000000
000000
000000
010000
000000
010000
000000
000000
000000
111110
000000
111110
000000
000000

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1500005
miniRT/assets/textures/earth.ppm Normal file

File diff suppressed because it is too large Load Diff

4300804
miniRT/assets/textures/marble.ppm Normal file

File diff suppressed because it is too large Load Diff

327813
miniRT/assets/textures/moon.ppm Normal file

File diff suppressed because it is too large Load Diff

3056980
miniRT/assets/textures/sky.ppm Normal file

File diff suppressed because it is too large Load Diff

11
miniRT/include/types.h Normal file
View File

@ -0,0 +1,11 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: victor </var/spool/mail/victor> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/08 16:38:11 by victor #+# #+# */
/* Updated: 2024/10/06 18:25:41 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -0,0 +1,29 @@
services:
postgres_key:
container_name: postgres_key
image: postgres:alpine
environment:
- POSTGRES_USER=keycloak_user
- POSTGRES_PASSWORD=keycloak_password
- POSTGRES_DB=keycloak_db
networks:
keycloak-shared-network:
ports:
- "15432:15432"
volumes:
- keycloak_data:/var/lib/postgresql/data
- ./postgres/logs:/var/logs/postgres
volumes:
keycloak_data:
networks:
jobited-net:
driver: bridge
keycloak-shared-network:
external: true

72
miniRT/libft/Makefile Normal file
View File

@ -0,0 +1,72 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: vvobis <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/17 14:23:19 by vvobis #+# #+# #
# Updated: 2025/05/31 12:28:02 by victor ### ########.fr #
# #
# **************************************************************************** #
NAME := libft.a
CC := cc
CFLAGS:= -Wall -Wextra -Werror
SRC := ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isdigit.c \
ft_isprint.c ft_memcpy.c ft_memmove.c ft_memset.c \
ft_strlcat.c ft_strlcpy.c ft_strlen.c \
ft_isascii.c ft_strchr.c ft_strrchr.c ft_strncmp.c \
ft_toupper.c ft_tolower.c ft_memchr.c ft_strnstr.c \
ft_atoi.c ft_atod.c ft_memcmp.c ft_calloc.c ft_strdup.c \
ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c \
ft_itoa.c ft_strmapi.c ft_striteri.c ft_putchar_fd.c \
ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \
ft_isspace.c ft_free.c ft_read.c
SRCGNL := gnl/get_next_line.c gnl/get_next_line_utils.c
SRCPRINT := printf/ft_fprintf.c printf/ft_printf.c printf/ft_putascii.c printf/ft_putptr.c printf/ft_puthex.c printf/ft_putfloat.c
SRCBON := ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c
OBJBON := $(SRCBON:%.c=%.o)
OBJ := $(SRC:%.c=%.o)
OBJGNL := $(SRCGNL:%.c=%.o)
OBJPRINT := $(SRCPRINT:%.c=%.o)
LIBS := printf
all: $(NAME)
bonus: $(OBJBON) $(OBJ)
ar rcs libft.a $(OBJ) $(OBJBON)
$(NAME): $(OBJ) $(OBJGNL) $(OBJPRINT) $(LIBS)
ar rcs libft.a $(OBJ) $(OBJGNL) $(OBJPRINT)
$(LIBS):
make -C $(LIBS)
%.o: %.c
$(CC) -c $(CFLAGS) $^ -o $@
re: fclean all
so:
$(CC) -fPIC $(CFLAGS) $(SRC) test.c
gcc -shared -o libft.so $(OBJ) $(OBJBON)
fclean: clean
rm -f $(NAME)
make fclean -C $(LIBS)
clean:
rm -f $(OBJ) $(OBJBON) $(OBJGNL)
make clean -C $(LIBS)

57
miniRT/libft/ft_atod.c Normal file
View File

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: victor </var/spool/mail/victor> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/08 22:25:35 by victor #+# #+# */
/* Updated: 2024/12/05 20:08:42 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
double atod_collect_fraction(char *n, double d)
{
int period;
int mult;
mult = 1;
period = 0;
while (*n && !ft_isspace(*n))
{
if (*n == '.' && period == 0)
{
period = 1;
n++;
continue ;
}
else if (((*n == '.' && period == 1) || (*n != '.' && !ft_isdigit(*n))))
return (ft_putendl_fd("Invalid double format: Too many periods", \
2), exit(1), 0);
if (period)
mult *= 10;
d *= 10;
d += (*n - '0');
n++;
}
return (d / mult);
}
double ft_atod(char *n)
{
double d;
int sign;
if (!n)
exit(1);
sign = 1;
if (*n == '-')
{
sign = -1;
n++;
}
d = 0;
return (atod_collect_fraction(n, d) * sign);
}

60
miniRT/libft/ft_atoi.c Normal file
View File

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bszilas <bszilas@student.42vienna.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/10 10:49:04 by vvobis #+# #+# */
/* Updated: 2024/09/13 22:19:12 by bszilas ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int is_space(char const c)
{
if ((c >= 9 && c <= 13) || c == ' ')
return (1);
return (0);
}
int ft_atoi(char const *s)
{
int nb;
char const *tmp;
nb = 0;
while (is_space(*s))
s++;
tmp = s;
if (*tmp == '+' || *tmp == '-')
tmp++;
while (*tmp >= '0' && *tmp <= '9')
{
nb *= 10;
nb += (*tmp - '0');
tmp++;
}
if (*s == '-')
nb = -nb;
return (nb);
}
long ft_atol(const char *nptr)
{
int64_t n;
int sign;
n = 0;
sign = 1;
while (ft_isspace(*nptr))
nptr++;
if (*nptr == '-')
sign = -1;
if (sign == -1 || *nptr == '+')
nptr++;
while (*nptr >= '0' && *nptr <= '9')
n = n * 10 + (*nptr++ - '0');
return (n * sign);
}

19
miniRT/libft/ft_bzero.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 16:04:55 by vvobis #+# #+# */
/* Updated: 2024/04/09 20:54:53 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
while (n--)
*(char *)s++ = 0;
}

30
miniRT/libft/ft_calloc.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 13:44:00 by vvobis #+# #+# */
/* Updated: 2024/04/10 16:39:56 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t n, size_t s)
{
char *tmp;
unsigned long i;
i = 0;
if (n == 0)
return (malloc(0));
if (SIZE_MAX / n < s)
return (NULL);
tmp = malloc(n * s);
if (tmp)
while (i < n * s)
tmp[i++] = 0;
return ((void *)tmp);
}

22
miniRT/libft/ft_free.c Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/10 12:16:39 by vvobis #+# #+# */
/* Updated: 2024/09/10 12:17:34 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_free(void *ptr_ptr)
{
void **ptr;
ptr = ptr_ptr;
free(*ptr);
*ptr = NULL;
}

20
miniRT/libft/ft_isalnum.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 15:59:18 by vvobis #+# #+# */
/* Updated: 2024/04/02 15:59:23 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
if (ft_isdigit(c) || ft_isalpha(c))
return (1);
return (0);
}

20
miniRT/libft/ft_isalpha.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 15:59:49 by vvobis #+# #+# */
/* Updated: 2024/04/02 16:00:04 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalpha(int c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return (1);
return (0);
}

20
miniRT/libft/ft_isascii.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 19:48:35 by vvobis #+# #+# */
/* Updated: 2024/04/02 19:49:36 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
return (0);
}

18
miniRT/libft/ft_isdigit.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 16:14:56 by vvobis #+# #+# */
/* Updated: 2024/04/02 19:38:45 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
}

18
miniRT/libft/ft_isprint.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 16:00:49 by vvobis #+# #+# */
/* Updated: 2024/04/02 16:00:52 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isprint(int c)
{
if (c >= 32 && c <= 126)
return (1);
return (0);
}

18
miniRT/libft/ft_isspace.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isspace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: victor </var/spool/mail/victor> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/08 18:27:49 by victor #+# #+# */
/* Updated: 2024/12/16 16:34:17 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isspace(int c)
{
return (c == ' ' || (c >= 9 && c < 14));
}

75
miniRT/libft/ft_itoa.c Normal file
View File

@ -0,0 +1,75 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/05 20:16:48 by vvobis #+# #+# */
/* Updated: 2024/04/11 14:48:59 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int get_len(int n)
{
int i;
if (n < 0)
n = -n;
i = 0;
while (n)
{
i++;
n /= 10;
}
return (i);
}
static char *is_negative(int n)
{
int i;
char *num;
i = get_len(n);
num = malloc(sizeof(*num) * i + 2);
if (!num)
return (NULL);
num[i + 1] = 0;
while (n)
{
num[i--] = -(n % 10) + 48;
n /= 10;
}
num[i] = 0x2d;
return (num);
}
static char *is_positive(int n)
{
int i;
char *num;
i = get_len(n);
num = malloc(sizeof(*num) * i + 1);
if (!num)
return (NULL);
num[i--] = 0;
while (n)
{
num[i--] = (n % 10) + 48;
n /= 10;
}
return (num);
}
char *ft_itoa(int n)
{
if (n == 0)
return (ft_strdup("0"));
else if (n < 0)
return (is_negative(n));
else
return (is_positive(n));
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 13:51:32 by vvobis #+# #+# */
/* Updated: 2024/04/09 18:17:12 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *tmp;
if (!new)
return ;
if (*lst)
{
tmp = *lst;
while (tmp->next)
tmp = tmp->next;
tmp->next = new;
}
else
*lst = new;
}

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 12:53:08 by vvobis #+# #+# */
/* Updated: 2024/04/09 18:17:50 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (!lst || !new)
return ;
if (!*lst)
*lst = new;
else
{
new->next = *lst;
*lst = new;
}
}

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:44:23 by vvobis #+# #+# */
/* Updated: 2024/04/09 22:35:41 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *tmp;
if (!*lst || !del || !lst)
return ;
while (*lst)
{
tmp = (*lst)->next;
del((*lst)->content);
free(*lst);
*lst = tmp;
}
}

View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 14:24:03 by vvobis #+# #+# */
/* Updated: 2024/04/09 15:42:04 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (!lst || !del)
return ;
del(lst->content);
free(lst);
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 15:57:51 by vvobis #+# #+# */
/* Updated: 2024/04/09 18:20:05 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!lst || !f)
return ;
while (lst)
{
f(lst->content);
lst = lst->next;
}
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 13:47:08 by vvobis #+# #+# */
/* Updated: 2024/04/09 15:11:51 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}

View File

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 16:18:03 by vvobis #+# #+# */
/* Updated: 2024/04/09 23:40:57 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void *free_list(t_list **head, void (*del)(void *), void *fcontent)
{
if (fcontent)
del(fcontent);
ft_lstclear(head, del);
return (NULL);
}
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *tmp;
t_list *head;
void *fcontent;
if (!lst || !f || !del)
return (NULL);
head = NULL;
while (lst)
{
fcontent = f(lst->content);
if (!fcontent)
return (free_list(&head, del, fcontent));
tmp = ft_lstnew(fcontent);
if (!tmp)
return (free_list(&head, del, fcontent));
ft_lstadd_back(&head, tmp);
lst = lst->next;
}
return (head);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 11:10:05 by vvobis #+# #+# */
/* Updated: 2024/04/09 18:59:48 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *tmp;
tmp = malloc(sizeof(*tmp));
if (!tmp)
return (NULL);
tmp->next = NULL;
tmp->content = content;
return (tmp);
}

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 13:43:08 by vvobis #+# #+# */
/* Updated: 2024/04/09 18:21:11 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
if (!lst)
return (0);
i = 1;
while (lst->next)
{
lst = lst->next;
i++;
}
return (i);
}

31
miniRT/libft/ft_memchr.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 15:13:59 by vvobis #+# #+# */
/* Updated: 2024/04/09 20:55:24 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(void *s, int c, size_t n)
{
unsigned char *p;
size_t i;
i = 0;
p = (unsigned char *)s;
while (i < n)
{
if (p[i] == (unsigned char)c)
return ((void *)&p[i]);
i++;
}
if (p[i - 1] == (unsigned char)c)
return ((void *)&p[i]);
return (NULL);
}

31
miniRT/libft/ft_memcmp.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 15:27:15 by vvobis #+# #+# */
/* Updated: 2024/04/09 19:21:02 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(void *s1, void const *s2, size_t n)
{
unsigned char *p1;
unsigned char *p2;
unsigned int i;
p1 = (unsigned char *)s1;
p2 = (unsigned char *)s2;
i = 0;
while (i < n)
{
if (p1[i] != p2[i])
return (p1[i] - p2[i]);
i++;
}
return (0);
}

32
miniRT/libft/ft_memcpy.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 17:13:18 by vvobis #+# #+# */
/* Updated: 2024/04/09 19:21:29 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dest, void const *src, size_t n)
{
char *d;
char *s;
if (n == 0 || (dest == NULL && src == NULL))
return (dest);
if (dest == NULL || src == NULL)
{
*(char *)dest = 1;
*(char *)src = 1;
}
d = (char *) dest;
s = (char *) src;
while (n--)
*d++ = *s++;
return (dest);
}

30
miniRT/libft/ft_memmove.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 17:42:28 by vvobis #+# #+# */
/* Updated: 2024/04/09 19:21:54 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, void const *src, size_t n)
{
unsigned char *d;
unsigned char *s;
if (!dest && !src)
return (dest);
d = (unsigned char *)dest;
s = (unsigned char *)src;
if (s < d)
while (n--)
d[n] = s[n];
else
ft_memcpy(dest, (void *)src, n);
return (dest);
}

23
miniRT/libft/ft_memset.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 15:57:27 by vvobis #+# #+# */
/* Updated: 2024/04/03 11:18:10 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
char *str;
str = (char *)s;
while (n--)
str[n] = c;
return (s);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/07 17:34:30 by vvobis #+# #+# */
/* Updated: 2024/04/07 17:53:33 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/07 17:57:33 by vvobis #+# #+# */
/* Updated: 2024/04/07 18:00:49 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char *str, int fd)
{
if (!str)
return ;
ft_putstr_fd(str, fd);
ft_putchar_fd(0x0a, fd);
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/07 18:02:14 by vvobis #+# #+# */
/* Updated: 2024/04/11 11:23:10 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
if (n < 0)
ft_putchar_fd(0x2d, fd);
if (n <= -10)
ft_putnbr_fd(n / -10, fd);
if (n >= 10)
ft_putnbr_fd(n / 10, fd);
if (n >= 0)
ft_putchar_fd(n % 10 + 0x30, fd);
if (n < 0)
ft_putchar_fd(-(n % -10) + 0x30, fd);
}

View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/07 17:48:41 by vvobis #+# #+# */
/* Updated: 2024/04/07 17:52:16 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char *str, int fd)
{
if (!str)
return ;
while (*str)
ft_putchar_fd(*str++, fd);
}

26
miniRT/libft/ft_read.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_read.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/18 12:49:30 by vvobis #+# #+# */
/* Updated: 2024/11/18 12:50:46 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_read(int fd, char *character, unsigned int size_to_read)
{
int bytes_read;
bytes_read = read(fd, character, size_to_read);
if (bytes_read == -1)
{
ft_fprintf(STDERR_FILENO, "Read failed\n");
exit (1);
}
return (bytes_read);
}

84
miniRT/libft/ft_split.c Normal file
View File

@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/05 20:14:20 by vvobis #+# #+# */
/* Updated: 2024/04/09 23:55:49 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int count(char const *s, char const c)
{
int n;
n = 0;
if (*s != c && *s)
n = 1;
while (*s)
{
if (*s == c && *(s + 1) != c && *(s + 1))
n++;
s++;
}
return (n);
}
static int count_sub(char const *s, char const c)
{
int i;
i = 0;
while (*s != c && *s)
{
i++;
s++;
}
return (i);
}
static char **free_all(char **back)
{
char **tmp;
tmp = back;
while (*back)
{
free(*back);
back++;
}
free(tmp);
return (NULL);
}
char **ft_split(char const *s, char const c)
{
char **tmp;
char **back;
if (!s)
return (NULL);
tmp = (char **)ft_calloc(sizeof(*tmp), count(s, c) + 1);
if (!tmp)
return (NULL);
back = tmp;
while (*s && tmp)
{
while (*s == c && *s)
s++;
if (*s)
{
*tmp = ft_substr(s, 0, count_sub(s, c));
if (!*tmp)
return (free_all(back));
}
tmp++;
while (*s != c && *s)
s++;
}
return (back);
}

29
miniRT/libft/ft_strchr.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 12:20:50 by vvobis #+# #+# */
/* Updated: 2024/04/09 20:54:14 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(char const *s, int c)
{
int i;
i = 0;
while (s[i])
{
if (s[i] == (char)c)
return ((char *)&s[i]);
i++;
}
if ((char)c == 0)
return ((char *)&s[i]);
return (NULL);
}

31
miniRT/libft/ft_strdup.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 18:44:05 by vvobis #+# #+# */
/* Updated: 2024/04/12 10:44:23 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(char const *s)
{
char *tmp;
int i;
i = 0;
tmp = ft_calloc(ft_strlen(s) + 1, sizeof(*tmp));
if (!tmp)
return (NULL);
while (s[i])
{
tmp[i] = s[i];
i++;
}
tmp[i] = 0;
return (tmp);
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/07 17:24:08 by vvobis #+# #+# */
/* Updated: 2024/04/09 19:27:07 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_striteri(char const *s, void (*f)(unsigned int, char *))
{
unsigned int i;
if (!s || !f)
return ;
i = 0;
while (s[i])
{
f(i, (char *)&s[i]);
i++;
}
}

41
miniRT/libft/ft_strjoin.c Normal file
View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 19:08:03 by vvobis #+# #+# */
/* Updated: 2024/04/12 10:07:26 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *tmp;
unsigned int i;
unsigned int j;
if (!s1 || !s2)
return (NULL);
tmp = ft_calloc(ft_strlen(s1) + ft_strlen(s2) + 1, sizeof(*tmp));
if (!tmp)
return (NULL);
i = 0;
while (s1[i])
{
tmp[i] = s1[i];
i++;
}
j = 0;
while (s2[j])
{
tmp[i] = s2[j];
i++;
j++;
}
tmp[i] = 0;
return (tmp);
}

37
miniRT/libft/ft_strlcat.c Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 16:10:59 by vvobis #+# #+# */
/* Updated: 2024/04/10 16:41:14 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dest, char const *src, size_t size)
{
size_t dlen;
size_t slen;
if (size == 0)
return (ft_strlen(src));
dlen = ft_strlen(dest);
slen = ft_strlen(src);
if (size <= dlen)
return (slen + size);
if (dlen + slen < size)
{
ft_memcpy(&dest[dlen], src, slen);
dest[dlen + slen] = 0;
}
else
{
ft_memcpy(&dest[dlen], src, size - dlen);
dest[size - 1] = 0;
}
return (dlen + slen);
}

32
miniRT/libft/ft_strlcpy.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 19:03:18 by vvobis #+# #+# */
/* Updated: 2024/04/09 19:28:44 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dest, char const *src, size_t size)
{
size_t i;
i = 0;
if (size != 0)
{
while (src[i] != '\0' && i < size - 1)
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
}
while (src[i] != '\0')
i++;
return (i);
}

27
miniRT/libft/ft_strlen.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 16:01:03 by vvobis #+# #+# */
/* Updated: 2024/04/12 10:40:59 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(char const *str)
{
size_t i;
i = 0;
while (*str++)
{
i++;
if (i == SIZE_MAX)
break ;
}
return (i);
}

33
miniRT/libft/ft_strmapi.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/07 17:01:35 by vvobis #+# #+# */
/* Updated: 2024/04/12 10:13:57 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *tmp;
unsigned int i;
if (!s || !f)
return (NULL);
tmp = ft_calloc(ft_strlen(s) + 1, sizeof(*tmp));
if (!tmp)
return (NULL);
i = 0;
while (s[i])
{
tmp[i] = f(i, s[i]);
i++;
}
tmp[i] = 0;
return (tmp);
}

31
miniRT/libft/ft_strncmp.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 13:33:22 by vvobis #+# #+# */
/* Updated: 2024/04/12 10:29:59 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(char const *s1, char const *s2, size_t n)
{
size_t i;
if (n == 0)
return (0);
i = 0;
while ((s1[i] || s2[i]) && i < n)
{
if (s1[i] < s2[i])
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
else if (s1[i] > s2[i])
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
i++;
}
return (0);
}

36
miniRT/libft/ft_strnstr.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 15:36:41 by vvobis #+# #+# */
/* Updated: 2024/04/10 16:42:02 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(char const *s1, char const *s2, size_t n)
{
size_t i;
size_t j;
if (!*s2)
return ((char *)s1);
i = 0;
while (i < n && s1[i])
{
j = 0;
if (s1[i + j] == s2[j])
{
while (s1[i + j] == s2[j] && s1[i + j] && i + j < n)
j++;
if (!s2[j])
return ((char *)&s1[i]);
}
i++;
}
return (NULL);
}

33
miniRT/libft/ft_strrchr.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 12:20:50 by vvobis #+# #+# */
/* Updated: 2024/04/09 20:54:22 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(char const *s, int c)
{
char *n;
int i;
i = 0;
n = NULL;
while (s[i] != 0)
{
if (s[i] == (char)c)
n = (char *)&s[i];
i++;
}
if ((char)c == 0)
return ((char *)&s[i]);
if (n)
return (n);
return (NULL);
}

47
miniRT/libft/ft_strtrim.c Normal file
View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 19:30:35 by vvobis #+# #+# */
/* Updated: 2024/04/15 13:07:55 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int is_set(char c, char const *s)
{
while (*s)
if (c == *s++)
return (1);
return (0);
}
static int find_end(char const *s1, char const *set)
{
int i;
i = 0;
while (*s1)
s1++;
while (is_set(*--s1, set))
i++;
return (i);
}
char *ft_strtrim(char const *s1, char const *set)
{
if (!s1)
return (NULL);
if (!set)
return ((char *)s1);
while (is_set(*s1, set) && *s1)
s1++;
if ((int)ft_strlen(s1) > find_end(s1, set))
return (ft_substr(s1, 0, ft_strlen(s1) - find_end(s1, set)));
else
return (ft_calloc(1, 1));
}

41
miniRT/libft/ft_substr.c Normal file
View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 18:58:25 by vvobis #+# #+# */
/* Updated: 2024/04/09 21:50:44 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *tmp;
unsigned int i;
i = 0;
if (!s || start >= ft_strlen(s) || len <= 0)
{
tmp = malloc(1);
if (!tmp)
return (NULL);
tmp[i] = 0;
return (tmp);
}
if (len + start > ft_strlen(s))
len = ft_strlen(s) - start;
tmp = malloc(sizeof(*tmp) * len + 1);
if (!tmp)
return (NULL);
while (i < len && s[i])
{
tmp[i] = s[i + start];
i++;
}
tmp[i] = 0;
return (tmp);
}

20
miniRT/libft/ft_tolower.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 12:01:54 by vvobis #+# #+# */
/* Updated: 2024/04/03 12:15:18 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_tolower(int c)
{
if (c >= 65 && c <= 90)
c += 32;
return (c);
}

20
miniRT/libft/ft_toupper.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 12:18:44 by vvobis #+# #+# */
/* Updated: 2024/04/03 12:19:05 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_toupper(int c)
{
if (c >= 97 && c <= 122)
c -= 32;
return (c);
}

View File

@ -0,0 +1,109 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 20:20:17 by vvobis #+# #+# */
/* Updated: 2024/05/27 17:44:59 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void *buffer_extend(void *ptr_old, size_t size_new, size_t size_old)
{
void *ptr_new;
void *ptr_back;
void *ptr_old_free;
ptr_new = g_calloc(size_new + 1, 1);
if (!ptr_new)
return (free(ptr_old), ptr_old = NULL, NULL);
ptr_back = ptr_new;
ptr_old_free = ptr_old;
while (size_old--)
*(char *)ptr_new++ = *(char *)ptr_old++;
return (free(ptr_old_free), ptr_old_free = NULL, ptr_back);
}
char *handle_no_nl(char **buf, char **left)
{
if (left)
{
free(*left);
*left = NULL;
}
if (!buf)
return (NULL);
if (g_strlen(*buf))
return (*buf);
free(*buf);
*buf = NULL;
return (NULL);
}
char *line_extract(char **buf_joined, char **left, size_t line_len)
{
char *line;
line = g_substr(*buf_joined, 0, line_len);
if (!line)
return (free(*buf_joined), *buf_joined = NULL, NULL);
*left = g_substr(*buf_joined, line_len, g_strlen(*buf_joined) - line_len);
free(*buf_joined);
*buf_joined = NULL;
if (!*left)
return (free(line), line = NULL, NULL);
return (line);
}
char *line_handle(char **buf_fetch)
{
char *buf_joined;
size_t line_len;
static char *left;
if (!buf_fetch)
return (free(left), NULL);
buf_joined = g_strjoin(left, *buf_fetch);
free(*buf_fetch);
*buf_fetch = NULL;
free(left);
left = NULL;
if (!buf_joined)
return (NULL);
line_len = find_newline(buf_joined);
if (line_len)
return (line_extract(&buf_joined, &left, line_len));
return (handle_no_nl(&buf_joined, &left));
}
char *get_next_line(int fd)
{
char *buf;
ssize_t bytes_read;
size_t buf_size_cur;
size_t buf_size_prev;
if (fd < 0)
return (line_handle(NULL), NULL);
buf = g_calloc(sizeof(*buf), BUFFER_SIZE + 1);
buf_size_prev = 0;
buf_size_cur = BUFFER_SIZE;
while (1)
{
if (!buf)
return (line_handle(NULL));
bytes_read = read(fd, buf + buf_size_prev, BUFFER_SIZE);
if (bytes_read < 0)
return (free(buf), buf = NULL, line_handle(NULL));
if (find_newline(buf) || bytes_read == 0)
break ;
buf_size_prev = buf_size_cur;
buf_size_cur += BUFFER_SIZE;
buf = buffer_extend(buf, buf_size_cur, buf_size_prev);
}
return (line_handle(&buf));
}

View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/15 14:07:36 by vvobis #+# #+# */
/* Updated: 2024/05/27 17:43:21 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GET_NEXT_LINE_H
# define GET_NEXT_LINE_H
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 50
# endif
# define MAX_FD 1024
# include <stdlib.h>
# include <unistd.h>
# include <fcntl.h>
# include <stdint.h>
char *get_next_line(int fd);
char *g_strjoin(char const *s1, char const *s2);
size_t g_strlen(char const *str);
void *g_calloc(size_t n, size_t s);
char *g_substr(char const *s, unsigned int start, size_t len);
char *line_handle(char **buf_fetch);
size_t find_newline(char *buf);
#endif

View File

@ -0,0 +1,118 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/15 14:14:13 by vvobis #+# #+# */
/* Updated: 2024/05/20 11:38:03 by victor ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t g_strlen(char const *str)
{
size_t i;
if (!str)
return (0);
i = 0;
while (*str)
{
i++;
str++;
}
return (i);
}
size_t find_newline(char *buf)
{
size_t i;
if (!buf)
return (0);
i = 0;
while (*buf)
{
if (*buf == '\n')
return (i + 1);
i++;
buf++;
}
return (0);
}
char *g_strjoin(char const *s1, char const *s2)
{
char *tmp;
unsigned int i;
unsigned int j;
if (!s2)
return (NULL);
if (!s1)
return (g_substr(s2, 0, g_strlen(s2)));
tmp = g_calloc(g_strlen(s1) + g_strlen(s2) + 1, sizeof(*tmp));
if (!tmp)
return (NULL);
i = 0;
if (s1)
{
while (s1[i])
{
tmp[i] = s1[i];
i++;
}
}
j = 0;
if (s2)
while (s2[j])
tmp[i++] = s2[j++];
return (tmp);
}
char *g_substr(char const *s, unsigned int start, size_t len)
{
char *tmp;
unsigned int i;
i = 0;
if (!s || start >= g_strlen(s) || len <= 0)
{
tmp = malloc(1);
if (!tmp)
return (NULL);
tmp[i] = 0;
return (tmp);
}
if (len + start > g_strlen(s))
len = g_strlen(s) - start;
tmp = g_calloc(len + 1, sizeof(*tmp));
if (!tmp)
return (NULL);
while (i < len && s[i])
{
tmp[i] = s[i + start];
i++;
}
return (tmp);
}
void *g_calloc(size_t n, size_t s)
{
char *tmp;
unsigned long i;
i = 0;
if (n == 0)
return (malloc(0));
if (SIZE_MAX / n < s)
return (NULL);
tmp = malloc(n * s);
if (tmp)
while (i < n * s)
tmp[i++] = 0;
return ((void *)tmp);
}

92
miniRT/libft/libft.h Normal file
View File

@ -0,0 +1,92 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bszilas <bszilas@student.42vienna.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/09 23:43:36 by vvobis #+# #+# */
/* Updated: 2025/05/31 12:27:14 by victor ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include "gnl/get_next_line.h"
# include "./printf/ft_printf.h"
# include <stdlib.h>
# include <unistd.h>
# include <stddef.h>
# include <stdint.h>
# include <limits.h>
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
int ft_isalpha(int c);
int ft_isdigit(int c);
int ft_isalnum(int c);
int ft_isprint(int c);
int ft_isascii(int c);
int ft_isspace(int c);
/*Memory Management*/
int ft_memcmp(void *s1, void const *s2, size_t n);
void *ft_memset(void *s, int c, size_t n);
void ft_bzero(void *s, size_t n);
void *ft_memcpy(void *dest, void const *src, size_t n);
void *ft_memmove(void *dest, void const *src, size_t n);
void *ft_memchr(void *s, int c, size_t n);
void *ft_calloc(size_t n, size_t s);
/*Info Conversion*/
int ft_atoi(char const *s);
double ft_atod(char *s);
char *ft_itoa(int n);
char **ft_split(char const *s, char c);
void ft_free(void *ptr_ptr);
long ft_atol(const char *nptr);
/*String Manip*/
int ft_toupper(int c);
int ft_tolower(int c);
int ft_strncmp(char const *s1, char const *s2, size_t n);
char *ft_strnstr(char const *s1, char const *s2, size_t n);
char *ft_strchr(char const *s, int c);
char *ft_strrchr(char const *s, int c);
char *ft_strdup(char const *s);
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strtrim(char const *s1, char const *set);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
void ft_striteri(char const *s, void (*f)(unsigned int, char *));
size_t ft_strlcpy(char *dest, char const *src, size_t size);
size_t ft_strlcat(char *dest, char const *src, size_t size);
size_t ft_strlen(char const *str);
/*List manip*/
int ft_lstsize(t_list *lst);
void ft_lstdelone(t_list *lst, void (*del)(void*));
void ft_lstclear(t_list **lst, void (*del)(void*));
void ft_lstiter(t_list *lst, void (*f)(void *));
void ft_lstadd_front(t_list **lst, t_list *node_new);
void ft_lstadd_back(t_list **lst, t_list *node_new);
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
t_list *ft_lstnew(void *content);
t_list *ft_lstlast(t_list *lst);
/*Output*/
void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char *str, int fd);
void ft_putendl_fd(char *str, int fd);
void ft_putnbr_fd(int n, int fd);
/* Get Next Line */
char *get_next_line(int fd);
#endif

View File

@ -0,0 +1,33 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: victor </var/spool/mail/victor> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/14 09:21:46 by victor #+# #+# #
# Updated: 2025/05/31 12:28:57 by victor ### ########.fr #
# #
# **************************************************************************** #
NAME := libftprintf.a
CC := cc
CFLAGS := -Wall -Werror -Wextra
SRC := ft_fprintf.c ft_printf.c ft_putascii.c ft_puthex.c ft_putptr.c ft_strlen.c ft_putfloat.c
OBJ := $(SRC:.c=.o)
all: $(NAME)
$(NAME): $(OBJ)
ar rsc $@ $(OBJ)
$(OBJ): $(SRC)
$(CC) $(CFLAGS) -c $(SRC)
clean:
rm -f $(OBJ)
fclean: clean
rm -f $(NAME)
re: fclean all

View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_fprintf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/17 12:04:30 by vvobis #+# #+# */
/* Updated: 2024/09/17 12:09:29 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "./ft_printf.h"
int ft_fprintf(int fd, const char *format, ...)
{
va_list args;
int count;
if (!format || fd < 0)
return (-1);
va_start(args, format);
count = 0;
while (1)
{
while (*format != '%' && *format)
ft_putchar(*format++, &count, fd);
if (!*format)
break ;
else
format++;
if (!*format || !handle_arg(args, *format, &count, fd))
return (-1);
format++;
}
va_end(args);
return (count);
}

View File

@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 17:50:35 by vvobis #+# #+# */
/* Updated: 2024/09/17 14:11:57 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int handle_arg(va_list args, char format, int *count, int fd)
{
if (format == 'd' || format == 'i')
ft_putnbr(va_arg(args, int), count, fd);
else if (format == 'u')
ft_putnbr(va_arg(args, unsigned int), count, fd);
else if (format == 's')
ft_putstr(va_arg(args, char *), count, fd);
else if (format == 'X')
ft_puthex_upper(va_arg(args, unsigned int), count, fd);
else if (format == 'x')
ft_puthex_lower(va_arg(args, unsigned int), count, fd);
else if (format == 'p')
ft_putptr(va_arg(args, void *), count, fd);
else if (format == 'c')
ft_putchar(va_arg(args, int), count, fd);
else if (format == '%')
ft_putchar('%', count, fd);
else if (format == 'f')
ft_putnbrf(va_arg(args, double), count, 5, fd);
else
return (0);
return (1);
}
int ft_printf(const char *format, ...)
{
va_list args;
int count;
if (!format)
return (-1);
va_start(args, format);
count = 0;
while (1)
{
while (*format != '%' && *format)
ft_putchar(*format++, &count, STDOUT_FILENO);
if (!*format)
break ;
else
format++;
if (!*format || !handle_arg(args, *format, &count, STDOUT_FILENO))
return (-1);
format++;
}
va_end(args);
return (count);
}

View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 12:50:35 by vvobis #+# #+# */
/* Updated: 2024/09/17 12:13:18 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_H
# define FT_PRINTF_H
# include <stdarg.h>
# include <stdlib.h>
# include <unistd.h>
int ft_fprintf(int fd, const char *format, ...);
int ft_printf(const char *format, ...);
int handle_arg(va_list args, char format, int *count, int fd);
void ft_puthex_lower(unsigned long nbr, int *count, int fd);
void ft_puthex_upper(unsigned long nbr, int *count, int fd);
void ft_putchar(int c, int *count, int fd);
void ft_putnbr(long n, int *count, int fd);
void ft_putnbrf(double f, int *count, int precision, int fd);
void ft_putstr(const char *str, int *count, int fd);
void ft_putptr(void *ptr, int *count, int fd);
size_t ft_strlen(const char *s);
#endif

View File

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 17:54:53 by vvobis #+# #+# */
/* Updated: 2024/09/17 16:35:10 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putchar(int c, int *count, int fd)
{
write(fd, &c, 1);
*count += 1;
}
void ft_putnbr(long n, int *count, int fd)
{
if (n < 0)
ft_putchar(0x2d, count, fd);
if (n <= -10)
ft_putnbr(n / -10, count, fd);
if (n >= 10)
ft_putnbr(n / 10, count, fd);
if (n >= 0)
ft_putchar(n % 10 + 0x30, count, fd);
if (n < 0)
ft_putchar(-(n % -10) + 0x30, count, fd);
}
void ft_putstr(const char *str, int *count, int fd)
{
if (!str)
{
*count += ft_fprintf(fd, "(null)");
return ;
}
*count += ft_fprintf(fd, str);
}

View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putfloat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/17 11:50:45 by vvobis #+# #+# */
/* Updated: 2024/12/05 14:15:28 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putnbrf(double f, int *count, int precision, int fd)
{
int number;
double fraction;
unsigned int mult;
char sign;
mult = 1;
sign = 0;
if (f < 0.0 && f > -1.0)
sign = 1;
while (precision-- > 0)
{
mult *= 10;
}
number = (int)f;
fraction = f - (double)number;
if (sign)
ft_putchar('-', count, fd);
ft_putnbr(number, count, fd);
ft_putchar('.', count, fd);
number = fraction * mult;
if (number < 0)
number = -number;
ft_putnbr(number, count, fd);
}

View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 17:52:38 by vvobis #+# #+# */
/* Updated: 2024/09/17 12:09:29 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_puthex_upper(unsigned long nbr, int *count, int fd)
{
char *base_str;
base_str = "0123456789ABCDEF";
if (nbr >= 16)
ft_puthex_upper(nbr / 16, count, fd);
ft_putchar(base_str[(nbr % 16)], count, fd);
}
void ft_puthex_lower(unsigned long nbr, int *count, int fd)
{
char *base_str;
base_str = "0123456789abcdef";
if (nbr >= 16)
ft_puthex_lower(nbr / 16, count, fd);
ft_putchar(base_str[(nbr % 16)], count, fd);
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 17:53:53 by vvobis #+# #+# */
/* Updated: 2024/09/17 12:09:29 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putptr(void *ptr, int *count, int fd)
{
void **to_print;
if (!ptr)
{
*count += ft_fprintf(fd, "(nil)");
return ;
}
to_print = &ptr;
*count += ft_printf("0x");
ft_puthex_lower((long)*to_print, count, fd);
}

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 16:01:03 by vvobis #+# #+# */
/* Updated: 2024/09/14 09:24:02 by victor ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include "limits.h"
size_t ft_strlen(char const *str)
{
size_t i;
i = 0;
while (*str++)
{
i++;
if (i == ULONG_MAX)
break ;
}
return (i);
}

37
miniRT/memory/Makefile Normal file
View File

@ -0,0 +1,37 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: victor </var/spool/mail/victor> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/08 17:46:41 by victor #+# #+# #
# Updated: 2025/05/31 12:29:32 by victor ### ########.fr #
# #
# **************************************************************************** #
CC := cc
CFLAGS := -Wall -Wextra -Werror -g3
NAME := memory.a
SRC := memory.c list.c
OBJ := $(SRC:.c=.o)
all: $(NAME)
$(NAME): $(OBJ) $(LIBS)
ar rcs $(NAME) $(OBJ)
$(OBJ): $(SRC)
$(CC) $(CFLAGS) -c $(SRC)
clean:
rm -f $(OBJ)
fclean: clean
rm -f $(NAME)
re: fclean all

94
miniRT/memory/list.c Normal file
View File

@ -0,0 +1,94 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: victor </var/spool/mail/victor> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/08 17:47:55 by victor #+# #+# */
/* Updated: 2024/09/13 10:16:10 by victor ### ########.fr */
/* */
/* ************************************************************************** */
#include "memory.h"
INTERN t_clean *lst_node_new(void *content, void (*del)(void *))
{
t_clean *new;
if (!content || !del)
return (NULL);
new = malloc(sizeof(*new));
if (!new)
return (NULL);
new->content = content;
new->clean = del;
new->next = NULL;
return (new);
}
INTERN void lst_node_del(t_clean **lst)
{
(*lst)->clean((*lst)->content);
free(*lst);
*lst = 0;
}
INTERN void lst_node_del_clean(t_clean **lst, void *mem)
{
t_clean *tmp;
t_clean *head;
if (!lst || !*lst)
return ;
head = *lst;
tmp = *lst;
while ((*lst) && (*lst)->next->content != mem)
(*lst) = (*lst)->next;
if (!*lst)
return ;
tmp = *lst;
if ((*lst)->next && (*lst)->next->next)
{
tmp = (*lst)->next->next;
lst_node_del(&(*lst)->next);
(*lst)->next = tmp;
}
else if ((*lst)->next)
lst_node_del(&(*lst)->next);
else
lst_node_del(lst);
*lst = head;
}
INTERN void lst_list_clean(t_clean **head)
{
t_clean *tmp;
while (*head)
{
tmp = (*head)->next;
lst_node_del(head);
*head = tmp;
}
free(*head);
}
INTERN void lst_add_back(t_clean **node, t_clean *new)
{
t_clean *tmp;
if (!new)
{
perror("malloc");
}
if (*node)
{
tmp = *node;
while (tmp->next)
tmp = tmp->next;
tmp->next = new;
}
else
*node = new;
}

35
miniRT/memory/memory.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* memory.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anarama <anarama@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/05 12:21:13 by victor #+# #+# */
/* Updated: 2024/09/12 16:16:33 by vvobis ### ########.fr */
/* */
/* ************************************************************************** */
#include "memory.h"
void lst_memory(void *mem, void (*del)(void *c), int mode)
{
static t_clean *list;
t_clean *new;
if (!del)
del = free;
if (mode == FAIL)
return (lst_list_clean(&list), exit(EXIT_FAILURE));
if (mode == END)
return (lst_list_clean(&list));
if (mode == FREE)
return (lst_node_del_clean(&list, mem));
if (!mem)
return (lst_list_clean(&list), perror("malloc"), exit(EXIT_FAILURE));
new = lst_node_new(mem, del);
if (!new)
return (del(mem), lst_list_clean(&list), \
perror("malloc"), exit(EXIT_FAILURE));
lst_add_back(&list, new);
}

56
miniRT/memory/memory.h Normal file
View File

@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* memory.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: victor </var/spool/mail/victor> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/08 17:18:13 by victor #+# #+# */
/* Updated: 2024/09/08 18:03:07 by victor ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEMORY_H
# define MEMORY_H
# include <stdlib.h>
# include <stdio.h>
# define INTERN
enum e_alloc
{
ADD,
FAIL,
END,
FREE,
};
typedef struct s_clean
{
void *content;
void (*clean)(void *del);
struct s_clean *next;
} t_clean;
/* Main memory handling function:
*
* Pointers may be passed to this function and will be stored on a linked list.
* DEL_FUNC is a function pointer that will be used to destroy the
* created node with the specified funtion.
* If DEL_FUNC is NULL, the pointer will be attempted to be freed using free()
*
* MODEs are:
* ADD: adds a node to the end of the list
* FREE: remove the specified node using the address pointed to by MEM
* END: cleans the list
* FAIL: cleans the list and exits with exit code (1)*/
void lst_memory(void *mem, void (*del_func)(void *c), int mode);
INTERN t_clean *lst_node_new(void *content, void (*del)(void *));
INTERN void lst_node_del(t_clean **lst);
INTERN void lst_node_del_clean(t_clean **lst, void *mem);
INTERN void lst_list_clean(t_clean **head);
INTERN void lst_add_back(t_clean **node, t_clean *new_node);
#endif

835
miniRT/minirt.h Normal file
View File

@ -0,0 +1,835 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minirt.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bszilas <bszilas@student.42vienna.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/08 16:34:08 by victor #+# #+# */
/* Updated: 2025/05/31 16:39:41 by victor ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINIRT_H
# define MINIRT_H
#include <stdint.h>
#include <sys/types.h>
# include <unistd.h>
# include <math.h>
# include <stdlib.h>
# include <errno.h>
# include <fcntl.h>
# include "libft/libft.h"
# include "memory/memory.h"
# include <stdbool.h>
# include <pthread.h>
# include <dirent.h>
# include "./raylib/src/raylib.h"
# include <string.h>
# ifndef WI
# define WI 1920
# endif
# ifndef HI
# define HI 1080
# endif
# define MAX_BODY_INIT 16
# define READ_BUFFER_SIZE 1000
# define ASPECT_RATIO 1.77777778
# ifdef VALGRIND
# define SCENE_START_RESOLUTION_X 16
# define SCENE_START_RESOLUTION_Y 9
# else
# define SCENE_START_RESOLUTION_X 1
# define SCENE_START_RESOLUTION_Y 1
# endif
# define RESOLUTION_SCALE_X 16
# define RESOLUTION_SCALE_Y 9
# define SCENE_START_RESOLUTION_CAP 4
# define CHECKER_GRID_SIZE 16
# define THREAD_COUNT 30
# define THREAD_HEIGHT HI / THREAD_COUNT
# define MAX_DEPTH 6
# define DROPOFF_DISTANCE 6
# define MAX_LIGHTS 4
# define ANTI_ALIASING_FACTOR 9
# define SQRT_AA_FACTOR 3
# define REC_SQRT_AA_FACTOR 0.33333333333
# define SHADOW_BIAS 1e-5
# define GLOSSINESS 10
# define COS_10 0.98480775301
# define SIN_10 0.17364817766
# define RAD_TO_DEG 57.2957795131
# define INDEX_OF_SKYSPHERE_IMAGE 1
# define SKYSPHERE INDEX_OF_SKYSPHERE_IMAGE
# define SKY_COLOR 0x83E8FC
# define MAIN_MENU 0x00beef00
# define ITEM_HEIGHT 30
# define ITEM_MARGIN 5
# define CONTAINER_ITEM_COUNT 32
# define CONTAINER_TITLE_LEN 1024
# define CONTAINER_PADDING 6
# define ITEM_PADDING 8
enum e_id_groups
{
ID_GROUP_MENU_MAIN = 1,
ID_GROUP_SPHERE,
ID_GROUP_PLANE,
ID_GROUP_CYLINDER,
ID_GROUP_DISC,
ID_GROUP_CONE,
ID_GROUP_ITEM,
};
enum e_mouse
{
LEFT_CLICK = 1,
RIGHT_CLICK = 3,
SCROLL_UP = 4,
SCROLL_DOWN = 5,
};
# define SCROLL_UP_DISTANCE -ITEM_HEIGHT
# define SCROLL_DOWN_DISTANCE ITEM_HEIGHT
typedef Image t_img;
enum e_menu_bg
{
MAIN_MENU_BG = 0x202020,
MENU_ITEM_BG = 0x404040,
HELP_MENU_BG = 0x0a0a0a,
};
enum e_menu_type
{
MENU_MAIN,
MENU_SPHERE,
MENU_PLANE,
MENU_CYLINDER,
};
typedef enum e_type
{
BODY_END = 0,
BODY_DELETED,
BODY_SPHERE,
BODY_PLANE,
BODY_CYLINDER,
BODY_DISK,
BODY_CONE,
} t_type;
typedef enum e_format
{
CONTAINER_GRID,
CONTAINER_LIST
} t_format;
# define GLYPH_COUNT 82
# define GLYPH_ROW 7
# define GLYPH_COL 6
# define PATH_LENGTH 128
typedef struct s_rect
{
uint x;
uint y;
uint width;
uint height;
} t_rect;
typedef enum e_i_type
{
ITEM_BUTTON,
ITEM_SLIDER,
ITEM_DIRENT,
} t_item_type;
typedef struct s_slider
{
t_rect bar;
t_rect cursor;
uint8_t max;
uint8_t min;
uint8_t *value;
} t_slider;
typedef struct s_button
{
uint color;
void *param;
void (*func_ptr)(void *, void *);
} t_button;
typedef struct s_dirent
{
int type;
char full_path[512];
void (*func)(void *, void *);
} t_dirent;
typedef enum e_param_type
{
PARAM_TEXTURE,
PARAM_BUMP,
PARAM_SCENE,
PARAM_BOOL,
PARAM_RADIUS,
PARAM_CONE,
PARAM_CYL,
PARAM_U8,
PARAM_UINT,
PARAM_DOUBLE,
} t_param_type;
typedef struct s_param
{
void *param;
void (*func)(void *);
t_param_type type;
} t_param;
# define ITEM_TITLE_LEN 128
typedef struct s_item
{
uint id;
t_item_type type;
t_rect rect;
char description[ITEM_TITLE_LEN];
t_param param;
union
{
t_button button;
t_slider slider;
t_dirent dirent;
};
} t_item;
typedef struct s_container
{
uint id;
t_rect attr;
t_format format;
t_param param;
char title[CONTAINER_TITLE_LEN];
char buffer[1024];
uint item_count;
uint item_width;
uint item_height;
struct s_data *data;
t_item item[CONTAINER_ITEM_COUNT];
} t_container;
typedef struct s_mouse
{
bool left_is_pressed;
bool right_is_pressed;
bool is_moving;
struct s_body *grabbed;
struct s_slider *slider;
uint color_store;
int prev_x;
int prev_y;
struct s_data *data;
} t_mouse;
typedef struct s_vector
{
double x;
double y;
double z;
} t_vector;
/* p = the visible point on the object
n = the object surface normal vector from that point
v = the normal vector towards the viewer
r = normalized perfect reflection of incoming light */
typedef struct s_hit_point
{
t_vector p;
t_vector n;
t_vector v;
t_vector r;
} t_hit_point;
typedef struct s_pixel
{
uint id;
double dist;
Color *color;
uint8_t surface_smoothness;
} t_pixel;
typedef struct s_line
{
char buffer[READ_BUFFER_SIZE + 1];
uint length;
uint count;
} t_line;
typedef struct s_buffer
{
char *bytes;
uint32_t start;
uint32_t end;
uint32_t size;
uint32_t capacity;
bool empty;
} t_buffer;
typedef struct s_sphere
{
double radius;
t_vector center;
} t_sphere;
typedef struct s_plane
{
t_vector point;
t_vector normal;
t_vector inverse_normal;
} t_plane;
typedef struct s_disk
{
t_vector point;
t_vector normal;
t_vector inverse_normal;
double radius;
} t_disk;
typedef struct s_cylinder
{
t_vector bottom;
t_vector normal;
t_vector center;
t_vector top;
t_vector coeffs;
double radius;
double height;
double hit_h;
} t_cylinder;
typedef struct s_cone
{
t_vector vertex;
t_vector normal;
t_vector coeffs;
double radius;
double height;
double hit_h;
double tan_a2p1;
double t[2];
t_disk bottom_cap;
} t_cone;
# ifndef TEXTURE_PATH
# define TEXTURE_PATH "./assets/textures/earth.ppm"
# endif
# ifndef SKYBOX_PATH
# define SKYBOX_PATH "./assets/textures/sky.ppm"
# endif
typedef struct s_texture
{
Color *pixel;
char path[255];
int width;
int height;
} t_texture;
# ifndef BUMP_MAP_PATH
# define BUMP_MAP_PATH "./assets/bump maps/earth.bump"
# endif
typedef struct s_bump_map
{
char path[255];
int *map;
uint width;
uint height;
} t_bump_map;
typedef struct s_body
{
uint id;
t_type type;
uint color;
bool reflect;
bool checker_board;
bool textured;
bool bump;
uint8_t surface_smoothness;
t_texture *texture;
t_bump_map *map;
union
{
t_sphere sphere;
t_plane plane;
t_cylinder cylinder;
t_disk disk;
t_cone cone;
};
} t_body;
typedef struct s_light
{
t_vector position;
t_vector ray;
float phong;
float obj_distance;
float intensity;
uint color;
} t_light;
typedef double t_matrix4[4][4];
typedef struct s_camera
{
t_vector *ray;
t_vector position;
t_vector normal;
t_vector right;
t_vector up;
t_matrix4 to_world;
float tilt;
double fov;
double fov_f;
} t_camera;
# define MAPS_MAX 16
typedef struct s_scene
{
uint current_body_max;
uint body_cursor;
uint resolution_x;
uint resolution_y;
uint anti_aliasing;
uint light_count;
t_light light[MAX_LIGHTS];
t_light ambient;
bool ambient_was_parsed;
t_camera camera;
bool camera_was_parsed;
uint light_focus;
uint depth;
bool sky_sphere;
uint sky_color;
t_body *body_focus;
t_pixel *pixel;
t_body *body;
pthread_mutex_t mutex;
bool reload;
t_texture *texture;
t_texture sky;
uint texture_count;
t_bump_map *bump_map;
uint bump_map_count;
} t_scene;
typedef struct s_data
{
Texture2D texture;
Color *pixel_colors;
t_pixel *pixel;
t_scene scene;
t_mouse mouse;
t_container *menu;
t_container explorer;
void *param;
void (*func_ptr)(void *, void *);
struct s_thread *threads;
int thread_count;
pthread_barrier_t barrier;
pthread_rwlock_t rwlock;
bool go;
} t_data;
typedef struct s_thread
{
int id;
pthread_t thread;
t_data *data;
t_scene *scene;
t_pixel *pixel;
pthread_rwlock_t *rwlock;
uint width;
uint height;
uint startx;
uint starty;
} t_thread;
/* ft_atod.c */
void item_double_inc(void *value, void *null);
void item_double_dec(void *value, void *null);
/* Utils */
void ft_open(int *fd, const char *path, int flag, int permissons);
int ft_close(int fd);
int ft_read(int fd, char *character, unsigned int size_to_read);
void glyph_print(uint begin_x, uint begin_y, \
char const *text, t_pixel *pixel);
void data_destroy_func(void *data_ptr);
long get_current_us(struct timeval start);
/* Drawing */
void rt_draw_rect(t_rect rect, t_pixel *pixel, uint id, uint color);
void rt_draw_rect_blend(t_rect rect, t_pixel *pixel, \
uint id, uint color);
# define COLLECT_MODE_NORMAL 0
# define COLLECT_MODE_END 1
/* Generics */
bool collect_param_comma(char **entry_position, \
char *params[], uint count, int mode);
bool collect_param_single(char **entry_position, \
char *params[], int mode);
uint id_set(uint group, int id);
uint id_group_get(int id);
void err(char *body_type, uint line);
bool check_line(char *tmp);
void swap_2_ints(uint *a, uint *b);
/* Colors */
uint color_to_uint(Color c);
Color uint_to_color(uint c);
Color set_color(uint r, uint g, uint b);
void get_color_reflect(t_vector new_center, t_vector normal, \
t_scene *scene, t_pixel *pixel);
/* Returns diffuse color when called with parameters
attn = dot product of surface normal and light ray,
uint obj = object color and float gloss = 1.
Returns specular reflection color when called with parameters
attn = dot product of light ray reflection and view ray
obj = 0xFFFFFF and float gloss greater than 1 */
uint phong_reflection(uint obj, float attn, t_light l, float gloss);
void apply_shadow_bias(t_vector *p, t_vector normal, double scale);
uint get_color(uint obj, uint light, double attn);
uint color_blend(uint color1, uint color2);
/* !!! This function PRINTS a SPACE at the BEGINNING and a NEWLINE
character at the END !!! */
void color_print(uint color, int fd);
uint add_color(uint color1, uint color2);
uint parse_body_color(char *params[], int *error);
void get_background_color(t_scene *sc, t_pixel *px, t_vector v);
uint color_brightness(uint original, float brightness);
/* Function to calculate the Euclidean distance between two colors */
float color_distance(uint r1, uint g1, uint b1, uint r2, uint g2, uint b2);
/* Sphere */
bool parse_sphere(char *entry, uint line_count, \
t_body *body, uint body_count);
void pixel_sphere_set(t_pixel *pixel, t_vector camera_ray, \
t_body *body, t_scene *scene);
void body_sphere_print(t_body *body);
void sphere_save(t_sphere sphere, uint color, int fd);
double sphere_hit_distance(t_vector ray, t_vector dlt_centr, \
t_sphere sphere, int *invert);
void get_color_sphere( t_body *body, \
t_hit_point *hit, \
t_pixel *pixel);
/* Plane */
bool parse_plane(char *entry, uint line_count, \
t_body *body, uint body_count);
void body_plane_print(t_body *body);
void trace_plane(t_pixel *pixel, t_vector camera_ray, \
t_body *body, t_scene *scene);
void plane_save(t_plane plane, uint color, int fd);
bool move_plane(int keycode, t_plane *plane);
double plane_hit_distance(t_plane pl, t_vector cam, \
t_vector camera_ray, int *invert);
void get_color_plane(t_body *body, t_hit_point *hit, t_pixel *pixel);
/* Cylinder */
void body_cylinder_print(t_body *body);
void cylinder_save(t_cylinder cylinder, uint color, int fd);
bool parse_cylinder(char *entry, uint line_count, \
t_body *body, uint body_count);
void calc_cyl_data(t_cylinder *cy);
/* The coefficients a, b, c in a quadratic equation f(x) = ax² + bx + c are
saved in a t_vector coeffs, so that coeffs.x = a, .y = b, .z = c */
void cyl_equation_coefficients(t_cylinder *cy, t_vector ray, \
t_vector cam_delta);
double cyl_hit_distance(t_cylinder *cy, t_vector ray, \
t_vector cam, int *invert);
double cyl_components_shadow(t_cylinder cy, t_vector ray, t_vector p);
bool move_cylinder(int keycode, t_cylinder *cyl);
t_vector cyl_normal(t_cylinder cy, t_vector p, int invert);
void get_color_cylinder(t_body *body, \
t_vector intersect, t_pixel *pixel);
void trace_cyl_caps(t_pixel *px, t_vector ray, \
t_body *cyl, t_scene *sc);
void trace_cyl(t_pixel *pixel, t_vector ray, t_body *body, t_scene *sc);
bool finite_cylinder_hit(t_cylinder *cy, t_vector hit);
/* Disk */
void trace_disk(t_pixel *pixel, t_vector ray, \
t_body *body, t_scene *scene);
bool parse_disk(char *entry, uint line_count, \
t_body *body, uint body_count);
double disk_hit_distance(t_disk disk, t_vector ray, \
t_vector cam, int *invert);
void print_disk(t_body *body);
bool move_disk(int keycode, t_disk *disk);
void disk_save(t_disk disk, uint color, int fd);
void get_color_disk(t_body *body, t_vector intersect, t_pixel *pixel);
/* Cone */
bool move_cone(int keycode, t_cone *cone);
bool parse_cone(char *entry, uint line_count, t_body *body, \
uint body_count);
void calc_cone_data(t_cone *cn);
bool cam_inside_cone(t_cone *cn, t_vector cam, double cam_h);
/* The coefficients a, b, c in a quadratic equation f(x) = ax² + bx + c are
saved in a t_vector coeffs, so that coeffs.x = a, .y = b, .z = c */
void cone_equation_coefficients(t_cone *cn, t_vector ray, \
t_vector cam_delta);
void solve_cone_equation(t_cone *cn, t_vector ray, t_vector cam_delta);
double cone_hit_distance(t_cone *cn, t_vector ray, t_vector cam, \
int *invert);
void trace_cone(t_pixel *pixel, t_vector ray, t_body *body, \
t_scene *sc);
void trace_cone_bottom(t_pixel *px, t_vector ray, t_body *cone, \
t_scene *sc);
double cone_components_shadow(t_cone cn, t_vector ray, t_vector p);
void cone_save(t_cone cone, uint color, int fd);
t_vector cone_surface_normal(t_cone cn, t_vector p, int invert);
bool finite_cone_hit(double cone_height, double h);
/* Vector */
void normalize_vector(t_vector *vec);
double dot_product(t_vector a, t_vector b);
double vector_length(t_vector vec);
t_vector vector_subtract(t_vector vec1, t_vector vec2);
t_vector set_vector(double x, double y, double z);
t_vector scale_vector(t_vector vec, double scale);
t_vector add_vector(t_vector vec, t_vector add);
void vector_print(t_vector vector, int fd);
t_vector get_normal(t_vector from, t_vector to);
t_vector cross_product(t_vector a, t_vector b);
t_vector rot_x(t_vector vec, int dir);
t_vector rot_y(t_vector vec, int dir);
t_vector rot_z(t_vector vec, int dir);
t_vector reflect_vector(t_vector incoming, t_vector axis);
void calc_hit_point_vectors(t_hit_point *hit, t_vector ray, t_vector n);
/* Camera */
void define_camera_rays(t_pixel *pixel, t_camera *camera, \
t_scene *scene);
void set_world_matrix(t_camera *camera);
/*camera->right in this function is used as cam normal projection onto the
xz plane to save one less t_vector type */
void calc_camera_tilt(t_camera *camera);
bool parse_camera(char *entry, uint line_count, t_camera *camera, \
bool *reload);
void body_camera_print(t_camera camera);
void camera_save(t_camera *camera, int fd);
t_vector set_ray(float x, float y, t_scene *scene, t_camera *camera);
void calc_camera_space(t_camera *camera);
/* Pixel */
t_pixel *pixel_plane_create(void);
void set_pixel_distances(t_pixel *array, uint size, double dist);
void pixels_clear(t_pixel *pixel, uint wi, uint hi);
void trace_lights(t_scene *sc, t_pixel *px, t_hit_point hit);
void pixel_clear_id(t_pixel *pixel);
void set_info_to_pixel(t_pixel *pixel, t_body *body, double dist);
/* Ray Utils */
double ray_distance_from_point_squared(t_vector ray, t_vector point);
double smaller_non_negative(double a, double b);
/* Image */
t_img image_create(void *mlx_ptr, uint width, uint height);
void pixels_image_syncronize(Color *image, t_pixel *pixel);
void save_all_lights(t_scene *scene, int fd);
/* Scene */
bool body_distribute(char *entry, char *tmp, \
uint line_cursor, t_scene *scene);
void scene_print(t_scene *scene);
void scene_create(const char *filepath, t_scene *scene);
void scene_create_loop(t_scene *scene, t_line line, int fd);
void scene_replace(t_scene *scene, char *new_path);
char *buffer_read_chunk(t_line *line, uint fd, bool *file_end_reached);
bool body_determine(char *entry, uint line_count, t_scene *scene);
void scene_body_add(t_body *body, t_scene *scene);
void scene_add_cylinder(void *data_ptr, void *null);
void scene_add_disk(void *data_ptr, void *null);
void scene_add_sphere_func(void *scene_ptr, void *null);
void scene_add_plane_func(void *data_ptr, void *null);
t_body *body_get_by_id(uint id, t_scene *scene);
void scene_save(t_scene *scene);
void trace_reflection(t_pixel *px, t_hit_point hit, t_scene new_scene);
void toggle_sky_sphere(t_scene *scene);
/* Rendering */
uint rendering_loop(t_data *data);
void pixel_fill(t_pixel *pixel, t_scene *scene);
void ray_check_bodys(t_pixel *pixel, t_vector ray, t_scene *scene);
/* Light */
bool parse_light(char *entry_light, uint line_count, t_light *light, \
int count);
void body_light_print(t_light light);
void light_save(t_light light, int fd);
bool parse_ambient(char *entry_light, uint line_count, t_light *light, \
bool *relaod);
bool shadow(t_vector p, t_light l, t_body *body, \
t_scene *scene);
void ambient_save(t_light light, int fd);
/* Keys */
int key_press(int keycode, void *data);
uint key_change_res(int keycode, t_scene *scene);
bool key_move_focused(int keycode, t_vector *focus);
bool key_change_fov(int keycode, t_camera *camera);
bool calc_camera_rotation(int key, t_camera *camera);
int move_body(int keycode, t_body *body);
bool key_move_light(int keycode, t_scene *scene);
uint key_misc_function(int keycode, t_scene *scene, t_data *data);
/* Menu */
void container_draw(void *menu, void *pixel);
void container_item_get_by_id(t_container *container, \
uint id, uint x, uint y);
void help_menu_draw(void *data_ptr, void *null);
t_container container_create(const char *title, t_rect *attr, uint format);
void container_item_add(t_container *container, t_item *item);
t_item container_item_button_create(const char *title, void *param, \
void (*func_ptr)(void *, void *));
t_item container_item_slider_create(const char *title, uint8_t min, \
uint8_t max, uint8_t *value);
void container_internal_slider_config(t_item *item);
/* Slider */
bool menu_slider_is_cursor(uint x, uint y, t_rect *slider);
void menu_slider_value_calculate(t_slider *slider);
/* Menu Mapping And Creating */
void disk_menu_map(t_container *menu, t_body *body, uint *color);
void sphere_menu_map(t_container *menu, t_body *body, uint *color);
void cylinder_menu_map(t_container *menu, t_body *body, uint *color);
void plane_menu_map(t_container *menu, t_body *body, uint *color);
void cone_menu_map(t_container *menu, t_body *body, uint *color);
void menu_body_map_bool_toggle(t_item *item, bool *value);
void menu_body_map_float(t_item *item, double *value);
void menu_body_map_vector(t_item *item, t_vector *vector);
void menu_body_map_color(t_item *item, uint *color);
void menu_body_map_texture(t_item *item, t_texture **texture);
void menu_body_map_bump(t_item *item, t_bump_map **bump);
void menu_body_bool_add(t_container *menu, char *name);
void menu_body_colors_add(t_container *menu);
void menu_body_vector_position_add(t_container *menu);
void menu_body_vector_normal_add(t_container *menu);
void menu_body_slider_add(t_container *menu, char *name);
void menu_body_float_add(t_container *menu, char *name_prefix);
void menu_body_texture_add(t_container *container);
void menu_body_bump_map_add(t_container *container);
void menu_body_slider_add(t_container *menu, char *name);
void menu_body_slider_map_value(t_item *item, uint8_t *value);
void cylinder_menu_create(t_container *menu);
void cone_menu_create(t_container *menu);
void disc_menu_create(t_container *menu);
void sphere_menu_create(t_container *menu);
void plane_menu_create(t_container *menu);
void item_normal_inc(void *null, void *value);
void item_normal_dec(void *null, void *value);
void item_double_inc(void *null, void *value);
void item_double_dec(void *null, void *value);
void item_bool_toggle(void *null, void *value);
/* Mouse */
int mouse_press(int x, int y, t_data *data);
int mouse_release(int x, int y, t_data *data);
int mouse_move(int x, int y, t_data *data);
void mouse_grab(t_mouse *mouse, t_body *body);
/* Parsing */
bool check_position(char **tmp);
bool check_end(char *entry);
char temporary_terminate_string(char *end);
void restore_string(char *end, char tmp);
int64_t get_one_tenth(char *nbr);
char get_last_char(char *str);
size_t count_digits(int64_t n, int base);
bool positive_overflow(int64_t max, char *str);
bool negative_overflow(int64_t min, char *str);
bool is_a_number(char *str);
char *skip_whitespace(char *str);
int64_t set_signed_int(const char *str, int64_t min, \
int64_t max, int *error);
void minirt_fd_close(void *ptr);
bool check_normal_vector(t_vector *vec);
/* PPM READER */
bool ppm_check(int fd, int *width, int *height);
void ppm_pixels_read(t_buffer *buffer, int fd, t_texture *texture);
int ppm_read_number(int fd, bool *eof);
void ppm_image_read(const char *path, t_texture *texture);
/* Threads */
void data_init_threads(t_data *data);
void threads_init(t_thread thread[], t_data *data);
void *thread_rendering_loop(void *thread_ptr);
void thread_define_camera_rays( t_thread *thread, \
t_pixel *pixel, \
t_scene *scene, \
t_camera *camera);
/* Read buffer */
void buffer_move_next_whitespace(t_buffer *buffer);
void buffer_allignment_set(t_buffer *buffer);
void buffer_read(t_buffer *buffer, int fd);
t_buffer buffer_init(uint capacity, void *bytes);
/* Bump Map */
void bump_map_read(char *map_path, t_bump_map *map);
bool contains_nan(char buffer[], uint size);
void perturb_normal(t_vector *normal, t_bump_map *map, \
double u, double v);
int close_window(void *data_ptr);
/* Mapgen */
void map_create_from_ppm(int infile, int outfile);
/* explorer */
void explorer_read_dir(void *data, void *path);
void file_load(t_item *item, t_data *data);
void explorer_entry_func(void *item_ptr, void *data);
void container_item_swap(t_item *itema, t_item *itemb);
void container_item_desc_sort(t_container *cont);
bool ft_opendir(DIR **dir, char *path);
/* Phong */
uint phong_reflection(uint obj, float attenuation, \
t_light l, float gloss);
void calc_phong_vectors(t_hit_point *hit, t_light *l);
uint diffuse_reflection(t_pixel *px, t_hit_point hit, t_light l);
uint specular_reflection(t_pixel *px, t_hit_point hit, t_light l);
float dropoff_factor(float distance);
#endif

115
miniRT/raylib/.gitignore vendored Normal file
View File

@ -0,0 +1,115 @@
# Ignore generated files
# ...
# Ignore VIM's backup generated files
*.swp
*.swo
*~
# Ignore thumbnails created by windows
Thumbs.db
# Ignore files build by Visual Studio
# *.obj --> Can be confused with 3d model!
*.pdb
*.aps
*.user
# *.vcproj
# *.vcxproj*
# *.sln
*.vspscc
*_i.c
*.i
*.icf
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
.vs
[Bb]in
[Dd]ebug/
*.sbr
*.sdf
obj/
[R]elease/
_ReSharper*/
[Tt]est[Rr]esult*
ipch/
*.opensdf
*.db
*.opendb
packages/
!examples/models/resources/models/obj/
# Ignore compiled binaries
*.o
*.exe
*.a
*.bc
*.so
*.so.*
*.dll
# Emscripten
emsdk
# Ignore wasm data in examples/
examples/**/*.wasm
examples/**/*.data
examples/**/*.js
examples/**/*.html
# Ignore files build by xcode
*.mode*v*
*.pbxuser
*.xcbkptlist
*.xcscheme
*.xcworkspacedata
*.xcuserstate
*.xccheckout
xcschememanagement.plist
.DS_Store
._.*
xcuserdata/
DerivedData/
# VSCode project
.vscode
# Jetbrains project
.idea/
cmake-build-*/
# CMake stuff
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
cmake_install.cmake
cmake_uninstall.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
build
# Ignore GNU global tags
GPATH
GRTAGS
GTAGS
# Zig programming language
.zig-cache/
zig-cache/
zig-out/
build/
build-*/
docgen_tmp/
# Parser stuff
parser/raylib_parser

177
miniRT/raylib/BINDINGS.md Normal file
View File

@ -0,0 +1,177 @@
# raylib bindings and wrappers
Some people ported raylib to other languages in the form of bindings or wrappers to the library. Here is a list with all the ports available. Feel free to send a PR if you know of any binding/wrapper not in this list.
### Language Bindings
| Name | raylib Version | Language | License |
| :--------------------------------------------------------------------------------------- | :--------------: | :------------------------------------------------------------------: | :------------------: |
| [raylib](https://github.com/raysan5/raylib) | **5.5** | [C/C++](https://en.wikipedia.org/wiki/C_(programming_language)) | Zlib |
| [raylib-beef](https://github.com/Starpelly/raylib-beef) | **5.5** | [Beef](https://www.beeflang.org) | MIT |
| [raybit](https://github.com/Alex-Velez/raybit) | **5.0** | [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck) | MIT |
| [raylib-c3](https://github.com/c3lang/vendor/tree/main/libraries/raylib55.c3l) | **5.5** | [C3](https://c3-lang.org) | MIT |
| [raylib-cs](https://github.com/raylib-cs/raylib-cs) | **5.5** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | Zlib |
| [Raylib-CsLo](https://github.com/NotNotTech/Raylib-CsLo) | 4.2 | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 |
| [Raylib-CSharp-Vinculum](https://github.com/ZeroElectric/Raylib-CSharp-Vinculum) | **5.0** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 |
| [Raylib-CSharp](https://github.com/MrScautHD/Raylib-CSharp) | **5.5** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MIT |
| [cl-raylib](https://github.com/longlene/cl-raylib) | 4.0 | [Common Lisp](https://common-lisp.net) | MIT |
| [claylib/wrap](https://github.com/defun-games/claylib) | 4.5 | [Common Lisp](https://common-lisp.net) | Zlib |
| [claw-raylib](https://github.com/bohonghuang/claw-raylib) | **auto** | [Common Lisp](https://common-lisp.net) | Apache-2.0 |
| [chez-raylib](https://github.com/Yunoinsky/chez-raylib) | **auto** | [Chez Scheme](https://cisco.github.io/ChezScheme) | GPLv3 |
| [CLIPSraylib](https://github.com/mrryanjohnston/CLIPSraylib) | **auto** | [CLIPS](https://www.clipsrules.net/) | MIT |
| [raylib-cr](https://github.com/sol-vin/raylib-cr) | 4.6-dev (5e1a81) | [Crystal](https://crystal-lang.org) | Apache-2.0 |
| [ray-cyber](https://github.com/fubark/ray-cyber) | **5.0** | [Cyber](https://cyberscript.dev) | MIT |
| [dart-raylib](https://gitlab.com/wolfenrain/dart-raylib) | 4.0 | [Dart](https://dart.dev) | MIT |
| [bindbc-raylib3](https://github.com/o3o/bindbc-raylib3) | **5.0** | [D](https://dlang.org) | BSL-1.0 |
| [dray](https://github.com/redthing1/dray) | **5.0** | [D](https://dlang.org) | Apache-2.0 |
| [raylib-d](https://github.com/schveiguy/raylib-d) | **5.5** | [D](https://dlang.org) | Zlib |
| [rayex](https://github.com/shiryel/rayex) | 3.7 | [elixir](https://elixir-lang.org) | Apache-2.0 |
| [raylib-factor](https://github.com/factor/factor/blob/master/extra/raylib/raylib.factor) | 4.5 | [Factor](https://factorcode.org) | BSD |
| [raylib-freebasic](https://github.com/WIITD/raylib-freebasic) | **5.0** | [FreeBASIC](https://www.freebasic.net) | MIT |
| [fortran-raylib](https://github.com/interkosmos/fortran-raylib) | **5.5** | [Fortran](https://fortran-lang.org) | ISC |
| [raylib-go](https://github.com/gen2brain/raylib-go) | **5.5** | [Go](https://golang.org) | Zlib |
| [raylib-guile](https://github.com/petelliott/raylib-guile) | **auto** | [Guile](https://www.gnu.org/software/guile) | Zlib |
| [gforth-raylib](https://github.com/ArnautDaniel/gforth-raylib) | 3.5 | [Gforth](https://gforth.org) | **???** |
| [h-raylib](https://github.com/Anut-py/h-raylib) | **5.5-dev** | [Haskell](https://haskell.org) | Apache-2.0 |
| [raylib-hx](https://github.com/foreignsasquatch/raylib-hx) | 4.2 | [Haxe](https://haxe.org) | Zlib |
| [hb-raylib](https://github.com/MarcosLeonardoMendezGerencir/hb-raylib) | 3.5 | [Harbour](https://harbour.github.io) | MIT |
| [jaylib](https://github.com/janet-lang/jaylib) | **5.0** | [Janet](https://janet-lang.org) | MIT |
| [jaylib](https://github.com/electronstudio/jaylib/) | **5.5** | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | GPLv3+CE |
| [raylib-j](https://github.com/CreedVI/Raylib-J) | 4.0 | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | Zlib |
| [Raylib.jl](https://github.com/chengchingwen/Raylib.jl) | 4.2 | [Julia](https://julialang.org) | Zlib |
| [kaylib](https://github.com/electronstudio/kaylib) | 3.7 | [Kotlin/native](https://kotlinlang.org) | **???** |
| [KaylibKit](https://codeberg.org/Kenta/KaylibKit) | 4.5 | [Kotlin/native](https://kotlinlang.org) | Zlib |
| [raylib-lua](https://github.com/TSnake41/raylib-lua) | 5.0 | [Lua](http://www.lua.org) | ISC |
| [raylib-lua-bindings (WIP)](https://github.com/legendaryredfox/raylib-lua-bindings) | 5.5 | [Lua](http://www.lua.org) | ISC |
| [ReiLua](https://github.com/nullstare/ReiLua) | 5.5 | [Lua](http://www.lua.org) | MIT |
| [raylib-lua-sol](https://github.com/RobLoach/raylib-lua-sol) | 5.5 | [Lua](http://www.lua.org) | Zlib |
| [raylib-luajit](https://github.com/homma/raylib-luajit) | 5.5 | [Lua](http://www.lua.org) | MIT |
| [raylib-luajit-generated](https://github.com/james2doyle/raylib-luajit-generated) | 5.5 | [Lua](http://www.lua.org) | MIT |
| [raylib-matte](https://github.com/jcorks/raylib-matte) | 4.6-dev | [Matte](https://github.com/jcorks/matte) | **???** |
| [Raylib.nelua](https://github.com/AuzFox/Raylib.nelua) | **5.5** | [nelua](https://nelua.io) | Zlib |
| [raylib-bindings](https://github.com/vaiorabbit/raylib-bindings) | 5.6-dev | [Ruby](https://www.ruby-lang.org/en) | Zlib |
| [naylib](https://github.com/planetis-m/naylib) | **5.6-dev** | [Nim](https://nim-lang.org) | MIT |
| [node-raylib](https://github.com/RobLoach/node-raylib) | 4.5 | [Node.js](https://nodejs.org/en) | Zlib |
| [raylib-odin](https://github.com/odin-lang/Odin/tree/master/vendor/raylib) | **5.5** | [Odin](https://odin-lang.org) | BSD-3Clause |
| [raylib_odin_bindings](https://github.com/Deathbat2190/raylib_odin_bindings) | 4.0-dev | [Odin](https://odin-lang.org) | MIT |
| [raylib-ocaml](https://github.com/tjammer/raylib-ocaml) | **5.0** | [OCaml](https://ocaml.org) | MIT |
| [TurboRaylib](https://github.com/turborium/TurboRaylib) | 4.5 | [Object Pascal](https://en.wikipedia.org/wiki/Object_Pascal) | MIT |
| [Ray4Laz](https://github.com/GuvaCode/Ray4Laz) | **5.5** | [Free Pascal](https://en.wikipedia.org/wiki/Free_Pascal) | Zlib |
| [Raylib.4.0.Pascal](https://github.com/sysrpl/Raylib.4.0.Pascal) | 4.0 | [Free Pascal](https://en.wikipedia.org/wiki/Free_Pascal) | Zlib |
| [pyraylib](https://github.com/Ho011/pyraylib) | 3.7 | [Python](https://www.python.org) | Zlib |
| [raylib-python-cffi](https://github.com/electronstudio/raylib-python-cffi) | **5.5** | [Python](https://www.python.org) | EPL-2.0 |
| [raylibpyctbg](https://github.com/overdev/raylibpyctbg) | 5.5 | [Python](https://www.python.org) | MIT |
| [raylib-py](https://github.com/overdev/raylib-py) | 5.5 | [Python](https://www.python.org) | MIT |
| [raylib-python-ctypes](https://github.com/sDos280/raylib-python-ctypes) | 4.6-dev | [Python](https://www.python.org) | MIT |
| [raylib-pkpy-bindings](https://github.com/blueloveTH/pkpy-bindings) | 5.1-dev | [pocketpy](https://pocketpy.dev) | MIT |
| [raylib-php](https://github.com/joseph-montanez/raylib-php) | 4.5 | [PHP](https://en.wikipedia.org/wiki/PHP) | Zlib |
| [raylib-phpcpp](https://github.com/oraoto/raylib-phpcpp) | 3.5 | [PHP](https://en.wikipedia.org/wiki/PHP) | Zlib |
| [raylibr](https://github.com/jeroenjanssens/raylibr) | 4.0 | [R](https://www.r-project.org) | MIT |
| [raylib-ffi](https://github.com/ewpratten/raylib-ffi) | 5.5 | [Rust](https://www.rust-lang.org) | GPLv3 |
| [raylib-rs](https://github.com/raylib-rs/raylib-rs) | **5.5** | [Rust](https://www.rust-lang.org) | Zlib |
| [raylib-ruby](https://github.com/wilsonsilva/raylib-ruby) | 4.5 | [Ruby](https://www.ruby-lang.org) | Zlib |
| [Relib](https://github.com/RedCubeDev-ByteSpace/Relib) | 3.5 | [ReCT](https://github.com/RedCubeDev-ByteSpace/ReCT) | **???** |
| [racket-raylib](https://github.com/eutro/racket-raylib) | **5.5** | [Racket](https://racket-lang.org) | MIT/Apache-2.0 |
| [raylib-swift](https://github.com/STREGAsGate/Raylib) | 4.0 | [Swift](https://swift.org) | MIT |
| [raylib-scopes](https://github.com/salotz/raylib-scopes) | auto | [Scopes](http://scopes.rocks) | MIT |
| [raylib-SmallBASIC](https://github.com/smallbasic/smallbasic.plugins/tree/master/raylib) | **5.5** | [SmallBASIC](https://github.com/smallbasic/SmallBASIC) | GPLv3 |
| [raylib-umka](https://github.com/robloach/raylib-umka) | 4.5 | [Umka](https://github.com/vtereshkov/umka-lang) | Zlib |
| [raylib-v](https://github.com/vlang/raylib) | 5.5 | [V](https://vlang.io) | MIT/Unlicense |
| [raylib.v](https://github.com/irishgreencitrus/raylib.v) | 4.2 | [V](https://vlang.io) | Zlib |
| [raylib-vapi](https://github.com/lxmcf/raylib-vapi) | **5.0** | [Vala](https://vala.dev) | Zlib |
| [raylib-wren](https://github.com/TSnake41/raylib-wren) | 4.5 | [Wren](http://wren.io) | ISC |
| [raylib-zig](https://github.com/Not-Nik/raylib-zig) | **5.5** | [Zig](https://ziglang.org) | MIT |
| [raylib.zig](https://github.com/ryupold/raylib.zig) | **5.1-dev** | [Zig](https://ziglang.org) | MIT |
| [raylib-zig-bindings](https://github.com/L-Briand/raylib-zig-bindings) | **5.0** | [Zig](https://ziglang.org) | Zlib |
| [hare-raylib](https://git.sr.ht/~evantj/hare-raylib) | **auto** | [Hare](https://harelang.org) | Zlib |
| [raylib-sunder](https://github.com/ashn-dot-dev/raylib-sunder) | **auto** | [Sunder](https://github.com/ashn-dot-dev/sunder) | 0BSD |
| [raylib-bqn](https://github.com/Brian-ED/raylib-bqn) | **5.0** | [BQN](https://mlochbaum.github.io/BQN) | MIT |
| [rayjs](https://github.com/mode777/rayjs) | 4.6-dev | [QuickJS](https://bellard.org/quickjs) | MIT |
| [raylib-raku](https://github.com/vushu/raylib-raku) | **auto** | [Raku](https://www.raku.org) | Artistic License 2.0 |
| [Raylib.lean](https://github.com/KislyjKisel/Raylib.lean) | **5.5-dev** | [Lean4](https://lean-lang.org) | BSD-3-Clause |
| [raylib-cobol](https://codeberg.org/glowiak/raylib-cobol) | **auto** | [COBOL](https://gnucobol.sourceforge.io) | Public domain |
| [raylib-apl](https://github.com/Brian-ED/raylib-apl) | **5.0** | [Dyalog APL](https://www.dyalog.com/) | MIT |
| [raylib-jai](https://github.com/ahmedqarmout2/raylib-jai) | **5.5** | [Jai](https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md) | MIT |
| [fnl-raylib](https://github.com/0riginaln0/fnl-raylib) | **5.5** | [Fennel](https://fennel-lang.org/) | MIT |
### Utility Wrapers
These are utility wrappers for specific languages, they are not required to use raylib in the language but may adapt the raylib API to be more inline with the language's paradigm.
| Name | raylib Version | Language | License |
| ---------------------------------------------------- | :------------: | :------------------------------------------: | :-----: |
| [raylib-cpp](https://github.com/robloach/raylib-cpp) | **5.5** | [C++](https://en.wikipedia.org/wiki/C%2B%2B) | Zlib |
| [claylib](https://github.com/defun-games/claylib) | 4.5 | [Common Lisp](https://common-lisp.net) | Zlib |
| [rayed-bqn](https://github.com/Brian-ED/rayed-bqn) | **5.0** | [BQN](https://mlochbaum.github.io/BQN) | MIT |
| [DOOR](https://github.com/RealDoigt/DOOR) | 4.0 | [D](https://dlang.org) | MIT |
### Older or Unmaintained Language Bindings
These are older raylib bindings that are more than 2 versions old or have not been maintained.
| Name | raylib Version | Language |
| ---------------------------------------------------------------------------------- | :------------: | :---------------------------------------------------------------------: |
| [raylib-cppsharp](https://github.com/phxvyper/raylib-cppsharp) | 2.5 | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) |
| [RaylibFS](https://github.com/dallinbeutler/RaylibFS) | 2.5 | [F#](https://fsharp.org) |
| [raylib\*d](https://github.com/Sepheus/raylib_d) | 2.5 | [D](https://dlang.org) |
| [bindbc-raylib](https://github.com/o3o/bindbc-raylib) | 3.0 | [D](https://dlang.org) |
| [go-raylib](https://github.com/chunqian/go-raylib) | 3.5 | [Go](https://golang.org) |
| [raylib-goplus](https://github.com/Lachee/raylib-goplus) | 2.6-dev | [Go](https://golang.org) |
| [ray-go](https://github.com/hecate-tech/ray-go) | 2.6-dev | [Go](https://golang.org) |
| [raylib-luamore](https://github.com/HDPLocust/raylib-luamore) | 3.0 | [Lua](http://www.lua.org) |
| [LuaJIT-Raylib](https://github.com/Bambofy/LuaJIT-Raylib) | 2.6 | [Lua](http://www.lua.org) |
| [raylib-lua-sol](https://github.com/RobLoach/raylib-lua-sol) | 2.5 | [Lua](http://www.lua.org) |
| [raylib-lua-ffi](https://github.com/raysan5/raylib/issues/693) | 2.0 | [Lua](http://www.lua.org) |
| [raylib-lua](https://github.com/raysan5/raylib-lua) | 1.7 | [Lua](http://www.lua.org) |
| [raylib-nelua](https://github.com/Andre-LA/raylib-nelua) | 3.0 | [Nelua](https://nelua.io) |
| [raylib-nim](https://github.com/Skrylar/raylib-nim) | 2.0 | [Nim](https://nim-lang.org) |
| [raylib-Nim](https://gitlab.com/define-private-public/raylib-Nim) | 1.7 | [Nim](https://nim-lang.org) |
| [nim-raylib](https://github.com/tomc1998/nim-raylib) | 3.1-dev | [Nim](https://nim-lang.org) |
| [raylib-Forever](https://github.com/Guevara-chan/Raylib-Forever) | auto | [Nim](https://nim-lang.org) |
| [NimraylibNow!](https://github.com/greenfork/nimraylib_now) | 4.2 | [Nim](https://nim-lang.org) |
| [raylib-haskell](https://github.com/DevJac/raylib-haskell) | 2.0 | [Haskell](https://www.haskell.org) |
| [raylib-cr](https://github.com/AregevDev/raylib-cr) | 2.5-dev | [Crystal](https://crystal-lang.org) |
| [raylib.cr](https://github.com/sam0x17/raylib.cr) | 2.0 | [Crystal](https://crystal-lang.org) |
| [cray](https://gitlab.com/Zatherz/cray) | 1.8 | [Crystal](https://crystal-lang.org) |
| [raylib-pas](https://github.com/tazdij/raylib-pas) | 3.0 | [Pascal](https://en.wikipedia.org/wiki/Pascal*(programming*language)) |
| [raylib-pascal](https://github.com/drezgames/raylib-pascal) | 2.0 | [Pascal](https://en.wikipedia.org/wiki/Pascal*(programming*language)) |
| [Graphics-Raylib](https://github.com/athreef/Graphics-Raylib) | 1.4 | [Perl](https://www.perl.org) |
| [raylib-ruby](https://github.com/a0/raylib-ruby) | 2.6 | [Ruby](https://www.ruby-lang.org/en) |
| [raylib-ruby-ffi](https://github.com/D3nX/raylib-ruby-ffi) | 2.0 | [Ruby](https://www.ruby-lang.org/en) |
| [raylib-mruby](https://github.com/lihaochen910/raylib-mruby) | 2.5-dev | [mruby](https://github.com/mruby/mruby) |
| [raylib-java](https://github.com/XoanaIO/raylib-java) | 2.0 | [Java](https://en.wikipedia.org/wiki/Java*(programming_language)) |
| [clj-raylib](https://github.com/lsevero/clj-raylib) | 3.0 | [Clojure](https://clojure.org) |
| [QuickJS-raylib](https://github.com/sntg-p/QuickJS-raylib) | 3.0 | [QuickJS](https://bellard.org/quickjs) |
| [raylib-duktape](https://github.com/RobLoach/raylib-duktape) | 2.6 | [JavaScript (Duktape)](https://en.wikipedia.org/wiki/JavaScript) |
| [raylib-v7](https://github.com/Rabios/raylib-v7) | 3.5 | [JavaScript (v7)](https://en.wikipedia.org/wiki/JavaScript) |
| [raylib-chaiscript](https://github.com/RobLoach/raylib-chaiscript) | 2.6 | [ChaiScript](http://chaiscript.com) |
| [raylib-squirrel](https://github.com/RobLoach/raylib-squirrel) | 2.5 | [Squirrel](http://www.squirrel-lang.org) |
| [racket-raylib-2d](https://github.com/arvyy/racket-raylib-2d) | 2.5 | [Racket](https://racket-lang.org) |
| [raylib-php-ffi](https://github.com/oraoto/raylib-php-ffi) | 2.4-dev | [PHP](https://en.wikipedia.org/wiki/PHP) |
| [raylib-haxe](https://github.com/ibilon/raylib-haxe) | 2.4 | [Haxe](https://haxe.org) |
| [ringraylib](https://github.com/ringpackages/ringraylib) | 2.6 | [Ring](http://ring-lang.sourceforge.net) |
| [raylib-scm](https://github.com/yashrk/raylib-scm) | 2.5 | [Chicken Scheme](https://www.call-cc.org) |
| [raylib-chibi](https://github.com/VincentToups/raylib-chibi) | 2.5 | [Chibi-Scheme](https://github.com/ashinn/chibi-scheme) |
| [raylib-gambit-scheme](https://github.com/georgjz/raylib-gambit-scheme) | 3.1-dev | [Gambit Scheme](https://github.com/gambit/gambit) |
| [Euraylib](https://github.com/gAndy50/Euraylib) | 3.0 | [Euphoria](https://openeuphoria.org) |
| [raylib-odin](https://github.com/kevinw/raylib-odin) | 3.0 | [Odin](https://odin-lang.org) |
| [vraylib](https://github.com/waotzi/vraylib) | 3.5 | [V](https://vlang.io) |
| [raylib-vala](https://code.guddler.uk/mart/raylibVapi) | 3.0 | [Vala](https://wiki.gnome.org/Projects/Vala) |
| [raylib-jai](https://github.com/kujukuju/raylib-jai) | 3.1-dev | [Jai](https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md) |
| [ray.zig](https://github.com/BitPuffin/zig-raylib-experiments) | 2.5 | [Zig](https://ziglang.org) |
| [raylib-Ada](https://github.com/mimo/raylib-Ada) | 3.0 | [Ada](https://www.adacore.com/about-ada) |
| [raykit](https://github.com/Gamerfiend/raykit) | **???** | [Kit](https://www.kitlang.org) |
| [ray.mod](https://github.com/bmx-ng/ray.mod) | 3.0 | [BlitzMax](https://blitzmax.org) |
| [raylib-mosaic](https://github.com/pluckyporcupine/raylib-mosaic) | 3.0 | [Mosaic](https://github.com/sal55/langs/tree/master/Mosaic) |
| [raylib-xdpw](https://github.com/vtereshkov/raylib-xdpw) | 2.6 | [XD Pascal](https://github.com/vtereshkov/xdpw) |
| [raylib-carp](https://github.com/sacredbirdman/raylib-carp) | 3.0 | [Carp](https://github.com/carp-lang/Carp) |
| [raylib-fb](https://github.com/IchMagBier/raylib-fb) | 3.0 | [FreeBasic](https://www.freebasic.net) |
| [raylib-purebasic](https://github.com/D-a-n-i-l-o/raylib-purebasic) | 3.0 | [PureBasic](https://www.purebasic.com) |
| [raylib-ats2](https://github.com/mephistopheles-8/raylib-ats2) | 3.0 | [ATS2](http://www.ats-lang.org) |
| [raylib-beef](https://github.com/M0n7y5/raylib-beef) | 3.0 | [Beef](https://www.beeflang.org) |
| [raylib-never](https://github.com/never-lang/raylib-never) | 3.0 | [Never](https://github.com/never-lang/never) |
| [raylib.cbl](https://github.com/Martinfx/Cobol/tree/master/OpenCobol/Games/raylib) | 2.0 | [COBOL](https://en.wikipedia.org/wiki/COBOL) |
Missing some language or wrapper? Feel free to create a new one! :)
Usually, raylib bindings follow the convention: `raylib-{language}`
Let me know if you're writing a new binding for raylib, I will list it here!

2599
miniRT/raylib/CHANGELOG Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 3.25)
#this change avoid the warning that appear when we include raylib using Cmake fatch content
project(raylib)
# Avoid excessive expansion of variables in conditionals. In particular, if
# "PLATFORM" is "DRM" then:
#
# if (${PLATFORM} MATCHES "DRM")
#
# may expand e.g to:
#
# if (/usr/lib/aarch64-linux-gnu/libdrm.so MATCHES "DRM")
#
# See https://cmake.org/cmake/help/latest/policy/CMP0054.html
cmake_policy(SET CMP0054 NEW)
# Makes a hidden visibility preset on a static lib respected
# This is used to hide glfw's symbols from the library exports when building an so/dylib
# See https://cmake.org/cmake/help/latest/policy/CMP0063.html
cmake_policy(SET CMP0063 NEW)
# Directory for easier includes
# Anywhere you see include(...) you can check <root>/cmake for that file
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Sets compiler flags and language standard
include(CompilerFlags)
# Registers build options that are exposed to cmake
include(CMakeOptions.txt)
if (UNIX AND NOT APPLE AND NOT "${PLATFORM}" MATCHES "DRM")
if (NOT GLFW_BUILD_WAYLAND AND NOT GLFW_BUILD_X11)
MESSAGE(FATAL_ERROR "Cannot disable both Wayland and X11")
endif()
endif()
# Main sources directory (the second parameter sets the output directory name to raylib)
add_subdirectory(src raylib)
# Uninstall target, only create when building raylib by itself
# Avoid conflicting target names when using raylib with other libraries
if(NOT TARGET uninstall AND PROJECT_IS_TOP_LEVEL)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Uninstall.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
if (${BUILD_EXAMPLES})
MESSAGE(STATUS "Building examples is enabled")
add_subdirectory(examples)
endif()
enable_testing()

View File

@ -0,0 +1,39 @@
# ## Config options ###
include(CMakeDependentOption)
include(EnumOption)
if(EMSCRIPTEN)
# When configuring web builds with "emcmake cmake -B build -S .", set PLATFORM to Web by default
SET(PLATFORM Web CACHE STRING "Platform to build for.")
endif()
enum_option(PLATFORM "Desktop;Web;Android;Raspberry Pi;DRM;SDL" "Platform to build for.")
enum_option(OPENGL_VERSION "OFF;4.3;3.3;2.1;1.1;ES 2.0;ES 3.0" "Force a specific OpenGL Version?")
# Configuration options
option(BUILD_EXAMPLES "Build the examples." ${PROJECT_IS_TOP_LEVEL})
option(CUSTOMIZE_BUILD "Show options for customizing your Raylib library build." OFF)
option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF)
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF)
option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended to run with ASAN)" OFF)
# Shared library is always PIC. Static library should be PIC too if linked into a shared library
option(WITH_PIC "Compile static library as position-independent code" OFF)
option(BUILD_SHARED_LIBS "Build raylib as a shared library" OFF)
cmake_dependent_option(USE_AUDIO "Build raylib with audio module" ON CUSTOMIZE_BUILD ON)
enum_option(USE_EXTERNAL_GLFW "OFF;IF_POSSIBLE;ON" "Link raylib against system GLFW instead of embedded one")
# GLFW build options
option(GLFW_BUILD_WAYLAND "Build the bundled GLFW with Wayland support" OFF)
option(GLFW_BUILD_X11 "Build the bundled GLFW with X11 support" ON)
option(INCLUDE_EVERYTHING "Include everything disabled by default (for CI usage)" OFF)
set(OFF ${INCLUDE_EVERYTHING} CACHE INTERNAL "Replace any OFF by default with \${OFF} to have it covered by this option")
include(ParseConfigHeader)
foreach(FLAG IN LISTS CONFIG_HEADER_FLAGS)
string(REGEX MATCH "([^=]+)=(.+)" _ ${FLAG})
cmake_dependent_option(${CMAKE_MATCH_1} "" ${CMAKE_MATCH_2} CUSTOMIZE_BUILD ${CMAKE_MATCH_2})
endforeach()

View File

@ -0,0 +1,76 @@
## Contributing to raylib
Hello contributors! Welcome to raylib!
Do you enjoy raylib and want to contribute? Nice! You can help with the following points:
- `C programming` - Can you write/review/test/improve the code?
- `Documentation/Tutorials/Example` - Can you write some tutorials/examples?
- `Porting to other platforms` - Can you port/adapt/compile raylib on other systems?
- `Web Development` - Can you help [with the website](https://github.com/raysan5/raylib.com)?
- `Testing` - Can you find some bugs in raylib?
This document contains a set of guidelines to contribute to the project. These are mostly guidelines, not rules.
Use your best judgment, and feel free to propose changes to this document in a pull request.
### raylib philosophy
- raylib is a tool to **ENJOY** videogames programming, every function in raylib is designed as a mini-tutorial on itself.
- raylib is **SIMPLE** and **EASY-TO-USE**, I tried to keep it compact with a small set of functions, if a function is too complex, better not including it.
- raylib is open source and free; educators and institutions can use this tool to **TEACH** videogames programming completely for free.
- raylib is collaborative; contribution of tutorials / code examples / bug fixes / code comments are highly appreciated.
- raylib's license (and its external libs respective licenses) allow using raylib on commercial projects.
### Some interesting reads to start with
- [raylib history](HISTORY.md)
- [raylib architecture](https://github.com/raysan5/raylib/wiki/raylib-architecture)
- [raylib license](LICENSE)
- [raylib roadmap](ROADMAP.md)
[raylib Wiki](https://github.com/raysan5/raylib/wiki) contains some information about the library and is open to anyone to edit.
Feel free to review it if required, just take care not to break something.
### raylib C coding conventions
Despite being written in C, raylib does not follow the standard Hungarian notation for C,
it [follows Pascal-case/camel-case notation](https://github.com/raysan5/raylib/wiki/raylib-coding-conventions),
more common in C# language. All code formatting decisions have been carefully taken
to make it easier for students/users to read, write and understand code.
Source code is extensively commented for that purpose, raylib primary learning method is:
> `Learn by reading code and examples`
For detailed information on building raylib and examples, please check [raylib Wiki](https://github.com/raysan5/raylib/wiki).
### Opening new Issues
To open new issues for raylib (bug, enhancement, discussion...), just try to follow these rules:
- Make sure the issue has not already been reported before by searching on GitHub under Issues.
- If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a
title and clear description, as much relevant information as possible, and a code sample demonstrating the unexpected behavior.
- If applicable, attach some screenshot of the issue and a .zip file with the code sample and required resources.
- On issue description, add a brackets tag about the raylib module that relates to this issue.
If don't know which module, just report the issue, I will review it.
- You can check other issues to see how it's being done!
### Sending a Pull-Request
- Make sure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
- Don't send big pull requests (lots of changelists), they are difficult to review. It's better to send small pull requests, one at a time.
- Verify that changes don't break the build (at least on Windows platform). The more platforms where you can test it, the better, but don't worry
if you cannot test all the platforms.
### Contact information
If you have any doubt, don't hesitate to [contact me](mailto:ray@raylib.com)!.
You can write me a direct mail but you can also contact me on the following networks:
- [raylib Discord](https://discord.gg/raylib) - A direct communication channel for project discussions.
- [raylib twitter](https://twitter.com/raysan5) - My personal twitter account, I usually post about raylib, you can send me PMs.
- [raylib reddit](https://www.reddit.com/r/raylib/) - A good place for discussions or to ask for help.
- [raylib web](http://www.raylib.com/) - On top-right corner there is a bunch of networks where you can find me.
Thank you very much for your time! :)

View File

@ -0,0 +1,94 @@
## C Coding Style Conventions
Here is a list with some of the code conventions used by raylib:
Code element | Convention | Example
--- | :---: | ---
Defines | ALL_CAPS | `#define PLATFORM_DESKTOP`
Macros | ALL_CAPS | `#define MIN(a,b) (((a)<(b))?(a):(b))`
Variables | lowerCase | `int screenWidth = 0;`, `float targetFrameTime = 0.016f;`
Local variables | lowerCase | `Vector2 playerPosition = { 0 };`
Global variables | lowerCase | `bool windowReady = false;`
Constants | lowerCase | `const int maxValue = 8;`
Pointers | MyType *pointer | `Texture2D *array = NULL;`
float values | always x.xf | `float gravity = 10.0f`
Operators | value1*value2 | `int product = value*6;`
Operators | value1/value2 | `int division = value/4;`
Operators | value1 + value2 | `int sum = value + 10;`
Operators | value1 - value2 | `int res = value - 5;`
Enum | TitleCase | `enum TextureFormat`
Enum members | ALL_CAPS | `PIXELFORMAT_UNCOMPRESSED_R8G8B8`
Struct | TitleCase | `struct Texture2D`, `struct Material`
Struct members | lowerCase | `texture.width`, `color.r`
Functions | TitleCase | `InitWindow()`, `LoadImageFromMemory()`
Functions params | lowerCase | `width`, `height`
Ternary Operator | (condition)? result1 : result2 | `printf("Value is 0: %s", (value == 0)? "yes" : "no");`
Some other conventions to follow:
- **ALWAYS** initialize all defined variables.
- **Do not use TABS**, use 4 spaces instead.
- Avoid trailing spaces, please, avoid them
- Control flow statements always are followed **by a space**:
```c
if (condition) value = 0;
while (!WindowShouldClose())
{
}
for (int i = 0; i < NUM_VALUES; i++) printf("%i", i);
// Be careful with the switch formatting!
switch (value)
{
case 0:
{
} break;
case 2: break;
default: break;
}
```
- All conditions checks are **always between parenthesis** but not boolean values:
```c
if ((value > 1) && (value < 50) && valueActive)
{
}
```
- When dealing with braces or curly brackets, open-close them in aligned mode:
```c
void SomeFunction()
{
// TODO: Do something here!
}
```
**If proposing new functions, please try to use a clear naming for function-name and functions-parameters, in case of doubt, open an issue for discussion.**
## Files and Directories Naming Conventions
- Directories will be named using `snake_case`: `resources/models`, `resources/fonts`
- Files will be named using `snake_case`: `main_title.png`, `cubicmap.png`, `sound.wav`
_NOTE: Avoid any space or special character in the files/dir naming!_
## Games/Examples Directories Organization Conventions
- Data files should be organized by context and usage in the game, think about the loading requirements for data and put all the resources that need to be loaded at the same time together.
- Use descriptive names for the files, it would be perfect if just reading the name of the file, it was possible to know what is that file and where fits in the game.
- Here is an example, note that some resources require to be loaded all at once while other require to be loaded only at initialization (gui, font).
```
resources/audio/fx/long_jump.wav
resources/audio/music/main_theme.ogg
resources/screens/logo/logo.png
resources/screens/title/title.png
resources/screens/gameplay/background.png
resources/characters/player.png
resources/characters/enemy_slime.png
resources/common/font_arial.ttf
resources/common/gui.png
```

138
miniRT/raylib/FAQ.md Normal file
View File

@ -0,0 +1,138 @@
# Frequently Asked Questions
- [What is raylib?](#what-is-raylib)
- [What can I do with raylib?](#what-can-i-do-with-raylib)
- [Which kinds of games can I make with raylib?](#which-kinds-of-games-can-i-make-with-raylib)
- [Can I create non-game applications with raylib?](#can-i-create-non-game-applications-with-raylib)
- [How can I learn to use raylib? Is there some official documentation or tutorials?](#how-can-i-learn-to-use-raylib-is-there-some-official-documentation-or-tutorials)
- [How much does it cost?](#how-much-does-it-cost)
- [What is the raylib license?](#what-is-the-raylib-license)
- [What platforms are supported by raylib?](#what-platforms-are-supported-by-raylib)
- [What programming languages can I use with raylib?](#what-programming-languages-can-i-use-with-raylib)
- [Why is it coded in C?](#why-is-it-coded-in-c)
- [Is raylib a videogames engine?](#is-raylib-a-videogames-engine)
- [What does raylib provide that other engines or libraries don't?](#what-does-raylib-provide-that-other-engines-or-libraries-dont)
- [How does raylib compare to Unity/Unreal/Godot?](#how-does-raylib-compare-to-unityunrealgodot)
- [What development tools are required for raylib?](#what-development-tools-are-required-for-raylib)
- [What are raylib's external dependencies?](#what-are-raylibs-external-dependencies)
- [Can I use raylib with other technologies or libraries?](#can-i-use-raylib-with-other-technologies-or-libraries)
- [What file formats are supported by raylib?](#what-file-formats-are-supported-by-raylib)
- [Does raylib support the Vulkan API?](#does-raylib-support-the-vulkan-api)
- [What could I expect to see in raylib in the future?](#what-could-i-expect-to-see-in-raylib-in-the-future)
- [Who are the raylib developers?](#who-are-the-raylib-developers)
- [MORE QUESTIONS...](https://github.com/raysan5/raylib/wiki/Frequently-Asked-Questions)
### What is raylib?
raylib is a C programming library, designed to be simple and easy-to-use. It provides a set of functions intended for graphics/multimedia applications programming.
### What can I do with raylib?
raylib can be used to create any kind of graphics/multimedia applications: videogames, tools, mobile apps, web applications... Actually it can be used to create any application that requires something to be shown in a display with graphic hardware acceleration (OpenGL); including [IoT](https://en.wikipedia.org/wiki/Internet_of_things) devices with a graphics display.
### Which kinds of games can I make with raylib?
With enough time and effort any kind of game/application can be created but small-mid sized 2d videogames are the best fit. The raylib [examples](https://www.raylib.com/examples.html)/[games](https://www.raylib.com/games.html) and [raylibtech](https://raylibtech.itch.io/) tools are an example of what can be accomplished with raylib.
### Can I create non-game applications with raylib?
Yes, raylib can be used to create any kind of application, not just videogames. For example, it can be used to create [desktop/web tools](https://raylibtech.itch.io/) or also applications for an IoT devices like [Raspberry Pi](https://www.raspberrypi.org/).
### How can I learn to use raylib? Is there some official documentation or tutorials?
raylib does not provide a "standard" API reference documentation like other libraries, all of the raylib functionality is exposed in a simple [cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html). Most of the functions are self-explanatory and the required parameters are very intuitive. It's also highly recommended to take a look at [`raylib.h`](https://github.com/raysan5/raylib/blob/master/src/raylib.h) header file or even the source code, that is very clean and organized, intended for teaching.
raylib also provides a big [collection of examples](https://www.raylib.com/examples.html), to showcase the multiple functionality usage (+120 examples). Examples are categorized by the internal module functionality and also define an estimated level of difficulty to guide the users checking them.
There is also a [FAQ on the raylib Wiki](https://github.com/raysan5/raylib/wiki/Frequently-Asked-Questions) with common technical questions.
There are also many tutorials on the internet and YouTube created by the growing raylib community over the years.
[raylib Discord Community](https://discord.gg/raylib) is also a great place to join and ask questions, the community is very friendly and always ready to help.
### How much does it cost?
raylib is [free and open source](https://github.com/raysan5/raylib). Anyone can use raylib library for free to create games/tools/apps but also the source code of raylib is open for anyone to check it, modify it, adapt it as required or just learn how it works internally.
### What is the raylib license?
raylib source code is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed-source software. Check [LICENSE](https://github.com/raysan5/raylib/blob/master/LICENSE) for further details.
### What platforms are supported by raylib?
raylib source code can be compiled for the following platforms:
- Windows (7, 8.1, 10, 11)
- Linux - Desktop (multiple distributions, X11 and Wayland based)
- Linux - Native (no windowing system, [DRM](https://en.wikipedia.org/wiki/Direct_Rendering_Manager))
- macOS (multiple versions, including ARM64)
- FreeBSD, OpenBSD, NetBSD, DragonFly
- Raspberry Pi (desktop and native)
- Android (multiple API versions and architectures)
- HTML5 (WebAssembly)
- Haiku
raylib code has also been ported to several [homebrew](https://en.wikipedia.org/wiki/Homebrew_(video_games)) platforms: N3DS, Switch, PS4, PSVita.
Also note that raylib is a low-level library that can be easily ported to any platform with OpenGL support (or similar API).
### What programming languages can I use with raylib?
raylib original version is coded in C language (using some C99 features) but it has bindings to +60 programming languages. Check [BINDINGS.md](https://github.com/raysan5/raylib/blob/master/BINDINGS.md) for details.
### Why is it coded in C?
It's a simple language, no high-level code abstractions like [OOP](https://en.wikipedia.org/wiki/Object-oriented_programming), just data types and functions. It's a very enjoyable language to code.
### Is raylib a videogames engine?
I personally consider raylib a graphics library with some high-level features rather than an engine. The line that separates a library/framework from an engine could be very confusing; raylib provides all the required functionality to create simple games or small applications but it does not provide 3 elements that I personally consider any "engine" should provide: Screen manager, GameObject/Entity manager and Resource Manager. Still, most users do not need those elements or just code simple approaches on their own.
### What does raylib provide that other engines or libraries don't?
I would say "simplicity" and "enjoyment" at a really low level of coding but actually it is up to the user to discover it, to try it and to see if it fits their needs. raylib is not good for everyone but it's worth a try.
### How does raylib compare to Unity/Unreal/Godot?
Those engines are usually big and complex to use, providing lot of functionality. They require some time to learn and test, they usually abstract many parts of the game development process and they usually provide a set of tools to assist users on their creations (like a GUI editor).
raylib is a simple programming library, with no integrated tools or editors. It gives full control to users at a very low level to create graphics applications in a more handmade way.
### What development tools are required for raylib?
To develop raylib programs you only need a text editor (with recommended code syntax highlighting) and a compiler.
A [raylib Windows Installer](https://raysan5.itch.io/raylib) package is distributed including the Notepad++ editor and MinGW (GCC) compiler pre-configured for Windows for new users as an starter-pack but for more advanced configurations with other editors/compilers, [raylib Wiki](https://github.com/raysan5/raylib/wiki) provides plenty of configuration tutorials.
### What are raylib's external dependencies?
raylib is self-contained, it has no external dependencies to build it. But internally raylib uses several libraries from other developers, mostly used to load specific file formats.
A detailed list of raylib dependencies can be found on the [raylib Wiki](https://github.com/raysan5/raylib/wiki/raylib-dependencies).
### Can I use raylib with other technologies or libraries?
Yes, raylib can be used with other libraries that provide specific functionality. There are multiple examples of raylib integrations with libraries like Spine, Tiled, Dear Imgui and several physics engines.
### What file formats are supported by raylib?
raylib can load data from multiple standard file formats:
- Image/Textures: PNG, BMP, TGA, JPG, GIF, QOI, PSD, DDS, HDR, KTX, ASTC, PKM, PVR
- Fonts: FNT (sprite font), TTF, OTF
- Models/Meshes: OBJ, IQM, GLTF, VOX, M3D
- Audio: WAV, OGG, MP3, FLAC, XM, MOD, QOA
### Does raylib support the Vulkan API?
No, raylib is built on top of OpenGL API, and there are currently no plans to support any other graphics APIs. In any case, raylib uses rlgl as an abstraction layer to support different OpenGL versions. If really required, a Vulkan backend equivalent could be added but creating that abstraction layer would imply a considerable amount of work.
### What could I expect to see in raylib in the future?
The main focus of the library is simplicity. Most of the efforts are invested in maintainability and bug-fixing. Despite new small features being regularly added, it's not the objective for raylib to become a full-featured engine. Personally I prefer to keep it small and enjoyable.
### Who are the raylib developers?
The main raylib developer and maintainer is [Ramon Santamaria](https://www.linkedin.com/in/raysan/) but there are 360+ contributors that have helped by adding new features, testing the library and solving issues in the 9+ years life of raylib.
The full list of raylib contributors can be seen [on GitHub](https://github.com/raysan5/raylib/graphs/contributors).

524
miniRT/raylib/HISTORY.md Normal file
View File

@ -0,0 +1,524 @@
![raylib logo](logo/raylib_256x256.png)
introduction
------------
I started developing videogames in 2006 and some years later I started teaching videogames development to young people with artistic profiles, most of students had never written a single line of code.
I decided to start with C language basis and, after searching for the most simple and easy-to-use library to teach videogames programming, I found [WinBGI](https://winbgim.codecutter.org/); it was great and it worked very well with students, in just a couple of weeks, those students that had never written a single line of code were able to program (and understand) a simple PONG game, some of them even a BREAKOUT!
But WinBGI was not the clearest and most organized library for my taste. There were lots of things I found confusing and some function names were not clear enough for most of the students; not to mention the lack of transparencies support and no hardware acceleration.
So, I decided to create my own library, hardware accelerated, clear function names, quite organized, well structured, plain C coding and, most importantly, primarily intended to learn videogames programming.
My previous videogames development experience was mostly in C# and [XNA](https://en.wikipedia.org/wiki/Microsoft_XNA) and I really loved it, so, I decided to use C# language style notation and XNA naming conventions. That way, students were able to move from raylib to XNA, MonoGame or similar libs extremely easily.
raylib started as a weekend project and after three months of hard work, **raylib 1.0 was published on November 2013**.
Enjoy it.
notes on raylib 1.1
-------------------
On April 2014, after 6 months of first raylib release, raylib 1.1 was released. This new version presents a complete internal redesign of the library to support OpenGL 1.1, OpenGL 3.3+ and OpenGL ES 2.0.
- A new module named [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.h) has been added to the library. This new module translates raylib-OpenGL-style immediate mode functions (i.e. rlVertex3f(), rlBegin(), ...) to different versions of OpenGL (1.1, 3.3+, ES2), selectable by one define.
- [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.h) also comes with a second new module named [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h), which includes a bunch of useful functions for 3d-math with vectors, matrices and quaternions.
Some other big changes of this new version have been the support for OGG file loading and stream playing, and the support of DDS texture files (compressed and uncompressed) along with mipmaps support.
Lots of code changes and a lot of testing have concluded in this amazing new raylib 1.1.
notes on raylib 1.2
-------------------
On September 2014, after 5 months of raylib 1.1 release, it comes raylib 1.2. Again, this version presents a complete internal redesign of [core](https://github.com/raysan5/raylib/blob/master/src/rcore.c) module to support two new platforms: [Android](http://www.android.com/) and [Raspberry Pi](http://www.raspberrypi.org/).
It's been some months of really hard work to accommodate raylib to those new platforms while keeping it easy for the users. On Android, raylib manages internally the activity cycle, as well as the inputs; on Raspberry Pi, a complete raw input system has been written from scratch.
- A new display initialization system has been created to support multiple resolutions, adding black bars if required; the user only defines the desired screen size and it gets properly displayed.
- Now raylib can easily deploy games to Android devices and Raspberry Pi (console mode).
Lots of code changes and a lot of testing have concluded in this amazing new raylib 1.2.
In December 2014, new raylib 1.2.2 was published with support to compile directly for web (html5) using [emscripten](http://kripken.github.io/emscripten-site/) and [asm.js](http://asmjs.org/).
notes on raylib 1.3
-------------------
On September 2015, after 1 year of raylib 1.2 release, arrives raylib 1.3. This version adds shaders functionality, improves tremendously textures module and also provides some new modules (camera system, gestures system, immediate-mode gui).
- Shaders support is the biggest addition to raylib 1.3, with support for easy shaders loading and use. Loaded shaders can be attached to 3d models or used as fullscreen post-processing effects. A bunch of postprocessing shaders are also included in this release, check raylib/shaders folder.
- Textures module has grown to support most of the internal texture formats available in OpenGL (RGB565, RGB888, RGBA5551, RGBA4444, etc.), including compressed texture formats (DXT, ETC1, ETC2, ASTC, PVRT); raylib 1.3 can load .dds, .pkm, .ktx, .astc and .pvr files.
- A brand new [camera](https://github.com/raysan5/raylib/blob/master/src/rcamera.h) module offers to the user multiple preconfigured ready-to-use camera systems (free camera, 1st person, 3rd person). Camera modes are very easy to use, just check examples: [core_3d_camera_free.c](https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_free.c) and [core_3d_camera_first_person.c](https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_first_person.c).
- New [gestures](https://github.com/raysan5/raylib/blob/master/src/rgestures.h) module simplifies gestures detection on Android and HTML5 programs.
- [raygui](https://github.com/raysan5/raylib/blob/master/examples/shapes/raygui.h), the new immediate-mode GUI module offers a set of functions to create simple user interfaces, primarily intended for tools development. It's still in an experimental state but already fully functional.
Most of the examples have been completely rewritten and +10 new examples have been added to show the new raylib features.
Lots of code changes and a lot of testing have concluded in this amazing new raylib 1.3.
notes on raylib 1.4
-------------------
On February 2016, after 4 months of raylib 1.3 release, it comes raylib 1.4. For this new version, lots of parts of the library have been reviewed, lots of bugs have been solved and some interesting features have been added.
- First big addition is a set of [Image manipulation functions](https://github.com/raysan5/raylib/blob/master/src/raylib.h#L1331) that have been added to crop, resize, colorize, flip, dither and even draw image-to-image or text-to-image. Now basic image processing can be done before converting the image to texture for usage.
- SpriteFonts system has been improved, adding support for AngelCode fonts (.fnt) and TrueType Fonts (using [stb_truetype](https://github.com/nothings/stb/blob/master/stb_truetype.h) helper library). Now raylib can read standard .fnt font data and also generate at loading a SpriteFont from a TTF file.
- New [physac](https://github.com/raysan5/raylib/blob/master/src/physac.h) physics module for basic 2D physics support. Still in development but already functional. Module comes with some usage examples for basic jump and level interaction and also force-based physic movements.
- [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h) module has been reviewed; some bugs have been solved and the module has been converted to a header-only file for easier portability, optionally, functions can also be used as inline.
- [gestures](https://github.com/raysan5/raylib/blob/master/src/rgestures.h) module has been redesigned and simplified, now it can process touch events from any source, including the mouse. This way, gestures system can be used on any platform providing a unified way to work with inputs and allowing the user to create multiplatform games with only one source code.
- Raspberry Pi input system has been redesigned to better read raw inputs using generic Linux event handlers (keyboard:`stdin`, mouse:`/dev/input/mouse0`, gamepad:`/dev/input/js0`). Gamepad support has also been added (experimental).
Other important improvements are the functional raycast system for 3D picking, including some ray collision-detection functions,
and the addition of two simple functions for persistent data storage. Now raylib users can save and load game data in a file (only some platforms are supported). A simple [easings](https://github.com/raysan5/raylib/blob/master/examples/shapes/reasings.h) module has also been added for values animation.
Up to 8 new code examples have been added to show the new raylib features and +10 complete game samples have been provided to learn
how to create some classic games like Arkanoid, Asteroids, Missile Commander, Snake or Tetris.
Lots of code changes and lots of hours of hard work have concluded in this amazing new raylib 1.4.
notes on raylib 1.5
-------------------
On July 2016, after 5 months of raylib 1.4 release, arrives raylib 1.5. This new version is the biggest boost of the library until now, lots of parts of the library have been redesigned, lots of bugs have been solved and some **AMAZING** new features have been added.
- VR support: raylib supports **Oculus Rift CV1**, one of the most anticipated VR devices in the market. Additionally, raylib supports simulated VR stereo rendering, independent of the VR device; it means, raylib can generate stereo renders with custom head-mounted-display device parameters, that way, any VR device in the market can be **simulated in any platform** just configuring device parameters (and consequently, lens distortion). To enable VR is [extremely easy](https://github.com/raysan5/raylib/blob/master/examples/core_oculus_rift.c).
- New materials system: now raylib supports standard material properties for 3D models, including diffuse-ambient-specular colors and diffuse-normal-specular textures. Just assign values to standard material and everything is processed internally.
- New lighting system: added support for up to 8 configurable lights and 3 light types: **point**, **directional** and **spot** lights. Just create a light, configure its parameters and raylib manages to render internally for every 3d object using standard material.
- Complete gamepad support on Raspberry Pi: Gamepad system has been completely redesigned. Now multiple gamepads can be easily configured and used; gamepad data is read and processed in raw mode in a second thread.
- Redesigned physics module: [physac](https://github.com/raysan5/raylib/blob/master/src/physac.h) module has been converted to header only and usage [has been simplified](https://github.com/raysan5/raylib/blob/master/examples/physics_basic_rigidbody.c). Performance has also been significantly improved, now physic objects are managed internally in a second thread.
- Audio chiptunes support and mixing channels: Added support for module audio music (.xm, .mod) loading and playing. Multiple mixing channels are now also supported. All these features thanks to the amazing work of @kd7tck.
Other additions include a [2D camera system](https://github.com/raysan5/raylib/blob/master/examples/core/core_2d_rcamera.c), render textures for offline render (and most comprehensive [postprocessing](https://github.com/raysan5/raylib/blob/master/examples/shaders/shaders_postprocessing.c)) or support for legacy OpenGL 2.1 on desktop platforms.
This new version is so massive that is difficult to list all the improvements, most of the raylib modules have been reviewed and [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.h) module has been completely redesigned to accommodate to new material-lighting systems and stereo rendering. You can check [CHANGELOG](https://github.com/raysan5/raylib/blob/master/CHANGELOG) file for a more detailed list of changes.
Up to 8 new code examples have been added to show the new raylib features and also some samples to show the usage of [rlgl](https://github.com/raysan5/raylib/blob/master/examples/others/rlgl_standalone.c) and [audio](https://github.com/raysan5/raylib/blob/master/examples/audio_standalone.c) raylib modules as standalone libraries.
Lots of code changes (+400 commits) and lots of hours of hard work have concluded in this amazing new raylib 1.5.
notes on raylib 1.6
-------------------
On November 2016, only 4 months after raylib 1.5, arrives raylib 1.6. This new version represents another big review of the library and includes some interesting additions. This version commemorates raylib 3rd anniversary (raylib 1.0 was published on November 2013) and it is a stepping stone for raylib future. raylib roadmap has been reviewed and redefined to focus on its primary objective: create a simple and easy-to-use library to learn videogames programming. Some of the new features:
- Complete [raylib Lua binding](https://github.com/raysan5/raylib-lua). All raylib functions plus the +60 code examples have been ported to Lua, now Lua users can enjoy coding videogames in Lua while using all the internal power of raylib. This addition also open the doors to Lua scripting support for a future raylib-based engine, being able to move game logic (Init, Update, Draw, De-Init) to Lua scripts while keep using raylib functionality.
- Completely redesigned [audio module](https://github.com/raysan5/raylib/blob/master/src/raudio.c). Based on the new direction taken in raylib 1.5, it has been further improved and more functionality added (+20 new functions) to allow raw audio processing and streaming. [FLAC file format support](https://github.com/raysan5/raylib/blob/master/src/external/dr_flac.h) has also been added. In the same line, [OpenAL Soft](https://github.com/kcat/openal-soft) backend is now provided as a static library in Windows to allow static linking and get ride of OpenAL32.dll. Now raylib Windows games are completely self-contained, no external libraries are required anymore!
- [Physac](https://github.com/victorfisac/Physac) module has been moved to its own repository and it has been improved A LOT, actually, the library has been completely rewritten from scratch by [@victorfisac](https://github.com/victorfisac), multiple samples have been added together with countless new features to match current standard 2D physic libraries. Results are amazing!
- Camera and gestures modules have been reviewed, highly simplified and ported to single-file header-only libraries for easier portability and usage flexibility. Consequently, camera system usage has been simplified in all examples.
- Improved Gamepad support on Windows and Raspberry Pi with the addition of new functions for custom gamepad configurations but supporting by default PS3 and Xbox-based gamepads.
- Improved textures and text functionality, adding new functions for texture filtering control and better TTF/AngelCode fonts loading and generation support.
Build system improvement. Added support for raylib dynamic library generation (raylib.dll) for users that prefer dynamic library linking. Also thinking on advanced users, it has been added pre-configured [Visual Studio C++ 2015 solution](https://github.com/raysan5/raylib/tree/master/projects/vs2015) with raylib project and C/C++ examples for users that prefer that professional IDE and compiler.
New examples, new functions, complete code-base review, multiple bugs corrected... this is raylib 1.6. Enjoy making games.
notes on raylib 1.7
-------------------
On May 2017, around 6 months after raylib 1.6, comes another raylib installment, raylib 1.7. This time library has been improved a lot in terms of consistency and cleanness. As stated in [this patreon article](https://www.patreon.com/posts/raylib-future-7501034), this new raylib version has focused efforts in becoming more simple and easy-to-use to learn videogames programming. Some highlights of this new version are:
- More than 30 new functions added to the library, functions to control Window, utils to work with filenames and extensions, functions to draw lines with custom thick, mesh loading, functions for 3d ray collisions detailed detection, functions for VR simulation and much more... Just check [CHANGELOG](CHANGELOG) for a detailed list of additions!
- Support of [configuration flags](https://github.com/raysan5/raylib/issues/200) on every raylib module. Advanced users can customize raylib just by choosing desired features, and defining some configuration flags on modules compilation. That way users can control library size and available functionality.
- Improved [build system](https://github.com/raysan5/raylib/blob/master/src/Makefile) for all supported platforms (Windows, Linux, OSX, RPI, Android, HTML5) with a unique Makefile to compile sources. Added support for Android compilation with a custom standalone toolchain and also multiple build compilation flags.
- New [examples](http://www.raylib.com/examples.html) and [sample games](http://www.raylib.com/games.html) added. All sample material has been reviewed, removing useless examples and adding more comprehensive ones; all material has been ported to the latest raylib version and tested on multiple platforms. Examples folder structure has been improved and also build systems.
- Improved library consistency and organization in general. Functions and parameters have been renamed, some parts of the library have been cleaned and simplified, some functions have been moved to examples (lighting, Oculus Rift CV1 support) towards a more generic library implementation. Lots of hours have been invested in this process...
Some other features: Gamepad support on HTML5, RPI touch screen support, 32bit audio support, frames timing improvements, public log system, rres file format support, automatic GIF recording...
And here is another version of **raylib, a simple and easy-to-use library to enjoy videogames programming**. Enjoy it.
notes on raylib 1.8
-------------------
October 2017, around 5 months after latest raylib version, another release is published: raylib 1.8. Again, several modules of the library have been reviewed and some new functionality added. Main changes of this new release are:
- [Procedural image generation](https://github.com/raysan5/raylib/blob/master/examples/textures/textures_image_generation.c) function, a set of new functions have been added to generate gradients, checked, noise and cellular images from scratch. Image generation could be useful for certain textures or learning purposes.
- [Parametric mesh generation](https://github.com/raysan5/raylib/blob/master/examples/models/models_mesh_generation.c) functions, create 3d meshes from scratch just defining a set of parameters, meshes like cube, sphere, cylinder, torus, knot and more can be very useful for prototyping or for lighting and texture testing.
- PBR Materials support, a completely redesigned shaders and material system allows advanced materials definition and usage, with fully customizable shaders. Some new functions have been added to generate the environment textures required for PBR shading and a a new complete [PBR material example](https://github.com/raysan5/raylib/blob/master/examples/models/models_material_pbr.c) is also provided for reference.
- Custom Android APK build pipeline with [simple Makefile](https://github.com/raysan5/raylib/blob/master/templates/simple_game/Makefile). Actually, full code building mechanism based on plain Makefile has been completely reviewed and Android building has been added for sources and also for examples and templates building into the final APK package. This way, raylib Android building has been greatly simplified and integrated seamlessly into standard build scripts.
- [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.h) module has been completely reviewed and most of the functions renamed for consistency. This way, standalone usage of rlgl is promoted, with a [complete example provided](https://github.com/raysan5/raylib/blob/master/examples/others/rlgl_standalone.c). rlgl offers a pseudo-OpenGL 1.1 immediate-mode programming-style layer, with backends to multiple OpenGL versions.
- [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h) library has been also reviewed to align with other advance math libraries like [GLM](https://github.com/g-truc/glm). Matrix math has been improved and simplified, some new Quaternion functions have been added and Vector3 functions have been renamed all around the library for consistency with new Vector2 functionality.
Additionally, as always, examples and templates have been reviewed to work with new version (some new examples have been added), all external libraries have been updated to latest stable version and latest Notepad++ and MinGW have been configured to work with new raylib. For a full list of changes, just check [CHANGELOG](CHANGELOG).
New installer provided, web updated, examples re-builded, documentation reviewed... **new raylib 1.8 published**. Enjoy coding games.
notes on raylib 2.0
-------------------
It's been 9 months since last raylib version was published, a lot of things have changed since then... This new raylib version represents an inflection point in the development of the library and so, we jump to a new major version... Here is the result of almost **5 years and thousands of hours of hard work**... here is... **raylib 2.0**
In **raylib 2.0** the full API has been carefully reviewed for better consistency, some new functionality has been added and the overall raylib experience has been greatly improved... The key features of new version are:
- **Complete removal of external dependencies.** Finally, raylib does not require external libraries to be installed and linked along with raylib, all required libraries are contained and compiled within raylib. Obviously some external libraries are required but only the strictly platform-dependent ones, the ones that come installed with the OS. So, raylib becomes a self-contained platform-independent games development library.
- **Full redesign of audio module to use the amazing miniaudio library**, along with external dependencies removal, OpenAL library has been replaced by [miniaudio](https://github.com/dr-soft/miniaudio), this brand new library offers automatic dynamic linking with default OS audio systems. Undoubtedly, the perfect low-level companion for raylib audio module!
- **Support for continuous integration building*** through AppVeyor and Travis CI. Consequently, raylib GitHub develop branch has been removed, simplifying the code-base to a single master branch, always stable. Every time a new commit is deployed, library is compiled for **up-to 12 different configurations**, including multiple platforms, 32bit/64bit and multiple compiler options! All those binaries are automatically attached to any new release!
- **More platforms supported and tested**, including BSD family (FreeBSD, openBSD, NetBSD, DragonFly) and Linux-based family platforms (openSUSE, Debian, Ubuntu, Arch, NixOS...). raylib has already been added to some package managers! Oh, and last but not less important, **Android 64bit** is already supported by raylib!
- **Support for TCC compiler!** Thanks to the lack of external dependencies, raylib can now be easily compiled with a **minimal toolchain**, like the one provided by Tiny C Compiler. It opens the door to an amazing future, allowing, for example, static linkage of libtcc for **runtime compilation of raylib-based code**... and the library itself if required! Moreover, TCC is blazing fast, it can compile all raylib in a couple of seconds!
- Refactored all raylib configuration #defines into a **centralized `config.h` header**, with more than **40 possible configuration options** to compile a totally customizable raylib version including only desired options like supported file formats or specific functionality support. It allows generating a trully ligth-weight version of the library if desired!
A part of that, lots of new features, like a brand **new font rendering and packaging system** for TTF fonts with **SDF support** (thanks to the amazing STB headers), new functions for **CPU image data manipulation**, new orthographic 3d camera mode, a complete review of `raymath.h` single-file header-only library for better consistency and performance, new examples and way, [way more](https://github.com/raysan5/raylib/blob/master/CHANGELOG).
Probably by now, **raylib 2.0 is the simplest and easiest-to-use library to enjoy (and learn) videogames programming**... but, undoubtedly its development has exceeded any initial objective; raylib has become a simple and easy-to-use truly multiplatform portable standalone media library with thousands of possibilities... and that's just the beginning!
notes on raylib 2.5
-------------------
After almost one years since latest raylib installment, here is **raylib 2.5**. A lot of work has been put on this new version and consequently I decided to bump versioning several digits. The complete list of changes and additions is humungous, details can be found in the [CHANGELOG](CHANGELOG), and here is a short recap with the highlight improvements.
- New **window management and file system functions** to query monitor information, deal with clipboard, check directory files info and even launch a URL with default system web browser. Experimental **High-DPI monitor support** has also been added through a compile flag.
- **Redesigned Gamepad mechanism**, now generic for all platforms and gamepads, no more specific gamepad configurations.
**Redesigned UWP input system**, now raylib supports UWP seamlessly, previous implementation required a custom input system implemented in user code.
- `rlgl` module has been redesigned to **support a unique buffer for shapes drawing batching**, including LINES, TRIANGLES, QUADS in the same indexed buffer, also added support for multi-buffering if required. Additionally, `rlPushMatrix()`/`rlPopMatrix()` functionality has been reviewed to behave exactly like OpenGL 1.1, `models_rlgl_solar_system` example has been added to illustrate this behavior.
- **VR simulator** has been reviewed to **allow custom configuration of Head-Mounted-Device parameters and distortion shader**, `core_vr_simulator` has been properly adapted to showcase this new functionality, now the VR simulator is a generic configurable stereo rendering system that allows any VR device simulation with just a few lines of code or even dynamic tweaking of HMD parameters.
- Support for **Unicode text drawing**; now raylib processes UTF8 strings on drawing, supporting Unicode codepoints, allowing rendering mostly any existent language (as long as the font with the glyphs is provided). An amazing example showing this feature has also been added: `text_unicode`.
- Brand **new text management API**, with the addition of multiple functions to deal with string data, including functionality like replace, insert, join, split, append, to uppercase, to lower... Note that most of those functions are intended for text management on rendering, using pre-loaded internal buffers, avoiding new memory allocation that user should free manually.
- Multiple **new shapes and textures drawing functions** to support rings (`DrawRing()`, `DrawRingLines()`), circle sectors (`DrawCircleSector()`, `DrawCircleSectorLines()`), rounded rectangles (`DrawRectangleRounded()`, `DrawRectangleRoundedLines()`) and also n-patch textures (`DrawTextureNPatch()`), detailed examples have been added to illustrate all this new functionality.
- Experimental **cubemap support**, to automatically load multiple cubemap layouts (`LoadTextureCubemap()`). It required some internal `rlgl` redesign to allow cubemap textures.
- **Skeletal animation support for 3d models**, this addition implied a redesign of `Model` data structure to accommodate multiple mesh/multiple materials support and bones information. Multiple models functions have been reviewed and added on this process, also **glTF models loading support** has been added.
This is just a brief list with some of the changes of the new **raylib 2.5** but there is way more, about **70 new functions** have been added and several subsystems have been redesigned. More than **30 new examples** have been created to show the new functionalities and better illustrate already available ones.
It has been a long year of hard work to make raylib a solid technology to develop new products over it.
notes on raylib 3.0
-------------------
After **10 months of intense development**, new raylib version is ready. Despite primary intended as a minor release, the [CHANGELIST](CHANGELOG) has grown so big and the library has changed so much internally that it finally became a major release. Library **internal ABI** has received a big redesign and review, targeting portability, integration with other platforms and making it a perfect option for other programming [language bindings](BINDINGS.md).
- All **global variables** from the multiple raylib modules have been moved to a **global context state**, it has several benefits, first, better code readability with more comprehensive variable naming and categorization (organized by types, i.e. `CORE.Window.display.width`, `CORE.Input.Keyboard.currentKeyState` or `RLGL.State.modelview`). Second, it allows better memory management to load global context state dynamically when required (not at the moment), making it easy to implement a **hot-reloading mechanism** if desired.
- All **memory allocations** on raylib and its dependencies now use `RL_MALLOC`, `RL_FREE` and similar macros. Now users can easily hook their own memory allocation mechanism if desired, having more control over memory allocated internally by the library. Additionally, it makes it easier to port the library to embedded devices where memory control is critical. For more info check raylib issue #1074.
- All **I/O file accesses** from raylib are being moved to **memory data access**, now all I/O file access is centralized into just four functions: `LoadFileData()`, `SaveFileData()`, `LoadFileText()`, `SaveFileText()`. Users can just update those functions to any I/O file system. This change makes it easier to integrate raylib with **Virtual File Systems** or custom I/O file implementations.
- All **raylib data structures** have been reviewed and optimized for pass-by-value usage. One of raylib distinctive design decisions is that most of its functions receive and return data by value. This design makes raylib really simple for newcomers, avoiding pointers and allowing complete access to all structures data in a simple way. The downside is that data is copied on stack every function call and that copy could be costly so, all raylib data structures have been optimized to **stay under 64 bytes** for fast copy and retrieve.
- All **raylib tracelog messages** have been reviewed and categorized for a more comprehensive output information when developing raylib applications, now all display, input, timer, platform, auxiliar libraries, file-accesses, data loading/unloading issues are properly reported with more detailed and visual messages.
- `raudio` module has been internally reviewed to accommodate the new `Music` structure (converted from previous pointer format) and the module has been adapted to the **highly improved** [`miniaudio v0.10`](https://github.com/dr-soft/miniaudio).
- `text` module reviewed to **improve fonts generation** and text management functions, `Font` structure has been redesigned to better accommodate characters data, decoupling individual characters as `Image` glyphs from the font atlas parameters. Several improvements have been made to better support Unicode strings with UTF-8 encoding.
- **Multiple new examples added** (most of them contributed by raylib users) and all examples reviewed for correct execution on most of the supported platforms, specially Web and Raspberry Pi. A detailed categorized table has been created on github for easy examples navigation and code access.
- New **GitHub Actions CI** system has been implemented for Windows, Linux and macOS code and examples compilation on every new commit or PR to make sure library keeps stable and usable with no breaking bugs.
Note that only key changes are listed here but there is way more! About **30 new functions**, multiple functions reviewed, bindings to [+40 programming languages](https://github.com/raysan5/raylib/blob/master/BINDINGS.md) and great samples/demos/tutorials [created by the community](https://discord.gg/raylib), including raylib integration with [Spine](https://github.com/WEREMSOFT/spine-raylib-runtimes), [Unity](https://unitycoder.com/blog/2019/12/09/using-raylib-dll-in-unity/), [Tiled](https://github.com/OnACoffeeBreak/raylib_tiled_import_with_tmx), [Nuklear](http://bedroomcoders.co.uk/implementing-a-3d-gui-with-raylib/), [enet](https://github.com/nxrighthere/NetDynamics) and [more](https://github.com/raysan5/raylib/issues/1079)!
It has been **10 months of improvements** to create the best raylib ever.
Welcome to **raylib 3.0**.
notes on raylib 3.5 - 7th Anniversary Edition
---------------------------------------------
It's December 25th... this crazy 2020 is about to finish and finally the holidays gave me some time to put a new version of raylib. It's been **9 months since last release** and last November raylib become 7 years old... I was not able to release this new version back then but here it is. Many changes and improvements have happened in those months and, even, last August, raylib was awarded with an [Epic Megagrant](https://www.unrealengine.com/en-US/blog/epic-megagrants-fall-2020-update)! Bindings list kept growing to [+50 programming languages](BINDINGS.md) and some new platforms have been supported. Let's see this new version details:
First, some general numbers of this new update:
- **+650** commits since previous RELEASE
- **+30** functions ADDED (for a TOTAL of **475**!)
- **+90** functions REVIEWED/REDESIGNED
- **+30** contributors (for a TOTAL of **170**!)
- **+8** new examples (for a TOTAL of **+120**!)
Here the list with some highlights for `raylib 3.5`.
- NEW **Platform** supported: **Raspberry Pi 4 native mode** (no X11 windows) through [DRM](https://en.wikipedia.org/wiki/Direct_Rendering_Manager) subsystem and GBM API. Actually this is a really interesting improvement because it opens the door to raylib to support other embedded platforms (Odroid, GameShell, NanoPi...). Also worth mentioning the un-official homebrew ports of raylib for [PS4](https://github.com/orbisdev/orbisdev-orbisGl2) and [PSVita](https://github.com/psp2dev/raylib4Vita).
- NEW **configuration options** exposed: For custom raylib builds, `config.h` now exposes **more than 150 flags and defines** to build raylib with only the desired features, for example, it allows to build a minimal raylib library in just some KB removing all external data filetypes supported, very useful to generate **small executables or embedded devices**.
- NEW **automatic GIF recording** feature: Actually, automatic GIF recording (**CTRL+F12**) for any raylib application has been available for some versions but this feature was really slow and low-performant using an old gif library with many file accesses. It has been replaced by a **high-performant alternative** (`msf_gif.h`) that operates directly on memory... and actually works very well! Try it out!
- NEW **RenderBatch** system: `rlgl` module has been redesigned to support custom **render batches** to allow grouping draw calls as desired, previous implementation just had one default render batch. This feature has not been exposed to raylib API yet but it can be used by advanced users dealing with `rlgl` directly. For example, multiple `RenderBatch` can be created for 2D sprites and 3D geometry independently.
- NEW **Framebuffer** system: `rlgl` module now exposes an API for custom **Framebuffer attachments** (including cubemaps!). raylib `RenderTexture` is a basic use-case, just allowing color and depth textures, but this new API allows the creation of more advanced Framebuffers with multiple attachments, like the **G-Buffers**. `GenTexture*()` functions have been redesigned to use this new API.
- Improved **software rendering**: raylib `Image*()` API is intended for software rendering, for those cases when **no GPU or no Window is available**. Those functions operate directly with **multi-format** pixel data on RAM and they have been completely redesigned to be way faster, specially for small resolutions and retro-gaming. Low-end embedded devices like **microcontrollers with custom displays** could benefit of this raylib functionality!
- File **loading from memory**: Multiple functions have been redesigned to load data from memory buffers **instead of directly accessing the files**, now all raylib file loading/saving goes through a couple of functions that load data into memory. This feature allows **custom virtual-file-systems** and it gives more control to the user to access data already loaded in memory (i.e. images, fonts, sounds...).
- NEW **Window states** management system: raylib `core` module has been redesigned to support Window **state check and setup more easily** and also **before/after Window initialization**, `SetConfigFlags()` has been reviewed and `SetWindowState()` has been added to control Window minification, maximization, hiding, focusing, topmost and more.
- NEW **GitHub Actions** CI/CD system: Previous CI implementation has been reviewed and improved a lot to support **multiple build configurations** (platforms, compilers, static/shared build) and also an **automatic deploy system** has been implemented to automatically attach the different generated artifacts to every new release. As the system seems to work very good, previous CI platforms (AppVeyor/TravisCI) have been removed.
A part of those changes, many new functions have been added, some redundant functions removed and many functions have been reviewed for consistency with the full API (function name, parameters name and order, code formatting...). Again, this release represents is a **great improvement for raylib and marks the way forward** for the library. Make sure to check [CHANGELOG](CHANGELOG) for details! Hope you enjoy it!
Happy holidays! :)
notes on raylib 3.7
-------------------
April 2021, it's been about 4 months since the last raylib release and here is already a new one, this time with a bunch of internal redesigns and improvements. Surprisingly, on April 8th I was awarded for a second time with the [Google Open Source Peer Bonus Award](https://opensource.googleblog.com/2021/04/announcing-first-group-of-google-open-source-peer-bonus-winners.html) for my contribution to open source world with raylib and it seems the library is getting some traction, what a better moment for a new release? Let's see what can be found in this new version:
Let's start with some numbers:
- **+100** closed issues (for a TOTAL of **+900**!)
- **+400** commits since previous RELEASE
- **+50** functions ADDED (**+30** of them to rlgl API)
- **+30** functions REVIEWED/REDESIGNED
- **+40** new contributors (for a TOTAL of **+210**!)
Highlights for `raylib 3.7`:
- **REDESIGNED: `rlgl` module for greater abstraction level**. This suppose an **important change in raylib architecture**, now `rlgl` functionality is self-contained in the module and used by higher-level layers (specially by `core` module), those upper layers are the ones that expose functionality to the main API when required, for example the `Shaders`, `Mesh` and `Materials` functionality. Multiple `rlgl` functions have been renamed for consistency, in this case, following the `rl*()` prefix convention. Functions have also been reorganized internally by categories and `GenTexture*()` functions have been removed from the library and moved to [`models_material_pbr`](https://github.com/raysan5/raylib/blob/master/examples/models/models_material_pbr.c) example.
- **REDESIGNED: VR simulator and stereo rendering mechanism**. A **brand new API** has been added, more comprehensive and better integrated with raylib, the **new stereo rendering** can be combined with `RenderTexture` and `Shader` API allowing the user to **manage fbo and distortion shader directly**. Also, the new rendering mechanism supports **instancing on stereo rendering**! Check the updated [`core_vr_simulator`](https://github.com/raysan5/raylib/blob/master/examples/core/core_vr_simulator.c) example for reference!
- **ADDED: New file access callbacks system**. Several new callback functions have been added to the API to allow custom file loaders. A [nice example](https://github.com/RobLoach/raylib-physfs) it's the **raylib integration with a virtual file system** [PhysFS](https://icculus.org/physfs/).
- **ADDED: glTF animations support**. glTF is the preferred models file format to be used with raylib and along the addition of a models animation API on latest raylib versions, now animations support for glTF format has come to raylib, thanks for this great contribution to [Hristo Stamenov](@object71)
- **ADDED: Music streaming support from memory**. raylib has been adding the `Load*FromMemory()` option to all its supported file formats but **music streaming** was not supported yet... until now. Thanks to this great contribution by [Agnis "NeZvērs" Aldiņš](@nezvers), now raylib supports music streaming from memory data for all supported file formats: WAV, OGG, MP3, FLAC, XM and MOD.
- **RENAMED: enums values for consistency**. Most raylib enums names and values names have been renamed for consistency, now all value names start with the type of data they represent. It increases clarity and readability when using those values and also **improves overall library consistency**.
Besides those key changes, many functions have been reviewed with improvements and bug fixes, many of them contributed by the community! Thanks! And again, this release sets a **new milestone for raylib library**. Make sure to check [CHANGELOG](CHANGELOG) for detailed list of changes! Hope you enjoy this new raylib installment!
Happy **gamedev/tools/graphics** programming! :)
notes on raylib 4.0 - 8th Anniversary Edition
---------------------------------------------
It's been about 6 months since last raylib release and it's been **8 years since I started with this project**, what an adventure! It's time for a new release: `raylib 4.0`, **the biggest release ever** and an inflection point for the library. Many hours have been put in this release to make it special, **many library details have been polished**: syntax, naming conventions, code comments, functions descriptions, log outputs... Almost all the issues have been closed (only 3 remain open at the moment of this writing) and some amazing new features have been added. I expect this **`raylib 4.0`** to be a long-term version (LTS), stable and complete enough for any new graphic/game/tool application development.
Let's start with some numbers:
- **+130** closed issues (for a TOTAL of **+1030**!)
- **+550** commits since previous RELEASE
- **+20** functions ADDED to raylib API
- **+60** functions ADDED to rlgl API
- **+40** functions RENAMED/REVIEWED/REDESIGNED
- **+60** new contributors (for a TOTAL of **+275**!)
Highlights for `raylib 4.0`:
- **Naming consistency and coherency**: `raylib` API has been completely reviewed to be consistent on naming conventions for data structures and functions, comments and descriptions have been reviewed, also the syntax of many symbols for consistency; some functions and structs have been renamed (i.e. `struct CharInfo` to `struct GlyphInfo`). Output log messages have been also improved to show more info to the users. Several articles have been written in this process: [raylib_syntax analysis](https://github.com/raysan5/raylib/wiki/raylib-syntax-analysis) and [raylib API usage analysis](https://gist.github.com/raysan5/7c0c9fff1b6c19af24bb4a51b7383f1e). In general, a big polishment of the library to make it more consistent and coherent.
- **Event Automation System**: This new _experimental_ feature has been added for future usage, it allows to **record input events and re-play them automatically**. This feature could be very useful to automatize examples testing but also for tutorials with assisted game playing, in-game cinematics, speedruns, AI playing and more! Note this feature is still experimental.
- **Custom game-loop control**: As requested by some advanced users, **the game-loop control can be exposed** compiling raylib with the config flag: `SUPPORT_CUSTOM_FRAME_CONTROL`. It's intended for advanced users that want to control the events polling and also the timing mechanisms of their games.
- [**`rlgl 4.0`**](https://github.com/raysan5/raylib/blob/master/src/rlgl.h): This module has been completely **decoupled from platform layer** and raylib, now `rlgl` single-file header-only library only depends on the multiple OpenGL backends supported, even the dependency on `raymath` has been removed. Additionally, **support for OpenGL 4.3** has been added, supporting compute shaders and Shader Storage Buffer Objects (SSBO). Now `rlgl` can be used as a complete standalone portable library to wrap several OpenGL version and providing **a simple and easy-to-use pseudo-OpenGL immediate-mode API**.
- [**`raymath 1.5`**](https://github.com/raysan5/raylib/blob/master/src/raymath.h): This module has been reviewed and some new conventions have been adopted to make it **more portable and self-contained**:
- Functions are self-contained, no function use other raymath function inside, required code is directly re-implemented
- Functions input parameters are always received by value
- Functions use always a "result" variable for return
- Angles are always in radians (`DEG2RAD`/`RAD2DEG` macros provided for convenience)
- [**`raygui 3.0`**](https://github.com/raysan5/raygui): The **official raylib immediate-mode gui library** (included in `raylib/src/extras`) has been updated to a new version, embedding the icons collection and adding mulstiple improvements. It has been simplified and constrained for a better focus on its task: provide a simple and easy-to-use immediate-mode-gui library for small tools development.
- [**`raylib_parser`**](https://github.com/raysan5/raylib/tree/master/parser): Added **new tool to parse `raylib.h`** and tokenize its enums, structs and functions, extracting all required info (name, params, descriptions...) into custom output formats (TXT, XML, JSON...) for further processing. This tool is specially useful to **automatize bindings generation**. Hopefully, this tool will make life easier to binding creators to update their bindings for raylib 4.0 or adding new ones!
- **Zig and Odin official support for raylib**: Those two new amazing programming languages are officially supporting raylib, `Zig` lists raylib as an [official example for C interoperatibility](https://ziglang.org/learn/samples/#c-interoperability) and Odin [officially supports raylib as a vendor library](https://github.com/odin-lang/Odin/tree/master/vendor/raylib). Both languages also have several bingings to raylib. Additionally, Zig build system supported has been added to compile raylib library and examples.
Those are some of the key features for this new release but actually there is way more! **Support for `VOX` ([MagikaVoxel](https://ephtracy.github.io/)) 3d model format** has been added, **new [raylib_game_template](https://github.com/raysan5/raylib-game-template)** repo shared, **new `EncodeDataBase64()` and `DecodeDataBase64()` functions** added, **improved HiDPI support**, new `DrawTextPro()` with support for text rotations, completely **reviewed `glTF` models loading**, added **`SeekMusicStream()` for music seeking**, many new examples and +20 examples reviewed... **hundreds of improvements and bug fixes**! Make sure to check [CHANGELOG](CHANGELOG) for a detailed list of changes!
Undoubtedly, **this is the best raylib ever**. Enjoy gamedev/tools/graphics programming! :)
notes on raylib 4.2
-------------------
**New raylib release!** Nine months after latest raylib, here is a new version. It was supposed to be just a small update but, actually, it's a huge update with lots of changes a improvements. It has been possible thanks to the many contributors that has helped with issues and improvements, it's the **update with more contributors to date** and that's amazing!
Some numbers to start with:
- **+200** closed issues (for a TOTAL of **1230**!)
- **+540** commits since previous RELEASE (for a TOTAL of **+6000**!)
- **+20** functions ADDED to raylib API (for a TOTAL of **502**!)
- **+60** functions REVIEWED/REDESIGNED
- **+70** new contributors (for a TOTAL of **+360**!)
Highlights for `raylib 4.2`:
- **raylib extra libraries cleanup**: raylib has been on diet and all the _extra_ libraries included on previous releases have been removed from raylib. Now raylib only includes the original **7** raylib modules: `rcore`, `rlgl`, `rshapes`, `rtextures`, `rtext`, `rmodels` and `raudio`. But no worries, _extra_ libraries have not been deleted, they have been moved to their own repos for better maintainability and more focus on its functionality. The libraries moved out from raylib repo are: [`raygui`](https://github.com/raysan5/raygui), [`physac`](https://github.com/raysan5/physac), [`rmem`](https://github.com/raylib-extras/rmem), [`reasings`](https://github.com/raylib-extras/reasings) and [`raudio`](https://github.com/raysan5/raudio) (standalone mode). On that same line, a new **amazing GitHub group:** [`raylib-extras`](https://github.com/raylib-extras) has been created by @JeffM2501 to contain raylib extra libraries as well as other raylib add-ons provided by the community. Jeff has done an amazing work on that line, providing multiple libraries and examples for raylib, like [custom first-person and third person camera systems](https://github.com/raylib-extras/extras-c/tree/main/cameras), [Dear ImGui raylib integration](https://github.com/raylib-extras/rlImGui), [multiple specific examples](https://github.com/raylib-extras/examples-c) and even a complete [RPG Game Example](https://github.com/raylib-extras/RPGExample)! Great work Jeff! :D
- **raylib examples review**: The +120 raylib examples have been reviewed to add clearer information about when the were first created (raylib version used) and when they were updated for the last time. But the greatest improvement for users has been the **addition of an estimated difficulty level** for every example, [web has been updated accordingly](https://www.raylib.com/examples.html) to reflect those difficulty levels. Now examples are classified with **1 to 4 stars** depending on difficulty to help users with their learning process. Personally, I think this "small" addition could be a game-changer to better guide new users on the library adoption! Additionally, this new raylib release includes 7 new examples; the most interesting one: [`text_codepoints_loading`](https://www.raylib.com/examples/text/loader.html?name=text_codepoints_loading) that illustrates how to load and draw custom codepoints from a font file, very useful for Asian languages.
- [**`rres 1.0`**](https://github.com/raysan5/rres): New `rres` **resources packaging file-format**, including a [`rres-raylib`](https://github.com/raysan5/rres/blob/master/src/rres-raylib.h) library implementation and [`rrespacker`](https://raylibtech.itch.io/rrespacker) tool. `rres` file format has been [under development for +8 years](https://github.com/raysan5/rres#design-history) and it was originally created to be part of raylib. It was highly inspired by _XNA XNB_ resources file format but design has changed a lot along the years. This first release of the format specs is engine-agnostic and has been designed to be portable to any engine, including lots of professional features like data processing, compression and encryption.
- [**`raygui 3.2`**](https://github.com/raysan5/raygui): The **official raylib immediate-mode gui library** designed for tools development has been updated to a new version aligned with raylib 4.2. Multiple controls have been reviewed for library consistency, now all controls follow a similar function signature. It has been battle-tested with the development of +8 published tools in the last months. The tools can be seen and used for free in the [raylib technologies tools page](https://raylibtech.itch.io/). Worth mentioning that several of those **tools have been open sourced** for anyone to use, compile, contribute or learn how the code works.
- [**`raylib_parser`**](https://github.com/raysan5/raylib/tree/master/parser): Multiple contributors **using the tool to automatize bindings creation** have contributed with improvements of this **tool to parse `raylib.h`** (and other raylib-style headers) to tokenize its enums, structs and functions. Processed data can be exported to custom file formats (i.e XML, JSON, LUA) for bindings generation or even docs generation if required.
- **New file system API**: Current API has been redesigned to be more comprehensive and better aligned with raylib naming conventions, two new functions are provided `LoadDirectoryFiles()`/`LoadDirectoryFilesEx()` to load a `FilePathList` for provided path, supporting extension filtering and recursive directory scan. `LoadDroppedFiles()` has been renamed to better reflect its internal functionality. Now, all raylib functions that start with `Load*()` allocate memory internally and a equivalent `Unload*()` function is defined to take care of that memory internally when not required any more!
- **New audio stream processors API** (_experimental_): Now real-time audio stream data processors can be added using callbacks to played Music. It allows users to create custom effects for audio like delays of low-pass-filtering (example provided). The new API uses a callback system and it's still _ highly experimental_, it differs from the usual level of complexity that provides raylib and it is intended for advanced users. It could change in the future but, actually, `raudio` module is in the spotlight for future updates; [miniaudio](https://github.com/mackron/miniaudio) implements a new higher-level API that can be useful in the future for raylib.
As always, there are more improvements than the key features listed, make sure to check raylib [CHANGELOG](CHANGELOG) for the detailed list of changes; for this release a `WARNING` flag has been added to all the changes that could affect bindings or productivity code. **raylib keeps improving one more version** and a special focus on maintainability has been put on the library for the future. Specific/advance functionality will be provided through **raylib-extras** repos and raylib main repo devlelopment will be focused on what made raylib popular: being a simple and easy-to-use library to **enjoy videogames programming**.
**Enjoy gamedev/tools/graphics programming!** :)
notes on raylib 4.5
-------------------
It's been **7 months** since latest raylib release. As usual, **many parts of the library have been reviewed and improved** along those months. Many issues have been closed, staying under 10 open issues at the moment of this writting and also many PRs from contributors have been received, reviewed and merged into raylib library. Some new functions have been added and some others have been removed to improve library coherence and avoid moving too high level, giving the users the tools to implement advance functionality themselfs over raylib. Again, this is a big release with a considerable amount of changes and improvements. Here is a small summary highlighting this new **rayib 4.5**.
Some numbers for this release:
- **+100** closed issues (for a TOTAL of **+1340**!)
- **+350** commits since previous RELEASE (for a TOTAL of **+6350**!)
- **+25** functions ADDED to raylib API (for a TOTAL of **516**!)
- **+40** functions REVIEWED/REDESIGNED
- **+40** new contributors (for a TOTAL of **405**!)
Highlights for `raylib 4.5`:
- **`NEW` Improved ANGLE support on Desktop platforms**: Support for OpenGL ES 2.0 on Desktop platforms (Windows, Linux, macOS) has been reviewed by @wtnbgo GitHub user. Now raylib can be compiled on desktop for OpenGL ES 2.0 and linked against [`ANGLE`](https://github.com/google/angle). This _small_ addition open the door to building raylib for all **ANGLE supported backends: Direct3D 11, Vulkan and Metal**. Please note that this new feature is still experimental and requires further testing!
- **`NEW` Camera module**: A brand new implementation from scratch for `rcamera` module, contributed by @Crydsch GitHub user! **New camera system is simpler, more flexible, more granular and more extendable**. Specific camera math transformations (movement/rotation) have been moved to individual functions, exposing them to users if required. Global state has been removed from the module and standalone usage has been greatly improved; now `rcamera.h` single-file header-only library can be used externally, independently of raylib. A new `UpdateCameraPro()` function has been added to address input-dependency of `UpdateCamera()`, now advanced users have **full control over camera inputs and movement/rotation speeds**!
- **`NEW` Support for M3D models and M3D/GLTF animations**: 3d models animations support has been a limited aspect of raylib for long time, some versions ago IQM animations were supported but raylib 4.5 also adds support for the brand new [M3D file format](https://bztsrc.gitlab.io/model3d/), including animations and the long expected support for **GLTF animations**! The new M3D file format is **simple, portable, feature complete, extensible and open source**. It also provides a complete set of tools to export/visualize M3D models from/to Blender! Now raylib supports up to **3 model file-formats with animations**: `IQM`, `GLTF` and `M3D`.
- **`NEW` Support QOA audio format (import/export)**: Just a couple of months ago the new [QOA file format](https://qoaformat.org/) was published, a very simple, portable and open source quite-ok-audio file format. raylib already supports it, added to `raudio` module and including audio loading from file, loading from memory, streaming from file, streaming from memory and **exporting to QOA** audio format. **Because simplicity really matters to raylib!**
- **`NEW` Module for compressed textures loading**: [`rl_gputex`](https://github.com/raysan5/raylib/blob/master/src/external/rl_gputex.h), a portable single-file header-only small library to load compressed texture file-formats (DDS, PKM, KTX, PVR, ASTC). Provided functionality is not new to raylib but it was part of the raylib `rtextures` module, now it has been moved into a separate self-contained library, **improving portability**. Note that this module is only intended to **load compressed data from files, ready to be uploaded to GPU**, no compression/decompression functionality is provided. This change is a first step towards a better modularization of raylib library.
- **Reviewed `rlgl` module for automatic limits checking**: Again, [`rlgl`](https://github.com/raysan5/raylib/blob/master/src/rlgl.h) has been reviewed to simplify usage. Now users do not need to worry about reaching the internal render-batch limits when they send their triangles to draw 2d/3d, `rlgl` manages it automatically! This change allows a **great simplification for other modules** like `rshapes`, `rtextures` and `rmodels` that do not need to worry about bufffer overflows and can just define as many vertex as desired!
- **Reviewed `rshapes` module to minimize the rlgl dependency**: Now `rshapes` 2d shapes drawing functions **only depend on 6 low-level functions**: `rlBegin()`, `rlEnd()`, `rlVertex3f()`, `rlTexCoord2f()`, `rlNormal3f()`, `rlSetTexture()`. With only those pseudo-OpenGl 1.1 minimal functionality, everything can be drawn! This improvement converts `rshapes` module in a **self-contained, portable shapes-drawing library that can be used independently of raylib**, as far as entry points for those 6 functions are provided by the user. It even allows to be used for software rendering, with the proper backend!
- **Added data structures validation functions**: Multiple functions have been added by @RobLoach GitHub user to ease the validation of raylib data structures: `IsImageReady()`, `IsTextureReady()`, `IsSoundReady()`... Now users have a simple mechanism to **make sure data has been correctly loaded**, instead of checking internal structure values by themselves.
As usual, those are only some highlights but there is much more! New image generators, new color transformation functionality, improved blending support for color/alpha, etc... Make sure to check raylib [CHANGELOG]([CHANGELOG](https://github.com/raysan5/raylib/blob/master/CHANGELOG)) for a detailed list of changes! Please, note that all breaking changes have been flagged with a `WARNING` in the CHANGELOG, specially useful for binding creators!
**raylib keeps improving one more version** with a special focus on maintainability and sustainability. Always working towards making the library more **simple and easy-to-use**.
Let's keep **enjoying games/tools/graphics programming!** :)
notes on raylib 5.0
-------------------
It's been **7 months** since latest raylib release and **10 years** since raylib 1.0 was officially released... what an adventure! In the last 10 years raylib has improved a lot, new functions have been added, many new features and improvements implemented, up to **500 contributors** have helped to shape the library as it is today. `raylib 5.0` is the final result of all this incredible amount of work and dedication. Here is the summary with the key features and additions of this NEW major version of raylib.
Some numbers for this release:
- **+200** closed issues (for a TOTAL of **+1540**!)
- **+550** commits since previous RELEASE (for a TOTAL of **+6950**!)
- **+35** functions ADDED to raylib API (for a TOTAL of **552**!)
- **+60** functions REVIEWED/REDESIGNED
- **+80** new contributors (for a TOTAL of **+500**!)
Highlights for `raylib 5.0`:
- **`rcore` module platform-split**: Probably the biggest raylib redesign in the last 10 years. raylib started as a library targeting 3 desktop platforms: `Windows`, `Linux` and `macOS` (thanks to `GLFW` underlying library) but with the years support for several new platforms has been added (`Android`, `Web`, `Rapsberry Pi`, `RPI native`...); lot of the platform code was shared so the logic was all together on `rcore.c` module, separated by compilation flags. This approach was very handy but also made it very difficult to support new platforms and specially painful for contributors not familiar with the module, navigating +8000 lines of code in a single file. A big redesign was really needed but the amount of work required was humungous and quite scary for a solo-developer like me, moreover considering that everything was working and the chances to break things were really high. Fortunately, some contributors were ready for the task (@ubkp, @michaelfiber, @Bigfoot71) and thanks to their initiative and super-hard work, the `rcore` [platform split](https://github.com/raysan5/raylib/blob/master/src/platforms) has been possible! This new raylib architecture greatly improves the platforms maintenance but also greatly simplifies the addition of new platforms. A [`platforms/rcore_template.c`](https://github.com/raysan5/raylib/blob/master/src/platforms/rcore_template.c) file is provided with the required structure and functions to be filled for the addition of new platforms, actually it has been simplified to mostly filling some pre-defined functions: `InitPlatform()`, `ClosePlatform`, `PollInputEvents`... Undoubtedly, **this redesign opens the doors to a new era for raylib**, letting the users to plug new platforms as desired.
- **`NEW` Platform backend supported: SDL**: Thanks to the new `rcore` platform-split, the addition of new platforms/backends to raylib has been greatly simplified. As a proof of concept, [`SDL2`](https://libsdl.org/) platform backend has been added to raylib as an alternative for `GLFW` library for desktop builds: [`platforms/rcore_desktop_sdl`](https://github.com/raysan5/raylib/blob/master/src/platforms/rcore_desktop_sdl.c). Lot of work has been put to provide exactly the same features as the other platforms and carefully test the new implementation. Now `SDL2` fans can use this new backend, just providing the required include libraries on compilation and linkage (not included in raylib, like `GLFW`). `SDL` backend support also **eases the process of supporting a wider range of platforms** that already support `SDL`.
- **`NEW` Platform backend supported: Nintendo Switch (closed source)**: The addition of the `SDL` backend was quite a challenge but to really verify the robustness and ease of the new platform plugin system, adding support for a console was a more demanding adventure. Surprisingly, only two days of work were required to add support for `Nintendo Switch` to raylib! Implementation result showed an outstanding level of simplicity, with a **self-contained module** (`rcore_swith.cpp`) supporting graphics and inputs. Unfortunately this module can not be open-sourced due to licensing restrictions.
- **`NEW` Splines drawing and evaluation API**: A complete set of functions has been added to [draw](https://github.com/raysan5/raylib/blob/master/src/raylib.h#L1258) and [evaluate](https://github.com/raysan5/raylib/blob/master/src/raylib.h#L1270) different types of splines: `Linear`, `Basis`, `Catmull-Rom`, `Quadratic Bezier` and `Cubic Bezier`. Splines are extremely useful for game development (describe paths, control NPC movement...) but they can also be very useful on tools development (node-conections, elements-movement, 3d modelling, animations...). This was the missing feature on the raylib [`rshapes`](https://github.com/raysan5/raylib/blob/master/src/rshapes.h) module to make it complete! Note that `rshapes` module can also be used independently of raylib just providing the **only 6 functions required for vertex definition and drawing**.
- **`NEW` Pseudo-random numbers generator: rprand**: After several years of users asking for this missing piece, a brand new pseudo-random generator module has been added to raylib. [`rprand`](https://github.com/raysan5/raylib/blob/master/src/external/rprand.h) implements the `Xoshiro128**` algorithm combined with `SplitMix64`, specially suited for **fast software pseudo-random numbers generation**. The module also implies some useful functions to generate non-repetitive random numbers sequences, functionality exposed by raylib. usage of this module can be controlled by a compilation flag, in case the default libc `rand()` function was preferred.
- **`NEW` Automation Events System API**: This new system was first added in `raylib 4.0` as an experimental feature but it was a bit clumsy and there was no API exposed to users. For the new `raylib 5.0` the system has been redesigned and [proper API](https://github.com/raysan5/raylib/blob/master/src/raylib.h#L1135) added for the users. With this new events automation system, users can **record input events for later replay**, very useful feature for testing automation, tutorials generation, assisted game playing, in-game cinematics, speedruns saving or even AI assited game playing!
- **`NEW` [`raygui 4.0`](https://github.com/raysan5/raygui)**: The **official raylib immediate-mode gui library** designed for tools development has been updated to a new version, aligned with raylib 5.0. This new version is a complete redesign of raygui to unify all controls structure and usage, now all controls have the same function signature!. `raygui` has been battle-tested with the development of +12 published tools in the last few years. The tools can be seen and used for free in the [raylib technologies tools page](https://raylibtech.itch.io/). Worth mentioning that several of those **tools have been open sourced** for anyone to use, compile, contribute or learn how the code works.
- **`NEW` raylib web examples functionality**: Beside the addition of several new examples, the web examples functionality has been improved. Examples have been organized by [complexity level](https://www.raylib.com/examples.html), marked with one star for simple examples and up to 4 stars for more complex ones. A new option has been added to web to allow to **filter examples by function-name** usage, to ease the learning process when looking for an usage example of some function. Finally, **open-graph metadata** information has been added to all examples individual webpages, improving a the visuals and information when sharing those webpages on social networks, sharing the example screenshot and details.
As always, those are only some highlights of the new `raylib 5.0` but there is many more improvements! Support for 16-bit HDR images/textures, SVG loading and scaling support, new OpenGL ES 3.0 graphic backend, new image gradient generators, sound alias loading, improved 3d models loading, multiple optimizations, new bindings, CodeQL integration and much more!
Make sure to check raylib [CHANGELOG]([CHANGELOG](https://github.com/raysan5/raylib/blob/master/CHANGELOG)) for a detailed list of changes!
Undoubtedly, this is the **biggest raylib update in 10 years**. Many new features and improvements with a special focus on maintainability and long-term sustainability. **Undoubtedly, this is the raylib of the future**.
**Enjoy programming!** :)
notes on raylib 5.5
-------------------
One year after raylib 5.0 release, arrives `raylib 5.5`, the next big revision of the library. It's been **11 years** since raylib 1.0 release and in all this time it has never stopped growing and improving. With an outstanding number of new contributors and improvements, it's, again, the biggest raylib release to date.
Some numbers for this release:
- **+270** closed issues (for a TOTAL of **+1810**!)
- **+800** commits since previous RELEASE (for a TOTAL of **+7770**!)
- **+30** functions ADDED to raylib API (for a TOTAL of **580**!)
- **+110** functions REVIEWED with fixes and improvements
- **+140** new contributors (for a TOTAL of **+640**!)
Highlights for `raylib 5.5`:
- **`NEW` raylib pre-configured Windows package**: The new raylib **portable and self-contained Windows package** for `raylib 5.5`, intended for nobel devs that start in programming world, comes with one big addition: support for **C code building for Web platform with one-single-mouse-click!** For the last 10 years, the pre-configured raylib Windows package allowed to edit simple C projects on Notepad++ and easely compile Windows executables with an automatic script; this new release adds the possibility to compile the same C projects for Web platform with a simple mouse click. This new addition **greatly simplifies C to WebAssembly project building for new users**. The `raylib Windows Installer` package can be downloaded for free from [raylib on itch.io](https://raysan5.itch.io/raylib).
- **`NEW` raylib project creator tool**: A brand new tool developed to help raylib users to **setup new projects in a professional way**. `raylib project creator` generates a complete project structure with **multiple build systems ready-to-use** and **GitHub CI/CD actions pre-configured**. It only requires providing some C files and basic project parameters! The tools is [free and open-source](https://raysan5.itch.io/raylib-project-creator), and [it can be used online](https://raysan5.itch.io/raylib-project-creator)!.
- **`NEW` Platform backend supported: RGFW**: Thanks to the `rcore` platform-split implemented in `raylib 5.0`, **adding new platforms backends has been greatly simplified**, new backends can be added using provided template, self-contained in a single C module, completely portable. A new platform backend has been added: [`RGFW`](https://github.com/raysan5/raylib/blob/master/src/platforms/rcore_desktop_rgfw.c). `RGFW` is a **new single-file header-only portable library** ([`RGFW.h`](https://github.com/ColleagueRiley/RGFW)) intended for platform-functionality management (windowing and inputs); in this case for **desktop platforms** (Windows, Linux, macOS) but also for **Web platform**. It adds a new alternative to the already existing `GLFW` and `SDL` platform backends.
- **`NEW` Platform backend version supported: SDL3**: Previous `raylib 5.0` added support for `SDL2` library, and `raylib 5.5` not only improves SDL2 functionality, with several issues reviewed, but also adds support for the recently released big SDL update in years: [`SDL3`](https://wiki.libsdl.org/SDL3/FrontPage). Now users can **select at compile time the desired SDL version to use**, increasing the number of potential platforms supported in the future!
- **`NEW` Retro-console platforms supported: Dreamcast, N64, PSP, PSVita, PS4**: Thanks to the platform-split on `raylib 5.0`, **supporting new platform backends is easier than ever!** Along the raylib `rlgl` module support for the `OpenGL 1.1` graphics API, it opened the door to [**multiple homebrew retro-consoles backend implementations!**](https://github.com/raylib4Consoles) It's amazing to see raylib running on +20 year old consoles like [Dreamcast](https://github.com/raylib4Consoles/raylib4Dreamcast), [PSP](https://github.com/raylib4Consoles/raylib4Psp) or [PSVita](https://github.com/psp2dev/raylib4Vita), considering the hardware constraints of those platforms and proves **raylib outstanding versability!** Those additional platforms can be found in separate repositories and have been created by the amazing programmer Antonio Jose Ramos Marquez (@psxdev).
- **`NEW` GPU Skinning support**: After lots of requests for this feature, it has been finally added to raylib thanks to the contributor Daniel Holden (@orangeduck), probably the developer that has further pushed models animations with raylib, developing two amazing tools to visualize and test animations: [GenoView](https://github.com/orangeduck/GenoView) and [BVHView](https://github.com/orangeduck/BVHView). Adding GPU skinning was a tricky feature, considering it had to be **available for all raylib supported platforms**, including limited ones like Raspberry Pi with OpenGL ES 2.0, where some advance OpenGL features are not available (UBO, SSBO, Transform Feedback) but a multi-platform solution was found to make it possible. A new example, [`models_gpu_skinning`](https://github.com/raysan5/raylib/blob/master/examples/models/models_gpu_skinning.c) has been added to illustrate this new functionality. As an extra, previous existing CPU animation system has been greatly improved, multiplying performance by a factor (simplifiying required maths).
- **`NEW` [`raymath`](https://github.com/raysan5/raylib/blob/master/src/raymath.h) C++ operators**: After several requested for this feature, C++ math operators for `Vector2`, `Vector3`, `Vector4`, `Quaternion` and `Matrix` has been added to `raymath` as an extension to current implementation. Despite being only available for C++ because C does not support it, these operators **simplify C++ code when doing math operations**.
Beside those new big features, `raylib 5.5` comes with MANY other improvements:
- Normals support on batching system
- Clipboard images reading support
- CRC32/MD5/SHA1 hash computation
- Gamepad vibration support
- Improved font loading (no GPU required) with BDF fonts support
- Time-based camera movement
- Improved GLTF animations loading
...and [much much more](https://github.com/raysan5/raylib/blob/master/CHANGELOG), including **many functions reviews and new functions added!**
Make sure to check raylib [CHANGELOG](https://github.com/raysan5/raylib/blob/master/CHANGELOG) for a detailed list of changes!
To end with, I want to **thank all the contributors (+640!**) that along the years have **greatly improved raylib** and pushed it further and better day after day. Thanks to all of them, raylib is the amazing library it is today.
Last but not least, I want to thank **raylib sponsors and all the raylib community** for their support and continuous engagement with the library, creating and sharing amazing raylib projects on a daily basis. **Thanks for making raylib a great platform to enjoy games/tools/graphic programming!**
**After 11 years of development, `raylib 5.5` is the best raylib ever.**
**Enjoy programming with raylib!** :)

16
miniRT/raylib/LICENSE Normal file
View File

@ -0,0 +1,16 @@
Copyright (c) 2013-2025 Ramon Santamaria (@raysan5)
This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you
wrote the original software. If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.

151
miniRT/raylib/README.md Normal file
View File

@ -0,0 +1,151 @@
<img align="left" style="width:260px" src="https://github.com/raysan5/raylib/blob/master/logo/raylib_logo_animation.gif" width="288px">
**raylib is a simple and easy-to-use library to enjoy videogames programming.**
raylib is highly inspired by Borland BGI graphics lib and by XNA framework and it's especially well suited for prototyping, tooling, graphical applications, embedded systems and education.
*NOTE for ADVENTURERS: raylib is a programming library to enjoy videogames programming; no fancy interface, no visual helpers, no debug button... just coding in the most pure spartan-programmers way.*
Ready to learn? Jump to [code examples!](https://www.raylib.com/examples.html)
---
<br>
[![GitHub Releases Downloads](https://img.shields.io/github/downloads/raysan5/raylib/total)](https://github.com/raysan5/raylib/releases)
[![GitHub Stars](https://img.shields.io/github/stars/raysan5/raylib?style=flat&label=stars)](https://github.com/raysan5/raylib/stargazers)
[![GitHub commits since tagged version](https://img.shields.io/github/commits-since/raysan5/raylib/5.5)](https://github.com/raysan5/raylib/commits/master)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/raysan5?label=sponsors)](https://github.com/sponsors/raysan5)
[![Packaging Status](https://repology.org/badge/tiny-repos/raylib.svg)](https://repology.org/project/raylib/versions)
[![License](https://img.shields.io/badge/license-zlib%2Flibpng-blue.svg)](LICENSE)
[![Discord Members](https://img.shields.io/discord/426912293134270465.svg?label=Discord&logo=discord)](https://discord.gg/raylib)
[![Reddit Static Badge](https://img.shields.io/badge/-r%2Fraylib-red?style=flat&logo=reddit&label=reddit)](https://www.reddit.com/r/raylib/)
[![Youtube Subscribers](https://img.shields.io/youtube/channel/subscribers/UC8WIBkhYb5sBNqXO1mZ7WSQ?style=flat&label=Youtube&logo=youtube)](https://www.youtube.com/c/raylib)
[![Twitch Status](https://img.shields.io/twitch/status/raysan5?style=flat&label=Twitch&logo=twitch)](https://www.twitch.tv/raysan5)
[![Windows](https://github.com/raysan5/raylib/workflows/Windows/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3AWindows)
[![Linux](https://github.com/raysan5/raylib/workflows/Linux/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3ALinux)
[![macOS](https://github.com/raysan5/raylib/workflows/macOS/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3AmacOS)
[![WebAssembly](https://github.com/raysan5/raylib/workflows/WebAssembly/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3AWebAssembly)
[![CMakeBuilds](https://github.com/raysan5/raylib/workflows/CMakeBuilds/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3ACMakeBuilds)
[![Windows Examples](https://github.com/raysan5/raylib/actions/workflows/windows_examples.yml/badge.svg)](https://github.com/raysan5/raylib/actions/workflows/windows_examples.yml)
[![Linux Examples](https://github.com/raysan5/raylib/actions/workflows/linux_examples.yml/badge.svg)](https://github.com/raysan5/raylib/actions/workflows/linux_examples.yml)
features
--------
- **NO external dependencies**, all required libraries are [included into raylib](https://github.com/raysan5/raylib/tree/master/src/external)
- Multiple platforms supported: **Windows, Linux, MacOS, RPI, Android, HTML5... and more!**
- Written in plain C code (C99) using PascalCase/camelCase notation
- Hardware accelerated with OpenGL: **1.1, 2.1, 3.3, 4.3, ES 2.0, ES 3.0**
- **Unique OpenGL abstraction layer** (usable as standalone module): [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.h)
- Multiple **Fonts** formats supported (TTF, OTF, FNT, BDF, sprite fonts)
- Multiple texture formats supported, including **compressed formats** (DXT, ETC, ASTC)
- **Full 3D support**, including 3D Shapes, Models, Billboards, Heightmaps and more!
- Flexible Materials system, supporting classic maps and **PBR maps**
- **Animated 3D models** supported (skeletal bones animation) (IQM, M3D, glTF)
- Shaders support, including model shaders and **postprocessing** shaders
- **Powerful math module** for Vector, Matrix and Quaternion operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h)
- Audio loading and playing with streaming support (WAV, QOA, OGG, MP3, FLAC, XM, MOD)
- **VR stereo rendering** support with configurable HMD device parameters
- Huge examples collection with [+140 code examples](https://github.com/raysan5/raylib/tree/master/examples)!
- Bindings to [+70 programming languages](https://github.com/raysan5/raylib/blob/master/BINDINGS.md)!
- **Free and open source**
basic example
--------------
This is a basic raylib example, it creates a window and draws the text `"Congrats! You created your first window!"` in the middle of the screen. Check this example [running live on web here](https://www.raylib.com/examples/core/loader.html?name=core_basic_window).
```c
#include "raylib.h"
int main(void)
{
InitWindow(800, 450, "raylib [core] example - basic window");
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}
```
build and installation
----------------------
raylib binary releases for Windows, Linux, macOS, Android and HTML5 are available at the [Github Releases page](https://github.com/raysan5/raylib/releases).
raylib is also available via multiple package managers on multiple OS distributions.
#### Installing and building raylib on multiple platforms
[raylib Wiki](https://github.com/raysan5/raylib/wiki#development-platforms) contains detailed instructions on building and usage on multiple platforms.
- [Working on Windows](https://github.com/raysan5/raylib/wiki/Working-on-Windows)
- [Working on macOS](https://github.com/raysan5/raylib/wiki/Working-on-macOS)
- [Working on GNU Linux](https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux)
- [Working on Chrome OS](https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS)
- [Working on FreeBSD](https://github.com/raysan5/raylib/wiki/Working-on-FreeBSD)
- [Working on Raspberry Pi](https://github.com/raysan5/raylib/wiki/Working-on-Raspberry-Pi)
- [Working for Android](https://github.com/raysan5/raylib/wiki/Working-for-Android)
- [Working for Web (HTML5)](https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5))
- [Working anywhere with CMake](https://github.com/raysan5/raylib/wiki/Working-with-CMake)
*Note that the Wiki is open for edit, if you find some issues while building raylib for your target platform, feel free to edit the Wiki or open an issue related to it.*
#### Setup raylib with multiple IDEs
raylib has been developed on Windows platform using [Notepad++](https://notepad-plus-plus.org/) and [MinGW GCC](https://www.mingw-w64.org/) compiler but it can be used with other IDEs on multiple platforms.
[Projects directory](https://github.com/raysan5/raylib/tree/master/projects) contains several ready-to-use **project templates** to build raylib and code examples with multiple IDEs.
*Note that there are lots of IDEs supported, some of the provided templates could require some review, so please, if you find some issue with a template or you think they could be improved, feel free to send a PR or open a related issue.*
learning and docs
------------------
raylib is designed to be learned using [the examples](https://github.com/raysan5/raylib/tree/master/examples) as the main reference. There is no standard API documentation but there is a [**cheatsheet**](https://www.raylib.com/cheatsheet/cheatsheet.html) containing all the functions available on the library a short description of each one of them, input parameters and result value names should be intuitive enough to understand how each function works.
Some additional documentation about raylib design can be found in [raylib GitHub Wiki](https://github.com/raysan5/raylib/wiki). Here are the relevant links:
- [raylib cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html)
- [raylib architecture](https://github.com/raysan5/raylib/wiki/raylib-architecture)
- [raylib library design](https://github.com/raysan5/raylib/wiki)
- [raylib examples collection](https://github.com/raysan5/raylib/tree/master/examples)
- [raylib games collection](https://github.com/raysan5/raylib-games)
contact and networks
---------------------
raylib is present in several networks and raylib community is growing everyday. If you are using raylib and enjoying it, feel free to join us in any of these networks. The most active network is our [Discord server](https://discord.gg/raylib)! :)
- Webpage: [https://www.raylib.com](https://www.raylib.com)
- Discord: [https://discord.gg/raylib](https://discord.gg/raylib)
- Twitter: [https://www.twitter.com/raysan5](https://www.twitter.com/raysan5)
- BlueSky: [https://bsky.app/profile/raysan5](https://bsky.app/profile/raysan5.bsky.social)
- Twitch: [https://www.twitch.tv/raysan5](https://www.twitch.tv/raysan5)
- Reddit: [https://www.reddit.com/r/raylib](https://www.reddit.com/r/raylib)
- Patreon: [https://www.patreon.com/raylib](https://www.patreon.com/raylib)
- YouTube: [https://www.youtube.com/channel/raylib](https://www.youtube.com/c/raylib)
contributors
------------
<a href="https://github.com/raysan5/raylib/graphs/contributors">
<img src="https://contrib.rocks/image?repo=raysan5/raylib&max=500&columns=20&anon=1" />
</a>
license
-------
raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.
raylib uses internally some libraries for window/graphics/inputs management and also to support different file formats loading, all those libraries are embedded with and are available in [src/external](https://github.com/raysan5/raylib/tree/master/src/external) directory. Check [raylib dependencies LICENSES](https://github.com/raysan5/raylib/wiki/raylib-dependencies) on [raylib Wiki](https://github.com/raysan5/raylib/wiki) for details.

93
miniRT/raylib/ROADMAP.md Normal file
View File

@ -0,0 +1,93 @@
# raylib roadmap
Here is a wishlist with features and ideas to improve the library. Note that features listed here are usually long term improvements or just describe a route to follow for the library. There are also some additional places to look for raylib improvements and ideas:
- [GitHub Issues](https://github.com/raysan5/raylib/issues) has several open issues for possible improvements or bugs to fix.
- [GitHub PRs](https://github.com/raysan5/raylib/pulls) open with improvements to be reviewed.
- [raylib source code](https://github.com/raysan5/raylib/tree/master/src) has multiple *TODO* comments around code with pending things to review or improve.
- raylib wishlists discussions are open to everyone to ask for improvements, feel free to check and comment:
- [raylib 6.0 wishlist](https://github.com/raysan5/raylib/discussions/4660)
- [raylib 5.0 wishlist](https://github.com/raysan5/raylib/discussions/2952)
- [raylib wishlist 2022](https://github.com/raysan5/raylib/discussions/2272)
- [raylib wishlist 2021](https://github.com/raysan5/raylib/discussions/1502)
_Current version of raylib is complete and functional but there is always room for improvements._
**raylib 5.x**
- [ ] `rcore`: Support additional platforms: iOS, consoles?
- [ ] `rcore_web`: Avoid GLFW dependency, functionality can be directly implemented using emscripten SDK
- [ ] `rlgl`: Review GLSL shaders naming conventions for consistency
- [ ] `textures`: Improve compressed textures support, loading and saving
- [ ] `rmodels`: Improve 3d objects loading, specially animations (obj, gltf)
- [ ] `raudio`: Implement miniaudio high-level provided features
- [ ] `examples`: Review all examples, add more and better code explanations
- [ ] Software renderer backend? Maybe using `Image` provided API
**raylib 4.x**
- [x] Split core module into separate platforms?
- [x] Redesign gestures system, improve touch inputs management
- [x] Redesign camera module (more flexible) ([#1143](https://github.com/raysan5/raylib/issues/1143), https://github.com/raysan5/raylib/discussions/2507)
- [x] Better documentation and improved examples, reviewed webpage with examples complexity level
- [x] Focus on HTML5 ([raylib 5k gamejam](https://itch.io/jam/raylib-5k-gamejam)) and embedded platforms (RPI and similar SOCs)
- [x] Additional support libraries: [raygui](https://github.com/raysan5/raygui), [rres](https://github.com/raysan5/rres)
**raylib 4.0**
- [x] Improved consistency and coherency in raylib API
- [x] Continuous Deployment using GitHub Actions
- [x] rlgl improvements for standalone usage (avoid raylib coupling)
- Basic CPU/GPU stats system (memory, draws, time...) ([#1295](https://github.com/raysan5/raylib/issues/1295)) - _DISCARDED_
- Software rendering backend (avoiding OpenGL) ([#1370](https://github.com/raysan5/raylib/issues/1370)) - _DISCARDED_
- Network module (UDP): `rnet` ([#753](https://github.com/raysan5/raylib/issues/753)) - _DISCARDED_ - Use [nbnet](https://github.com/nathhB/nbnet).
**raylib 3.0**
- [x] Custom memory allocators support
- [x] Global variables moved to global context
- [x] Optimize data structures for pass-by-value
- [x] Trace log messages redesign ([#1065](https://github.com/raysan5/raylib/issues/1065))
- [x] Continuous Integration using GitHub Actions
**raylib 2.5**
- [x] Support Animated models
- [x] Support glTF models file format
- [x] Unicode support on text drawing
**raylib 2.0**
- [x] Removed external dependencies (GLFW3 and OpenAL)
- [x] Support TCC compiler (32bit and 64bit)
**raylib 1.8**
- [x] Improved Materials system with PBR support
- [x] Procedural image generation functions (spot, gradient, noise...)
- [x] Procedural mesh generation functions (cube, sphere...)
- [x] Custom Android APK build pipeline (default Makefile)
**raylib 1.7**
- [x] Support configuration flags
- [x] Improved build system for Android
- [x] Gamepad support on HTML5
**raylib 1.6**
- [x] Lua scripting support (raylib Lua wrapper)
- [x] Redesigned audio module
- [x] Support FLAC file format
**raylib 1.5**
- [x] Support Oculus Rift CV1 and VR stereo rendering (simulator)
- [x] Redesign Shaders/Textures system -> New Materials system
- [x] Support lighting: Omni, Directional and Spotlights
- [x] Redesign physics module (physac)
- [x] Chiptunes audio modules support
**raylib 1.4**
- [x] TTF fonts support (using stb_truetype)
- [x] Raycast system for 3D picking (including collisions detection)
- [x] Floyd-Steinberg dithering on 16bit image format conversion
- [x] Basic image manipulation functions (crop, resize, draw...)
- [x] Storage load/save data functionality
- [x] Add Physics module (physac)
- [x] Remove GLEW dependency -> Replaced by GLAD
- [x] Redesign Raspberry PI inputs system
- [x] Redesign gestures module to be multiplatform
- [x] Module raymath as header-only and functions inline
- [x] Add Easings module (easings.h)

612
miniRT/raylib/build.zig Normal file
View File

@ -0,0 +1,612 @@
const std = @import("std");
const builtin = @import("builtin");
/// Minimum supported version of Zig
const min_ver = "0.13.0";
comptime {
const order = std.SemanticVersion.order;
const parse = std.SemanticVersion.parse;
if (order(builtin.zig_version, parse(min_ver) catch unreachable) == .lt)
@compileError("Raylib requires zig version " ++ min_ver);
}
fn setDesktopPlatform(raylib: *std.Build.Step.Compile, platform: PlatformBackend) void {
switch (platform) {
.glfw => raylib.root_module.addCMacro("PLATFORM_DESKTOP_GLFW", ""),
.rgfw => raylib.root_module.addCMacro("PLATFORM_DESKTOP_RGFW", ""),
.sdl => raylib.root_module.addCMacro("PLATFORM_DESKTOP_SDL", ""),
.android => raylib.root_module.addCMacro("PLATFORM_ANDROID", ""),
else => {},
}
}
fn createEmsdkStep(b: *std.Build, emsdk: *std.Build.Dependency) *std.Build.Step.Run {
if (builtin.os.tag == .windows) {
return b.addSystemCommand(&.{emsdk.path("emsdk.bat").getPath(b)});
} else {
return b.addSystemCommand(&.{emsdk.path("emsdk").getPath(b)});
}
}
fn emSdkSetupStep(b: *std.Build, emsdk: *std.Build.Dependency) !?*std.Build.Step.Run {
const dot_emsc_path = emsdk.path(".emscripten").getPath(b);
const dot_emsc_exists = !std.meta.isError(std.fs.accessAbsolute(dot_emsc_path, .{}));
if (!dot_emsc_exists) {
const emsdk_install = createEmsdkStep(b, emsdk);
emsdk_install.addArgs(&.{ "install", "latest" });
const emsdk_activate = createEmsdkStep(b, emsdk);
emsdk_activate.addArgs(&.{ "activate", "latest" });
emsdk_activate.step.dependOn(&emsdk_install.step);
return emsdk_activate;
} else {
return null;
}
}
/// A list of all flags from `src/config.h` that one may override
const config_h_flags = outer: {
// Set this value higher if compile errors happen as `src/config.h` gets larger
@setEvalBranchQuota(1 << 20);
const config_h = @embedFile("src/config.h");
var flags: [std.mem.count(u8, config_h, "\n") + 1][]const u8 = undefined;
var i = 0;
var lines = std.mem.tokenizeScalar(u8, config_h, '\n');
while (lines.next()) |line| {
if (!std.mem.containsAtLeast(u8, line, 1, "SUPPORT")) continue;
if (std.mem.containsAtLeast(u8, line, 1, "MODULE")) continue;
if (std.mem.startsWith(u8, line, "//")) continue;
if (std.mem.startsWith(u8, line, "#if")) continue;
var flag = std.mem.trimLeft(u8, line, " \t"); // Trim whitespace
flag = flag["#define ".len - 1 ..]; // Remove #define
flag = std.mem.trimLeft(u8, flag, " \t"); // Trim whitespace
flag = flag[0 .. std.mem.indexOf(u8, flag, " ") orelse continue]; // Flag is only one word, so capture till space
flag = "-D" ++ flag; // Prepend with -D
flags[i] = flag;
i += 1;
}
// Uncomment this to check what flags normally get passed
//@compileLog(flags[0..i].*);
break :outer flags[0..i].*;
};
fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
var raylib_flags_arr = std.ArrayList([]const u8).init(b.allocator);
defer raylib_flags_arr.deinit();
try raylib_flags_arr.appendSlice(&[_][]const u8{
"-std=gnu99",
"-D_GNU_SOURCE",
"-DGL_SILENCE_DEPRECATION=199309L",
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
});
if (options.shared) {
try raylib_flags_arr.appendSlice(&[_][]const u8{
"-fPIC",
"-DBUILD_LIBTYPE_SHARED",
});
}
// Sets a flag indiciating the use of a custom `config.h`
try raylib_flags_arr.append("-DEXTERNAL_CONFIG_FLAGS");
if (options.config.len > 0) {
// Splits a space-separated list of config flags into multiple flags
//
// Note: This means certain flags like `-x c++` won't be processed properly.
// `-xc++` or similar should be used when possible
var config_iter = std.mem.tokenizeScalar(u8, options.config, ' ');
// Apply config flags supplied by the user
while (config_iter.next()) |config_flag|
try raylib_flags_arr.append(config_flag);
// Apply all relevant configs from `src/config.h` *except* the user-specified ones
//
// Note: Currently using a suboptimal `O(m*n)` time algorithm where:
// `m` corresponds roughly to the number of lines in `src/config.h`
// `n` corresponds to the number of user-specified flags
outer: for (config_h_flags) |flag| {
// If a user already specified the flag, skip it
config_iter.reset();
while (config_iter.next()) |config_flag| {
// For a user-specified flag to match, it must share the same prefix and have the
// same length or be followed by an equals sign
if (!std.mem.startsWith(u8, config_flag, flag)) continue;
if (config_flag.len == flag.len or config_flag[flag.len] == '=') continue :outer;
}
// Otherwise, append default value from config.h to compile flags
try raylib_flags_arr.append(flag);
}
} else {
// Set default config if no custome config got set
try raylib_flags_arr.appendSlice(&config_h_flags);
}
const raylib = if (options.shared)
b.addSharedLibrary(.{
.name = "raylib",
.target = target,
.optimize = optimize,
})
else
b.addStaticLibrary(.{
.name = "raylib",
.target = target,
.optimize = optimize,
});
raylib.linkLibC();
// No GLFW required on PLATFORM_DRM
if (options.platform != .drm) {
raylib.addIncludePath(b.path("src/external/glfw/include"));
}
var c_source_files = try std.ArrayList([]const u8).initCapacity(b.allocator, 2);
c_source_files.appendSliceAssumeCapacity(&.{ "src/rcore.c", "src/utils.c" });
if (options.rshapes) {
try c_source_files.append("src/rshapes.c");
try raylib_flags_arr.append("-DSUPPORT_MODULE_RSHAPES");
}
if (options.rtextures) {
try c_source_files.append("src/rtextures.c");
try raylib_flags_arr.append("-DSUPPORT_MODULE_RTEXTURES");
}
if (options.rtext) {
try c_source_files.append("src/rtext.c");
try raylib_flags_arr.append("-DSUPPORT_MODULE_RTEXT");
}
if (options.rmodels) {
try c_source_files.append("src/rmodels.c");
try raylib_flags_arr.append("-DSUPPORT_MODULE_RMODELS");
}
if (options.raudio) {
try c_source_files.append("src/raudio.c");
try raylib_flags_arr.append("-DSUPPORT_MODULE_RAUDIO");
}
if (options.opengl_version != .auto) {
raylib.root_module.addCMacro(options.opengl_version.toCMacroStr(), "");
}
raylib.addIncludePath(b.path("src/platforms"));
switch (target.result.os.tag) {
.windows => {
switch (options.platform) {
.glfw => try c_source_files.append("src/rglfw.c"),
.rgfw, .sdl, .drm, .android => {},
}
raylib.linkSystemLibrary("winmm");
raylib.linkSystemLibrary("gdi32");
raylib.linkSystemLibrary("opengl32");
setDesktopPlatform(raylib, options.platform);
},
.linux => {
if (options.platform == .drm) {
if (options.opengl_version == .auto) {
raylib.linkSystemLibrary("GLESv2");
raylib.root_module.addCMacro("GRAPHICS_API_OPENGL_ES2", "");
}
raylib.linkSystemLibrary("EGL");
raylib.linkSystemLibrary("gbm");
raylib.linkSystemLibrary2("libdrm", .{ .use_pkg_config = .force });
raylib.root_module.addCMacro("PLATFORM_DRM", "");
raylib.root_module.addCMacro("EGL_NO_X11", "");
raylib.root_module.addCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", "");
} else if (target.result.abi.isAndroid()) {
//these are the only tag options per https://developer.android.com/ndk/guides/other_build_systems
const hostTuple = switch (builtin.target.os.tag) {
.linux => "linux-x86_64",
.windows => "windows-x86_64",
.macos => "darwin-x86_64",
else => @panic("unsupported host OS"),
};
const androidTriple = switch (target.result.cpu.arch) {
.x86 => "i686-linux-android",
.x86_64 => "x86_64-linux-android",
.arm => "arm-linux-androideabi",
.aarch64 => "aarch64-linux-android",
.riscv64 => "riscv64-linux-android",
else => error.InvalidAndroidTarget,
} catch @panic("invalid android target!");
const androidNdkPathString: []const u8 = options.android_ndk;
if (androidNdkPathString.len < 1) @panic("no ndk path provided and ANDROID_NDK_HOME is not set");
const androidApiLevel: []const u8 = options.android_api_version;
const androidSysroot = try std.fs.path.join(b.allocator, &.{ androidNdkPathString, "/toolchains/llvm/prebuilt/", hostTuple, "/sysroot" });
const androidLibPath = try std.fs.path.join(b.allocator, &.{ androidSysroot, "/usr/lib/", androidTriple });
const androidApiSpecificPath = try std.fs.path.join(b.allocator, &.{ androidLibPath, androidApiLevel });
const androidIncludePath = try std.fs.path.join(b.allocator, &.{ androidSysroot, "/usr/include" });
const androidArchIncludePath = try std.fs.path.join(b.allocator, &.{ androidIncludePath, androidTriple });
const androidAsmPath = try std.fs.path.join(b.allocator, &.{ androidIncludePath, "/asm-generic" });
const androidGluePath = try std.fs.path.join(b.allocator, &.{ androidNdkPathString, "/sources/android/native_app_glue/" });
raylib.addLibraryPath(.{ .cwd_relative = androidLibPath });
raylib.root_module.addLibraryPath(.{ .cwd_relative = androidApiSpecificPath });
raylib.addSystemIncludePath(.{ .cwd_relative = androidIncludePath });
raylib.addSystemIncludePath(.{ .cwd_relative = androidArchIncludePath });
raylib.addSystemIncludePath(.{ .cwd_relative = androidAsmPath });
raylib.addSystemIncludePath(.{ .cwd_relative = androidGluePath });
var libcData = std.ArrayList(u8).init(b.allocator);
const writer = libcData.writer();
try (std.zig.LibCInstallation{
.include_dir = androidIncludePath,
.sys_include_dir = androidIncludePath,
.crt_dir = androidApiSpecificPath,
}).render(writer);
const libcFile = b.addWriteFiles().add("android-libc.txt", try libcData.toOwnedSlice());
raylib.setLibCFile(libcFile);
if (options.opengl_version == .auto) {
raylib.root_module.linkSystemLibrary("GLESv2", .{});
raylib.root_module.addCMacro("GRAPHICS_API_OPENGL_ES2", "");
}
raylib.root_module.linkSystemLibrary("EGL", .{});
setDesktopPlatform(raylib, .android);
} else {
try c_source_files.append("src/rglfw.c");
if (options.linux_display_backend == .X11 or options.linux_display_backend == .Both) {
raylib.root_module.addCMacro("_GLFW_X11", "");
raylib.linkSystemLibrary("GLX");
raylib.linkSystemLibrary("X11");
raylib.linkSystemLibrary("Xcursor");
raylib.linkSystemLibrary("Xext");
raylib.linkSystemLibrary("Xfixes");
raylib.linkSystemLibrary("Xi");
raylib.linkSystemLibrary("Xinerama");
raylib.linkSystemLibrary("Xrandr");
raylib.linkSystemLibrary("Xrender");
}
if (options.linux_display_backend == .Wayland or options.linux_display_backend == .Both) {
_ = b.findProgram(&.{"wayland-scanner"}, &.{}) catch {
std.log.err(
\\ `wayland-scanner` may not be installed on the system.
\\ You can switch to X11 in your `build.zig` by changing `Options.linux_display_backend`
, .{});
@panic("`wayland-scanner` not found");
};
raylib.root_module.addCMacro("_GLFW_WAYLAND", "");
raylib.linkSystemLibrary("EGL");
raylib.linkSystemLibrary("wayland-client");
raylib.linkSystemLibrary("xkbcommon");
waylandGenerate(b, raylib, "wayland.xml", "wayland-client-protocol");
waylandGenerate(b, raylib, "xdg-shell.xml", "xdg-shell-client-protocol");
waylandGenerate(b, raylib, "xdg-decoration-unstable-v1.xml", "xdg-decoration-unstable-v1-client-protocol");
waylandGenerate(b, raylib, "viewporter.xml", "viewporter-client-protocol");
waylandGenerate(b, raylib, "relative-pointer-unstable-v1.xml", "relative-pointer-unstable-v1-client-protocol");
waylandGenerate(b, raylib, "pointer-constraints-unstable-v1.xml", "pointer-constraints-unstable-v1-client-protocol");
waylandGenerate(b, raylib, "fractional-scale-v1.xml", "fractional-scale-v1-client-protocol");
waylandGenerate(b, raylib, "xdg-activation-v1.xml", "xdg-activation-v1-client-protocol");
waylandGenerate(b, raylib, "idle-inhibit-unstable-v1.xml", "idle-inhibit-unstable-v1-client-protocol");
}
setDesktopPlatform(raylib, options.platform);
}
},
.freebsd, .openbsd, .netbsd, .dragonfly => {
try c_source_files.append("rglfw.c");
raylib.linkSystemLibrary("GL");
raylib.linkSystemLibrary("rt");
raylib.linkSystemLibrary("dl");
raylib.linkSystemLibrary("m");
raylib.linkSystemLibrary("X11");
raylib.linkSystemLibrary("Xrandr");
raylib.linkSystemLibrary("Xinerama");
raylib.linkSystemLibrary("Xi");
raylib.linkSystemLibrary("Xxf86vm");
raylib.linkSystemLibrary("Xcursor");
setDesktopPlatform(raylib, options.platform);
},
.macos => {
// Include xcode_frameworks for cross compilation
if (b.lazyDependency("xcode_frameworks", .{})) |dep| {
raylib.addSystemFrameworkPath(dep.path("Frameworks"));
raylib.addSystemIncludePath(dep.path("include"));
raylib.addLibraryPath(dep.path("lib"));
}
// On macos rglfw.c include Objective-C files.
try raylib_flags_arr.append("-ObjC");
raylib.root_module.addCSourceFile(.{
.file = b.path("src/rglfw.c"),
.flags = raylib_flags_arr.items,
});
_ = raylib_flags_arr.pop();
raylib.linkFramework("Foundation");
raylib.linkFramework("CoreServices");
raylib.linkFramework("CoreGraphics");
raylib.linkFramework("AppKit");
raylib.linkFramework("IOKit");
setDesktopPlatform(raylib, options.platform);
},
.emscripten => {
// Include emscripten for cross compilation
if (b.lazyDependency("emsdk", .{})) |dep| {
if (try emSdkSetupStep(b, dep)) |emSdkStep| {
raylib.step.dependOn(&emSdkStep.step);
}
raylib.addIncludePath(dep.path("upstream/emscripten/cache/sysroot/include"));
}
raylib.root_module.addCMacro("PLATFORM_WEB", "");
if (options.opengl_version == .auto) {
raylib.root_module.addCMacro("GRAPHICS_API_OPENGL_ES2", "");
}
},
else => {
@panic("Unsupported OS");
},
}
raylib.root_module.addCSourceFiles(.{
.files = c_source_files.items,
.flags = raylib_flags_arr.items,
});
return raylib;
}
pub fn addRaygui(b: *std.Build, raylib: *std.Build.Step.Compile, raygui_dep: *std.Build.Dependency) void {
const raylib_dep = b.dependencyFromBuildZig(@This(), .{});
var gen_step = b.addWriteFiles();
raylib.step.dependOn(&gen_step.step);
const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
raylib.addCSourceFile(.{ .file = raygui_c_path });
raylib.addIncludePath(raygui_dep.path("src"));
raylib.addIncludePath(raylib_dep.path("src"));
raylib.installHeader(raygui_dep.path("src/raygui.h"), "raygui.h");
}
pub const Options = struct {
raudio: bool = true,
rmodels: bool = true,
rshapes: bool = true,
rtext: bool = true,
rtextures: bool = true,
platform: PlatformBackend = .glfw,
shared: bool = false,
linux_display_backend: LinuxDisplayBackend = .Both,
opengl_version: OpenglVersion = .auto,
android_ndk: []const u8 = "",
android_api_version: []const u8 = "35",
/// config should be a list of space-separated cflags, eg, "-DSUPPORT_CUSTOM_FRAME_CONTROL"
config: []const u8 = &.{},
const defaults = Options{};
pub fn getOptions(b: *std.Build) Options {
return .{
.platform = b.option(PlatformBackend, "platform", "Choose the platform backedn for desktop target") orelse defaults.platform,
.raudio = b.option(bool, "raudio", "Compile with audio support") orelse defaults.raudio,
.rmodels = b.option(bool, "rmodels", "Compile with models support") orelse defaults.rmodels,
.rtext = b.option(bool, "rtext", "Compile with text support") orelse defaults.rtext,
.rtextures = b.option(bool, "rtextures", "Compile with textures support") orelse defaults.rtextures,
.rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes,
.shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared,
.linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend,
.opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
.config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h") orelse &.{},
.android_ndk = b.option([]const u8, "android_ndk", "specify path to android ndk") orelse std.process.getEnvVarOwned(b.allocator, "ANDROID_NDK_HOME") catch "",
.android_api_version = b.option([]const u8, "android_api_version", "specify target android API level") orelse defaults.android_api_version,
};
}
};
pub const OpenglVersion = enum {
auto,
gl_1_1,
gl_2_1,
gl_3_3,
gl_4_3,
gles_2,
gles_3,
pub fn toCMacroStr(self: @This()) []const u8 {
switch (self) {
.auto => @panic("OpenglVersion.auto cannot be turned into a C macro string"),
.gl_1_1 => return "GRAPHICS_API_OPENGL_11",
.gl_2_1 => return "GRAPHICS_API_OPENGL_21",
.gl_3_3 => return "GRAPHICS_API_OPENGL_33",
.gl_4_3 => return "GRAPHICS_API_OPENGL_43",
.gles_2 => return "GRAPHICS_API_OPENGL_ES2",
.gles_3 => return "GRAPHICS_API_OPENGL_ES3",
}
}
};
pub const LinuxDisplayBackend = enum {
X11,
Wayland,
Both,
};
pub const PlatformBackend = enum {
glfw,
rgfw,
sdl,
drm,
android,
};
pub fn build(b: *std.Build) !void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const lib = try compileRaylib(b, target, optimize, Options.getOptions(b));
lib.installHeader(b.path("src/raylib.h"), "raylib.h");
lib.installHeader(b.path("src/rcamera.h"), "rcamera.h");
lib.installHeader(b.path("src/raymath.h"), "raymath.h");
lib.installHeader(b.path("src/rlgl.h"), "rlgl.h");
b.installArtifact(lib);
const examples = b.step("examples", "Build/Install all examples");
examples.dependOn(try addExamples("audio", b, target, optimize, lib));
examples.dependOn(try addExamples("core", b, target, optimize, lib));
examples.dependOn(try addExamples("models", b, target, optimize, lib));
examples.dependOn(try addExamples("others", b, target, optimize, lib));
examples.dependOn(try addExamples("shaders", b, target, optimize, lib));
examples.dependOn(try addExamples("shapes", b, target, optimize, lib));
examples.dependOn(try addExamples("text", b, target, optimize, lib));
examples.dependOn(try addExamples("textures", b, target, optimize, lib));
}
fn waylandGenerate(
b: *std.Build,
raylib: *std.Build.Step.Compile,
comptime protocol: []const u8,
comptime basename: []const u8,
) void {
const waylandDir = "src/external/glfw/deps/wayland";
const protocolDir = b.pathJoin(&.{ waylandDir, protocol });
const clientHeader = basename ++ ".h";
const privateCode = basename ++ "-code.h";
const client_step = b.addSystemCommand(&.{ "wayland-scanner", "client-header" });
client_step.addFileArg(b.path(protocolDir));
raylib.addIncludePath(client_step.addOutputFileArg(clientHeader).dirname());
const private_step = b.addSystemCommand(&.{ "wayland-scanner", "private-code" });
private_step.addFileArg(b.path(protocolDir));
raylib.addIncludePath(private_step.addOutputFileArg(privateCode).dirname());
raylib.step.dependOn(&client_step.step);
raylib.step.dependOn(&private_step.step);
}
fn addExamples(
comptime module: []const u8,
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
raylib: *std.Build.Step.Compile,
) !*std.Build.Step {
if (target.result.os.tag == .emscripten) {
return &b.addFail("Emscripten building via Zig unsupported").step;
}
const all = b.step(module, "All " ++ module ++ " examples");
const module_subpath = b.pathJoin(&.{ "examples", module });
var dir = try std.fs.cwd().openDir(b.pathFromRoot(module_subpath), .{ .iterate = true });
defer if (comptime builtin.zig_version.minor >= 12) dir.close();
var iter = dir.iterate();
while (try iter.next()) |entry| {
if (entry.kind != .file) continue;
const extension_idx = std.mem.lastIndexOf(u8, entry.name, ".c") orelse continue;
const name = entry.name[0..extension_idx];
const path = b.pathJoin(&.{ module_subpath, entry.name });
// zig's mingw headers do not include pthread.h
if (std.mem.eql(u8, "core_loading_thread", name) and target.result.os.tag == .windows) continue;
const exe = b.addExecutable(.{
.name = name,
.target = target,
.optimize = optimize,
});
exe.addCSourceFile(.{ .file = b.path(path), .flags = &.{} });
exe.linkLibC();
// special examples that test using these external dependencies directly
// alongside raylib
if (std.mem.eql(u8, name, "rlgl_standalone")) {
exe.addIncludePath(b.path("src"));
exe.addIncludePath(b.path("src/external/glfw/include"));
if (!hasCSource(raylib.root_module, "rglfw.c")) {
exe.addCSourceFile(.{ .file = b.path("src/rglfw.c"), .flags = &.{} });
}
}
if (std.mem.eql(u8, name, "raylib_opengl_interop")) {
exe.addIncludePath(b.path("src/external"));
}
exe.linkLibrary(raylib);
switch (target.result.os.tag) {
.windows => {
exe.linkSystemLibrary("winmm");
exe.linkSystemLibrary("gdi32");
exe.linkSystemLibrary("opengl32");
exe.root_module.addCMacro("PLATFORM_DESKTOP", "");
},
.linux => {
exe.linkSystemLibrary("GL");
exe.linkSystemLibrary("rt");
exe.linkSystemLibrary("dl");
exe.linkSystemLibrary("m");
exe.linkSystemLibrary("X11");
exe.root_module.addCMacro("PLATFORM_DESKTOP", "");
},
.macos => {
exe.linkFramework("Foundation");
exe.linkFramework("Cocoa");
exe.linkFramework("OpenGL");
exe.linkFramework("CoreAudio");
exe.linkFramework("CoreVideo");
exe.linkFramework("IOKit");
exe.root_module.addCMacro("PLATFORM_DESKTOP", "");
},
else => {
@panic("Unsupported OS");
},
}
const install_cmd = b.addInstallArtifact(exe, .{});
const run_cmd = b.addRunArtifact(exe);
run_cmd.cwd = b.path(module_subpath);
run_cmd.step.dependOn(&install_cmd.step);
const run_step = b.step(name, name);
run_step.dependOn(&run_cmd.step);
all.dependOn(&install_cmd.step);
}
return all;
}
fn hasCSource(module: *std.Build.Module, name: []const u8) bool {
for (module.link_objects.items) |o| switch (o) {
.c_source_file => |c| if (switch (c.file) {
.src_path => |s| std.ascii.endsWithIgnoreCase(s.sub_path, name),
.generated, .cwd_relative, .dependency => false,
}) return true,
.c_source_files => |s| for (s.files) |c| if (std.ascii.endsWithIgnoreCase(c, name)) return true,
else => {},
};
return false;
}

View File

@ -0,0 +1,27 @@
.{
.name = .raylib,
.version = "5.5.0",
.minimum_zig_version = "0.14.0",
.fingerprint = 0x13035e5cb8bc1ac2, // Changing this has security and trust implications.
.dependencies = .{
.xcode_frameworks = .{
.url = "git+https://github.com/hexops/xcode-frameworks#9a45f3ac977fd25dff77e58c6de1870b6808c4a7",
.hash = "N-V-__8AABHMqAWYuRdIlflwi8gksPnlUMQBiSxAqQAAZFms",
.lazy = true,
},
.emsdk = .{
.url = "git+https://github.com/emscripten-core/emsdk#3.1.50",
.hash = "N-V-__8AALRTBQDo_pUJ8IQ-XiIyYwDKQVwnr7-7o5kvPDGE",
.lazy = true,
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
"examples",
},
}

View File

@ -0,0 +1,12 @@
include(CheckCCompilerFlag)
function(add_if_flag_compiles flag)
CHECK_C_COMPILER_FLAG("${flag}" COMPILER_HAS_THOSE_TOGGLES)
set(outcome "Failed")
if(COMPILER_HAS_THOSE_TOGGLES)
foreach(var ${ARGN})
set(${var} "${flag} ${${var}}" PARENT_SCOPE)
endforeach()
set(outcome "compiles")
endif()
message(STATUS "Testing if ${flag} can be used -- ${outcome}")
endfunction()

View File

@ -0,0 +1,23 @@
# Adding compile definitions
target_compile_definitions("raylib" PUBLIC "${PLATFORM_CPP}")
target_compile_definitions("raylib" PUBLIC "${GRAPHICS}")
function(define_if target variable)
if(${${variable}})
message(STATUS "${variable}=${${variable}}")
target_compile_definitions(${target} PRIVATE "${variable}")
endif()
endfunction()
if(${CUSTOMIZE_BUILD})
target_compile_definitions("raylib" PRIVATE EXTERNAL_CONFIG_FLAGS)
foreach(FLAG IN LISTS CONFIG_HEADER_FLAGS)
string(REGEX MATCH "([^=]+)=(.+)" _ ${FLAG})
define_if("raylib" ${CMAKE_MATCH_1})
endforeach()
foreach(VALUE IN LISTS CONFIG_HEADER_VALUES)
target_compile_definitions("raylib" PRIVATE ${VALUE})
endforeach()
endif()

View File

@ -0,0 +1,79 @@
include(AddIfFlagCompiles)
# Makes +/- operations on void pointers be considered an error
# https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html
add_if_flag_compiles(-Werror=pointer-arith CMAKE_C_FLAGS)
# Generates error whenever a function is used before being declared
# https://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/Warning-Options.html
add_if_flag_compiles(-Werror=implicit-function-declaration CMAKE_C_FLAGS)
# Allows some casting of pointers without generating a warning
add_if_flag_compiles(-fno-strict-aliasing CMAKE_C_FLAGS)
if (ENABLE_MSAN AND ENABLE_ASAN)
# MSAN and ASAN both work on memory - ASAN does more things
MESSAGE(WARNING "Compiling with both AddressSanitizer and MemorySanitizer is not recommended")
endif()
if (ENABLE_ASAN)
# If enabled it would generate errors/warnings for all kinds of memory errors
# (like returning a stack variable by reference)
# https://clang.llvm.org/docs/AddressSanitizer.html
add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
add_if_flag_compiles(-fsanitize=address CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
endif()
if (ENABLE_UBSAN)
# If enabled this will generate errors for undefined behavior points
# (like adding +1 to the maximum int value)
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
add_if_flag_compiles(-fsanitize=undefined CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
endif()
if (ENABLE_MSAN)
# If enabled this will generate warnings for places where uninitialized memory is used
# https://clang.llvm.org/docs/MemorySanitizer.html
add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
add_if_flag_compiles(-fsanitize=memory CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
endif()
if(CMAKE_VERSION VERSION_LESS "3.1")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_if_flag_compiles(-std=gnu99 CMAKE_C_FLAGS)
endif()
else()
set (CMAKE_C_STANDARD 99)
endif()
if(${PLATFORM} MATCHES "Android")
# If enabled will remove dead code during the linking process
# https://gcc.gnu.org/onlinedocs/gnat_ugn/Compilation-options.html
add_if_flag_compiles(-ffunction-sections CMAKE_C_FLAGS)
# If enabled will generate some exception data (usually disabled for C programs)
# https://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc/Code-Gen-Options.html
add_if_flag_compiles(-funwind-tables CMAKE_C_FLAGS)
# If enabled adds stack protection guards around functions that allocate memory
# https://www.keil.com/support/man/docs/armclang_ref/armclang_ref_cjh1548250046139.htm
add_if_flag_compiles(-fstack-protector-strong CMAKE_C_FLAGS)
# Marks that the library will not be compiled with an executable stack
add_if_flag_compiles(-Wa,--noexecstack CMAKE_C_FLAGS)
# Do not expand symbolic links or resolve paths like "/./" or "/../", etc.
# https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
add_if_flag_compiles(-no-canonical-prefixes CMAKE_C_FLAGS)
endif()

Some files were not shown because too many files have changed in this diff Show More