updated mlx

This commit is contained in:
Danny Jonker 2023-10-25 13:29:53 +02:00
parent 4cbcfa131a
commit 4d9e691ea6
62 changed files with 1903 additions and 1469 deletions

View File

@ -1,12 +1,12 @@
# **************************************************************************** #
# #
# .--. _ #
# Makefile |o_o || | #
# Makefile :+: :+: #
# |:_/ || |_ _ ___ __ #
# By: djonker <djonker@student.codam.nl> // \ \ __| | | \ \/ / #
# (| | )|_| |_| |> < #
# Created: 2022/11/24 10:12:10 by djonker /'\_ _/`\__|\__,_/_/\_\ #
# Updated: 2023/04/14 17:29:23 by houtworm \___)=(___/ #
# Updated: 2023/10/25 12:07:54 by djonker ######## odam.nl #
# #
# **************************************************************************** #
@ -18,10 +18,10 @@ RM =rm -f
UNAME_S :=$(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS =Freedom Respecting Linux! :)
LIB =libft/libft.a mlx/libmlx42.a -ldl -lglfw -pthread -lm
LIB =libft/libft.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
else
OS =Proprietary Malware :(
LIB =libft/libft.a mlx/libmlx42.a -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit
LIB =libft/libft.a mlx/build/libmlx42.a -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit
endif
SRC =src/main.c\
src/colors.c\
@ -65,6 +65,9 @@ libft:
@$(MAKE) -C libft all
libmlx:
@$(MAKE) -C mlx
@cd mlx
@cmake -S mlx -B mlx/build
@$(MAKE) -C mlx/build -j4
@cd ..
.PHONY: libft

View File

@ -16,8 +16,8 @@ A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
2. Click on '...'
3. Scroll down to '...'
4. See error
**Expected behavior**
@ -28,7 +28,7 @@ If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. MacOS]
- Version [e.g. BigSur]
- Version: [e.g. BigSur]
**Additional context**
Add any other context about the problem here.

View File

@ -1,89 +1,78 @@
# -----------------------------------------------------------------------------
# Codam Coding College, Amsterdam @ 2022-2023-2023 by W2Wizard.
# See README in the root project for more information.
# -----------------------------------------------------------------------------
name: Build
#=============================================================================#
on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 0 * * FRI'
#=============================================================================#
jobs:
# Tests
#=============================================================================#
unit-test:
timeout-minutes: 10
runs-on: ubuntu-latest
needs: build
env:
DISPLAY: ":99"
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Clone repository
uses: actions/checkout@v3
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y gcc make libglfw3-dev libglfw3 xorg build-essential cmake xorg-dev libx11-dev libglu1-mesa-dev freeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa libgl1-mesa-glx libgl1-mesa-dev xvfb
- name: Install GLFW
uses: RpxdYTX/install-glfw-deps@v2
- name: Install Dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq xorg-dev xvfb
- name: Setup x11
run: Xvfb $DISPLAY -screen 0 1280x1024x24 &
- name: Setup virtual screen
run: Xvfb $DISPLAY -screen 0 1280x1024x24 &
- name: Run tests
run: make -C test
- name: Build MLX42 & tests
run: cmake -DBUILD_TESTS=YES -B ${{github.workspace}}/build && cmake --build ${{github.workspace}}/build --parallel
build-unix:
- name: Run tests
run: ctest --output-on-failure --test-dir ${{github.workspace}}/build
# Unix
#=============================================================================#
build:
timeout-minutes: 10
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Clone repository
uses: actions/checkout@v2
uses: actions/checkout@v3
# Windows will just fetch glfw with cmake automatically.
# This avoids doing extra work like installing a package manager.
- name: Install Dependencies
if: matrix.os != 'windows-latest'
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update -qq
sudo apt-get install -y -qq gcc make xorg build-essential cmake xorg-dev libx11-dev libglu1-mesa-dev freeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa libgl1-mesa-glx libgl1-mesa-dev libglfw3-dev libglfw3
sudo apt-get install -y -qq xorg-dev
elif [ "$RUNNER_OS" == "macOS" ]; then
brew update
brew install glfw
else
echo "$RUNNER_OS not supported"
exit 1
fi
- name: Build
run: make
run: cmake -B build && cmake --build build --parallel
build-win:
timeout-minutes: 20
runs-on: windows-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Install MinGW
uses: egor-tensin/setup-mingw@v2
- name: Download GLFW binaries
uses: carlosperate/download-file-action@v1.1.1
with:
file-url: 'https://github.com/glfw/glfw/releases/download/3.3.6/glfw-3.3.6.bin.WIN64.zip'
file-name: 'glfw.zip'
location: '${{ github.workspace }}\lib'
- name: Unpack GLFW binaries
run: |
unzip 'lib/glfw.zip' -d 'lib'
rm 'lib\glfw.zip'
mv 'lib\glfw*' 'lib\glfw'
- name: Build
run: make HEADERS="-I lib/glfw/include" WIN_UNIX=1
#=============================================================================#

6
mlx/.gitignore vendored
View File

@ -60,3 +60,9 @@ lib/glfw/
# Special shader files
mlx_*_shader.c
build/
main.c
test
# Automatic downloaded deps
_deps/

180
mlx/CMakeLists.txt Normal file
View File

@ -0,0 +1,180 @@
# -----------------------------------------------------------------------------
# Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
# See README in the root project for more information.
# -----------------------------------------------------------------------------
# CMake specifications
# -----------------------------------------------------------------------------
cmake_minimum_required (VERSION 3.18.0)
project(mlx42 VERSION 2.3.2)
message(STATUS "MLX42 @ ${CMAKE_PROJECT_VERSION}")
# Variables
# -----------------------------------------------------------------------------
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# Options
set(DEBUG OFF CACHE BOOL "Build MLX42 in debug mode, enabling assertions")
set(GLFW_FETCH ON CACHE BOOL "Clone and install GLFW")
set(BUILD_TESTS OFF CACHE BOOL "Build the tests to verify the integrity of the lib")
# Compile Options
# -----------------------------------------------------------------------------
# Reduce the size of LodePNG, we don't need these things.
add_definitions(-D LODEPNG_NO_COMPILE_ENCODER)
add_definitions(-D LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS)
if(UNIX)
set(CCSHADER ${PROJECT_SOURCE_DIR}/tools/compile_shader.sh)
add_compile_options(
-Wextra
-Wall
-Werror
-Wunreachable-code
# Some low priority warnings that are annoying.
-Wno-char-subscripts
-Wno-sign-compare
-Wno-unused-parameter
-Wno-missing-field-initializers
)
if(DEBUG)
message(STATUS "Building in DEBUG mode")
add_compile_options(-g)
else()
message(STATUS "Building in RELEASE mode")
add_definitions(-D NDEBUG)
add_compile_options(-Ofast)
endif(DEBUG)
else()
# TODO: Figure out what we need for windows.
set(CCSHADER ${PROJECT_SOURCE_DIR}/tools/compile_shader.bat)
endif()
# Build specific files
# @see https://cmake.org/cmake/help/latest/command/add_custom_command.html
# -----------------------------------------------------------------------------
add_custom_command(
COMMENT "Building fragment shader"
DEPENDS ${PROJECT_SOURCE_DIR}/shaders/default.frag
OUTPUT mlx_frag_shader.c
COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR}/shaders/default.frag > mlx_frag_shader.c
VERBATIM
PRE_BUILD
USES_TERMINAL
)
add_custom_command(
COMMENT "Building vertex shader"
DEPENDS ${PROJECT_SOURCE_DIR}/shaders/default.vert
OUTPUT mlx_vert_shader.c
COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR}/shaders/default.vert > mlx_vert_shader.c
VERBATIM
PRE_BUILD
USES_TERMINAL
)
# Sources
# -----------------------------------------------------------------------------
add_library(mlx42 STATIC
# Root
${SOURCE_DIR}/mlx_cursor.c
${SOURCE_DIR}/mlx_exit.c
${SOURCE_DIR}/mlx_images.c
${SOURCE_DIR}/mlx_init.c
${SOURCE_DIR}/mlx_keys.c
${SOURCE_DIR}/mlx_loop.c
${SOURCE_DIR}/mlx_monitor.c
${SOURCE_DIR}/mlx_mouse.c
${SOURCE_DIR}/mlx_put_pixel.c
${SOURCE_DIR}/mlx_window.c
# Utils
${SOURCE_DIR}/utils/mlx_error.c
${SOURCE_DIR}/utils/mlx_list.c
${SOURCE_DIR}/utils/mlx_utils.c
${SOURCE_DIR}/utils/mlx_compare.c
# Textures
${SOURCE_DIR}/font/mlx_font.c
${SOURCE_DIR}/textures/mlx_png.c
${SOURCE_DIR}/textures/mlx_texture.c
${SOURCE_DIR}/textures/mlx_xpm42.c
# Libs
lib/png/lodepng.c
lib/glad/glad.c
mlx_vert_shader.c
mlx_frag_shader.c
)
target_include_directories(mlx42 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Dependencies
# -----------------------------------------------------------------------------
find_package(glfw3)
find_package(OpenGL REQUIRED)
target_link_libraries(mlx42 OpenGL::GL)
if (NOT glfw3_FOUND AND GLFW_FETCH)
message(STATUS "Install GLFW to suppress this message")
message(STATUS "Please wait, fetching GLFW ...")
include(${CMAKE_DIR}/LinkGLFW.cmake)
LinkGLFW(mlx42)
elseif(NOT glfw3_FOUND AND NOT GLFW_FETCH)
message(FATAL_ERROR "Unable to build: GLFW can't be found nor fetched.")
endif()
if (glfw3_FOUND)
target_link_libraries(mlx42 ${GLFW3_LIBRARY})
endif()
if(APPLE)
target_link_libraries(mlx42 "-framework Cocoa" "-framework IOKit")
endif()
# Testing
# -----------------------------------------------------------------------------
# Only build tests if we are the main project or explicitly told to, make sure
# tests are not built when mlx42 is included as a subproject, use MLX42_BUILD_TESTS to overwrite this
# use cmake -DBUILD_TESTS=ON/-DMLX42_BUILD_TESTS=ON to build tests
if ((PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME AND BUILD_TESTS) OR MLX42_BUILD_TESTS)
add_subdirectory(tests)
enable_testing()
endif()
# Installation
# -----------------------------------------------------------------------------
# Convenience feature to install the library and headers to the system.
# Use cmake -DCMAKE_INSTALL_PREFIX=/usr/local for example to install to /usr/local
# or any other directory that you want to install to.
#
# This only really useful if you are a system administrator and want to install
# the library to the system, if you are a developer you should just use the
# library as a subproject as you probably don't have (nor really should) have any
# amibitons to use this for anything other than your own school projects.
install(
DIRECTORY ./include/MLX42 DESTINATION ${CMAKE_INSTALL_PREFIX}/include
FILES_MATCHING PATTERN MLX42.h
)
install(TARGETS mlx42
EXPORT mlx42Targets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)

View File

@ -6,30 +6,30 @@ We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
nationality, personal appearance, race, religion or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
diverse, inclusive and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Demonstrating empathy and kindness towards other people
* Being respectful of differing opinions, viewpoints and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
* Accepting responsibility and apologizing to those affected by our mistakes
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
* The use of sexualized language or imagery and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Trolling, insulting or derogatory comments and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
@ -43,22 +43,22 @@ acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
Community leaders have the right and responsibility to remove, edit or reject
comments, commits, code, wiki edits, issues and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
This Code of Conduct applies within all community spaces and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
posting via an official social media account or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
Instances of abusive, harassing or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
main@w2wizard.dev.
All complaints will be reviewed and investigated promptly and fairly.
@ -98,7 +98,7 @@ Violating these terms may lead to a permanent ban.
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
individual or aggression towards or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.

View File

@ -1,77 +0,0 @@
# **************************************************************************** #
# #
# :::::::: #
# Makefile :+: :+: #
# +:+ #
# By: W2Wizard <w2.wizzard@gmail.com> +#+ #
# +#+ #
# Created: 2022/02/26 21:32:49 by W2Wizard #+# #+# #
# Updated: 2022/08/10 12:42:39 by lde-la-h ######## odam.nl #
# #
# **************************************************************************** #
NAME := libmlx42.a
LIB_DIR := lib
SRC_DIR := src
SHADER_DIR := shaders
INCLUDE_DIR := include
override HEADERS += -I $(INCLUDE_DIR)
CFLAGS := -Wextra -Wall -Werror -Wunreachable-code -Wno-char-subscripts -Wno-sign-compare \
-DLODEPNG_NO_COMPILE_ANCILLARY_CHUNKS -DLODEPNG_NO_COMPILE_ENCODER
ifdef DEBUG
CFLAGS += -g
else
CFLAGS += -Ofast -D NDEBUG
endif
# Recursive wildcard/find function, the subst is to guarantee unix file paths
rwildcard = $(subst \,/,$(sort $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2) $(wildcard $1/$2))))
SHDR := $(call rwildcard,$(SHADER_DIR),default.*)
SHDR := $(SHDR:$(SHADER_DIR)/default.%=$(SRC_DIR)/mlx_%_shader.c)
LIB := $(call rwildcard,$(LIB_DIR),*.c)
SRCS := $(call rwildcard,$(SRC_DIR),*.c)
OBJS := $(sort $(patsubst %.c,%.o,$(SRCS) $(LIB) $(SHDR)))
HDRS := $(call rwildcard,$(INCLUDE_DIR),*.h)
ifeq ($(OS), Windows_NT)
ifdef WIN_UNIX
include Makefile_Unix.mk
else
include Makefile_WindowsNT.mk
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
include Makefile_Unix.mk
else ifeq ($(UNAME_S), Darwin)
# Default
DYLIB_EXISTS := test -e /usr/local/lib/libglfw.3.dylib || echo "false"
# Generic Homebrew path
ifneq ($(DYLIB_EXISTS), false)
BREW_GLFW_PREFIX := $(shell brew --prefix glfw)
DYLIB_EXISTS := test -e $(BREW_GLFW_PREFIX)/lib/libglfw.3.dylib || echo "false"
ifneq ($(DYLIB_EXISTS), false)
override HEADERS += -I $(BREW_GLFW_PREFIX)/include
endif
endif
include Makefile_Unix.mk
else
$(error OS: $(OS) - Is not supported!)
endif
endif
#//= Make Rules =//#
all: $(SHDR) $(NAME)
# Run make as part of the recipe to allow for multi-threading to be used (-j)
re: fclean
@$(MAKE) -e
#//= Misc =//#
.DEFAULT_GOAL := all
.PHONY: all clean fclean re

View File

@ -1,44 +0,0 @@
# **************************************************************************** #
# #
# :::::::: #
# Makefile_Unix.mk :+: :+: #
# +:+ #
# By: W2Wizard <w2.wizzard@gmail.com> +#+ #
# +#+ #
# Created: 2022/02/26 21:36:38 by W2Wizard #+# #+# #
# Updated: 2022/07/05 14:53:23 by jobvan-d ######## odam.nl #
# #
# **************************************************************************** #
#//= Colors =//#
BOLD := \033[1m
BLACK := \033[30;1m
RED := \033[31;1m
GREEN := \033[32;1m
YELLOW := \033[33;1m
BLUE := \033[34;1m
MAGENTA := \033[35;1m
CYAN := \033[36;1m
WHITE := \033[37;1m
RESET := \033[0m
#//= Make Rules =//#
$(NAME): $(OBJS)
@ar rc $@ $^
@echo "$(GREEN)$(BOLD)Done$(RESET)"
%.o: %.c $(HDRS)
@echo "$(GREEN)$(BOLD)Compiling:$(RESET) $(notdir $<)"
@$(CC) $(CFLAGS) -o $@ -c $< $(HEADERS)
# Convert shaders to .c files
$(SRC_DIR)/mlx_%_shader.c: $(SHADER_DIR)/default.%
@echo "$(GREEN)$(BOLD)Shader to C: $< -> $@$(RESET)"
@bash tools/compile_shader.sh $< > $@
clean:
@echo "$(RED)Cleaning$(RESET)"
@rm -f $(OBJS) $(SHDR)
fclean: clean
@rm -f $(NAME)

View File

@ -1,49 +0,0 @@
# **************************************************************************** #
# #
# :::::::: #
# Makefile_WindowsNT.mk :+: :+: #
# +:+ #
# By: W2Wizard <w2.wizzard@gmail.com> +#+ #
# +#+ #
# Created: 2022/02/26 21:32:00 by W2Wizard #+# #+# #
# Updated: 2022/07/05 14:55:05 by jobvan-d ######## odam.nl #
# #
# **************************************************************************** #
# While windows does have support for nmake it offers nowhere near the amount of
# features GnuWin does.
#//= Colors =//#
# Nope :(
CC := gcc # We need to explicitly mention GCC/CC here.
WINSTFU := > NUL 2>&1 # In some cases we want windows to just stfu
# Switch file paths to windows \ delimiter
SHDR := $(subst /,\,$(SHDR))
LIB := $(subst /,\,$(LIB))
SRCS := $(subst /,\,$(SRCS))
OBJS := $(subst /,\,$(OBJS))
HDRS := $(subst /,\,$(HDRS))
#//= Make Rules =//#
$(NAME): $(OBJS)
@ar rc $@ $^
@echo Done
%.o: %.c $(HDRS)
@echo Compiling: $(notdir $<)
@$(CC) $(CFLAGS) -o $@ -c $< $(HEADERS)
# Convert shaders to .c files
$(SRC_DIR)\mlx_%_shader.c: $(SHADER_DIR)\default.%
@echo Shader to C: $< -^> $@
@.\tools\compile_shader.bat $< > $@
clean:
@echo Cleaning
@del /F /Q $(OBJS) $(SHDR) $(WINSTFU)
fclean: clean
@del /F /Q $(NAME) $(WINSTFU)

View File

@ -7,115 +7,149 @@
<div align="center">
</br>
<img src="https://img.shields.io/github/license/codam-coding-college/MLX42" alt="License GPL2.0">
<img src="https://svgshare.com/i/Zhy.svg" alt="Linux">
<img src="https://svgshare.com/i/ZjP.svg" alt="MacOS">
<img src="https://svgshare.com/i/ZhY.sv" alt="Windows">
<img src="https://github.com/codam-coding-college/MLX42/actions/workflows/ci.yml/badge.svg" alt="Build">
<img src="https://img.shields.io/github/forks/codam-coding-college/MLX42" alt="Forks">
</div>
</div>
A recreation of the MiniLibX library used by 42, using GLFW & glad, running on OpenGL.
The goal of MLX42 is to replace the outdated and stale MiniLibX library.
MLX42 is a performant, easy to use, cross-platform, minimal windowing graphics library to create graphical applications without having to work directly with the native windowing framework of the given operating system.
For information and documentation about MLX42 check the wiki.
It provides primitive tools to draw textures onto the window as well as modifying them at runtime as they get displayed on the window.
## Differences to MiniLibX
# Features ✨
#### Cross-Platform
The main idea of MLX42 is to be a cross-platform graphics interface. In 42 everything runs (currently) on MacOS, but it's
very useful to be able to work remotely on different machines. With MiniLibX this is not possible.
MLX42 comes with a plethora of features that make using it actually a joy instead of a chore.
#### Documented
Almost all functions and types are fully documented giving you a clue as to how to approach and use the library.
## Cross-Platform 🖥️
Run it on your grandma's WindowsXP, on your uncle's debian or on a hipster's MacOS!
No matter what the platform, if MLX42 can build on it, it will run on its native windowing system.
This allows you to work on your project no matter which machine it is on.
## Documented 📚
MLX42 cares about good documentation, every function, usage and even some internal workings are documented!
No more guessing and searching how something functions or is supposed to work.
#### Custom XPM (XPM42) format
A custom simple to use XPM-like format which has some minor differences to the XPM3 format.
## Performance 🚀
#### Almost identical usage to MiniLibX
Switching to MLX42 from MiniLibX is not a lot of work, most features present in MiniLibX are also present in MLX42, albeit with different prototypes.
It is built on OpenGL and uses batched rendering to speed up the rendering process compared to other libraries.
## Open source && Community driven 🌐
This project is being actively maintained by Codam as well as students from the 42 Network. This gives students the direct opportunity to learn more about the library itself as well as fix any potential bugs instead of merely accepting them.
---
## Installation
## Installation 🏗️
### General compilation
In the very end a library is generated, compile your program with this library!
Overall the building of this project is as follows for ALL systems. As long as CMake can make sense of it.
### For MacOS:
1. [Download and build MLX42](#download-and-build---mlx42)
1. Download MLX42
```bash
➜ ~ git clone https://github.com/codam-coding-college/MLX42.git
```
In case your system doesn't have [glfw](https://github.com/glfw/glfw) installed cmake will detect this and download it for you.
You can then run `sudo make install` in the `_deps` directory of glfw. If you're using a 42 Computer (MacOS, Linux), ask your favourite sysadmin to install it.
Same goes for CMake or any other dependencies you might need for your system.
### Via [Homebrew](https://brew.sh/) / [Homebrew42](https://github.com/kube/42homebrew) by building from source.
However if you can't do either CMake will still be able to fetch GLFW and build it. You can then statically link it from the `_deps` folder.
2. Install GLFW
> **Note**: For Codam, GLFW is already installed on the Macs.
Through brew:
> **Note**: During the linking stage, the flag to link GLFW can either be: -lglfw3 or -lglfw depending on your system.
1. Compile your program with the library:
- For: [MacOS](#for-macos)
- For: [Linux](#for-linux)
- For: [Windows](#for-windows)
2. Profit!
### Installing to the system
To fully build the library and install it to your system run the following command:
```bash
➜ ~ brew update
➜ ~ brew install glfw
cmake -B build && cmake --build build --parallel --config (Debug|Release|RelWithDebInfo|MinSizeRel) --target install
```
If you're studying at Codam you can simply link GLFW normally since its now installed on the macs.
By default windows will place the installed lib into: `C:\Program Files (x86)\mlx42` and for MacOS / Linux it will be placed into `/usr/local/lib` and `/usr/local/include` respectively.
3. [Download and build MLX42](#download-and-build---mlx42)
4. Compile Program
With the normal brew version you can now simply compile the program with:
```bash
➜ ~ gcc main.c libmlx42.a -lglfw ...
### Unit tests
MLX42 comes with some unit tests to ensure the integrity of the library, to build them run the following command:
```sh
cmake -DBUILD_TESTS=ON -B build && cmake --build build --parallel
```
You might have to specify the location explicitly:
```bash
➜ ~ gcc main.c libmlx42.a -lglfw -L /opt/homebrew/Cellar/glfw/3.3.6/lib/
Then simply run them with:
```sh
ctest --output-on-failure --test-dir build
```
However, with 42Homebrew you have additionally specify the location of the library like here:
```bash
➜ ~ gcc main.c libmlx42.a -I include -lglfw -L "/Users/$USER/.brew/opt/glfw/lib/"
```
Or, if studying at Codam, compile using the following flags:
```bash
➜ ~ gcc main.c libmlx42.a -I include -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit
```
5. Run!
----
### Pre-compiled libraries (GLFW)
## Download and build - MLX42
2. Download the binaries directly [here](https://www.glfw.org/download.html).
3. If possible move the contents of `lib` and `include` of GLFW to `/usr/local/lib` and `/usr/local/include` respectively.
If not possible, move the lib file to the root of MLX42 and move the GLFW directory in include to the include of MLX42.
NOTE: For the lib choose the appropriate `.a` & `.dylib` file depending on your architecture.
4. [Download and build MLX42](#download-and-build---mlx42)
When compiling with the static library, directly you should compile your program like this:
```bash
➜ ~ gcc main.c libmlx42.a libglfw3.a ... -framework Cocoa -framework OpenGL -framework IOKit
```
Else, simply compile like this:
```bash
➜ ~ gcc main.c libmlx42.a -lglfw ...
```bash
➜ ~ git clone https://github.com/codam-coding-college/MLX42.git
➜ ~ cd MLX42
➜ ~ cmake -B build # build here refers to the outputfolder.
➜ ~ cmake --build build -j4 # or do make -C build -j4
```
5. Run
The output library file is called `libmlx42.a` and is located in the `build` folder that you specified.
### Available Options
You can pass build [options](./docs/index.md#available-options) to cmake, e.g: `cmake -DDEBUG=1 -DGLFW_FETCH=0...`. These will for instance let you build it in DEBUG mode or alter any sort of behaviour at build-time.
You can find an example makefile in the documentation [here](https://github.com/codam-coding-college/MLX42/blob/master/docs/Basics.md).
----
## For MacOS:
### Installing the dependencies
If your system has neither GLFW nor CMake its highly recommended you use brew to install those missing dependencies.
For 42 Campuses you can use: [42Homebrew](https://github.com/kube/42homebrew)
```bash
# This will also install CMake.
# Be aware that this may take a while so be patient.
➜ ~ brew install glfw
```
For MacOS you need to use the following flags to compile your program with the library
in order to link the program with the correct frameworks:
```bash
-framework Cocoa -framework OpenGL -framework IOKit
```
Normally if you simply installed / built `glfw` from source or already have it installed
the compilation should be:
```bash
➜ ~ gcc main.c ... libmlx42.a -Iinclude -lglfw
```
#### Via [Homebrew](https://brew.sh/) / [42Homebrew](https://github.com/kube/42homebrew)
```bash
# Homebrew
➜ ~ gcc main.c ... libmlx42.a -Iinclude -lglfw -L"/opt/homebrew/Cellar/glfw/3.3.8/lib/"
# 42Homebrew
➜ ~ gcc main.c ... libmlx42.a -Iinclude -lglfw -L"/Users/$(USER)/.brew/opt/glfw/lib/"
```
#### MacOS Security:
When running your program in MacOS it may complain, because with Macs you just gotta think differently.
In case of any security warnings or MacOS telling you it can't verify the author/developer, go to ```Settings > Security & Privacy```.
There will be a pop-up at the bottom telling you that an application tried to run, click the option to let it run.
----
### For Linux:
## For Linux:
1. Install the necessary packages:
@ -137,13 +171,18 @@ OR (if you use sway/wlroots compositor or other wayland compositor)
2. [Download and build MLX42](#download-and-build---mlx42)
3. Create a ```main.c``` file, include ```MLX42/MLX42.h```, compile with ```-ldl -lglfw (or -lglfw3) -pthread -lm```, make sure to also do ```-I <include_path>```.
4. Run.
3. Compile your program with the library:
```bash
➜ ~ gcc main.c ... libmlx42.a -Iinclude -ldl -lglfw -pthread -lm
```
4. Profit!
----
### For Windows (with Windows Subsystem for Linux 2 (WSL2))
## For Windows (with Windows Subsystem for Linux 2 (WSL2))
> **Warning**: Before starting with all these steps, [read this](https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps)
1. Set these variables in your `.zshrc` or `.bashrc`:
```bash
@ -174,130 +213,112 @@ and they might not even show up in the list until the first time you start the a
----
### For Windows:
## For Windows Native:
1. Download & Install [MinGW](https://sourceforge.net/projects/mingw/)
> **Warning**: Be aware that Visual Studio (2022) is required for this. Developing on Windows can be somewhat frustrating.
2. Simply click continue, select whatever your choice is.
Once reaching the MinGW Installation Manager select:
- mingw32-base
- mingw32-gcc-g++
We highly recommend you simply use [WSL2](#for-windows-with-windows-subsystem-for-linux-2-wsl2) to make this as painless as possible.
However if you insist on building for windows natively then all you need in terms of dependencies is:
3. Apply by going to `Installation > Apply Changes`, after it's done, you may close the window.
- [CMake](https://cmake.org/download/)
- [GLFW](https://www.glfw.org/download.html)
4. Download & Install [CMake](https://cmake.org/download/).
- Use the installer and select all default options.
Once you have all the dependencies correctly installed `CMake` will generate
the visual studio project files. Simply build it and once you have a `.lib` file
move them to your actual project and install them as you would with any other library.
5. For Windows we need to install an additional component to **make** the **make** command available.
Just in case here's a [video](https://youtu.be/or1dAmUO8k0?t=494) showing you how this can be done. Conveniently this video also covers how you can link `glfw`.
- Using the [chocolatey package manager](https://chocolatey.org/)
```bash
➜ ~ choco install make
```
- Using [GnuWin](https://sourceforge.net/projects/gnuwin32/files/make/3.81/make-3.81.exe/download) (download & install)
6. If you used all default options, add these paths to your SYSTEM Environment variables:
- C:\MinGW\bin
- C:\Program Files\CMake\bin
- C:\Program Files (x86)\GnuWin32\bin
7. Download the [GLFW source package](https://www.glfw.org/download.html) and extract it somewhere.
8. Open the terminal and type `cmake-gui`, select the downloaded/extracted
source folder, select any place you want the build output to be.
9. Click on configure once and select the `MinGW Makefiles`, then finish.
10. Set the CMAKE_INSTALL_PREFIX to `C:/GLFW`
11. Click on configure again, and then generate.
12. Go to the build directory and do:
- `make`
- `make install`
13. Go to the directory you assigned in Step 10. Copy the GLFW folder in the include folder to `C:\MinGW\include` & copy the .a file in the lib folder to `C:\MinGW\lib`.
14. [Download and build MLX42](#download-and-build---mlx42)
15. Compile your program with these flags:
- `-lglfw3`
- `-lopengl32`
- `-lgdi32`
In the end you should have something like:
```bash
➜ ~ gcc main.c <Additional .c Files> libmlx42.a -lglfw3 -lopengl32 -lgdi32
```
15. Run.
## Download and build - MLX42
```bash
➜ ~ git clone https://github.com/codam-coding-college/MLX42.git
➜ ~ cd MLX42
➜ ~ make
```
The output library file is called `libmlx42.a`.
Of course it's up to you to make sure that the code you write is portable. Things that exist on `Unix` don't necessarily exist on `Win32`.
## Example
![MLX42](https://user-images.githubusercontent.com/63303990/150696516-95b3cd7b-2740-43c5-bdcd-112193d59e14.gif)
![MLX42](docs/assets/demo.gif)
```c
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* +#+ */
/* Created: 2022/01/31 00:40:08 by W2Wizard #+# #+# */
/* Updated: 2022/01/31 00:41:56 by W2Wizard ######## odam.nl */
/* */
/* ************************************************************************** */
// -----------------------------------------------------------------------------
// Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
// See README in the root project for more information.
// -----------------------------------------------------------------------------
#include "MLX42/MLX42.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <memory.h>
#define WIDTH 256
#define HEIGHT 256
#include <stdlib.h>
#include <stdbool.h>
#include <MLX42/MLX42.h>
mlx_image_t *g_img;
#define WIDTH 512
#define HEIGHT 512
void hook(void *param)
static mlx_image_t* image;
// -----------------------------------------------------------------------------
int32_t ft_pixel(int32_t r, int32_t g, int32_t b, int32_t a)
{
mlx_t *mlx;
return (r << 24 | g << 16 | b << 8 | a);
}
void ft_randomize(void* param)
{
for (int32_t i = 0; i < image->width; ++i)
{
for (int32_t y = 0; y < image->height; ++y)
{
uint32_t color = ft_pixel(
rand() % 0xFF, // R
rand() % 0xFF, // G
rand() % 0xFF, // B
rand() % 0xFF // A
);
mlx_put_pixel(image, i, y, color);
}
}
}
void ft_hook(void* param)
{
mlx_t* mlx = param;
mlx = param;
if (mlx_is_key_down(mlx, MLX_KEY_ESCAPE))
mlx_close_window(mlx);
if (mlx_is_key_down(mlx, MLX_KEY_UP))
g_img->instances[0].y -= 5;
image->instances[0].y -= 5;
if (mlx_is_key_down(mlx, MLX_KEY_DOWN))
g_img->instances[0].y += 5;
image->instances[0].y += 5;
if (mlx_is_key_down(mlx, MLX_KEY_LEFT))
g_img->instances[0].x -= 5;
image->instances[0].x -= 5;
if (mlx_is_key_down(mlx, MLX_KEY_RIGHT))
g_img->instances[0].x += 5;
image->instances[0].x += 5;
}
int32_t main(void)
{
mlx_t *mlx;
// -----------------------------------------------------------------------------
int32_t main(int32_t argc, const char* argv[])
{
mlx_t* mlx;
// Gotta error check this stuff
if (!(mlx = mlx_init(WIDTH, HEIGHT, "MLX42", true)))
{
puts(mlx_strerror(mlx_errno));
return(EXIT_FAILURE);
}
if (!(image = mlx_new_image(mlx, 128, 128)))
{
mlx_close_window(mlx);
puts(mlx_strerror(mlx_errno));
return(EXIT_FAILURE);
}
if (mlx_image_to_window(mlx, image, 0, 0) == -1)
{
mlx_close_window(mlx);
puts(mlx_strerror(mlx_errno));
return(EXIT_FAILURE);
}
mlx_loop_hook(mlx, ft_randomize, mlx);
mlx_loop_hook(mlx, ft_hook, mlx);
mlx = mlx_init(WIDTH, HEIGHT, "MLX42", true);
if (!mlx)
exit(EXIT_FAILURE);
g_img = mlx_new_image(mlx, 128, 128);
memset(g_img->pixels, 255, g_img->width * g_img->height * sizeof(int));
mlx_image_to_window(mlx, g_img, 0, 0);
mlx_loop_hook(mlx, &hook, mlx);
mlx_loop(mlx);
mlx_terminate(mlx);
return (EXIT_SUCCESS);

View File

@ -1,7 +0,0 @@
# Version
## Current Version: 2.2.1
---
## Latest: <img style="margin: 0px 0px -3px 0px" src="https://img.shields.io/github/v/tag/codam-coding-college/MLX42?label=Version" alt="License GPL2.0"> <img style="margin: 0px 0px -3px 0px" src="https://github.com/codam-coding-college/MLX42/actions/workflows/ci.yml/badge.svg" alt="Build">

45
mlx/cmake/Findglfw3.cmake Normal file
View File

@ -0,0 +1,45 @@
# -----------------------------------------------------------------------------
# Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
# See README in the root project for more information.
# -----------------------------------------------------------------------------
# Try to find GLFW3 library and include path.
# Once done this will define:
# - GLFW3_FOUND
# - GLFW3_INCLUDE_PATH
# - GLFW3_LIBRARY
# Possbile header locations
set(_glfw3_HEADER_SEARCH_DIRS
"/usr/include"
"/usr/local/include"
"C:/Program Files/GLFW/include"
"C:/Program Files (x86)/GLFW/include"
"$ENV{HOME}/.brew/include/"
"$ENV{HOME}/homebrew/include/"
)
# Possbile library locations
set(_glfw3_LIB_SEARCH_DIRS
"/usr/lib"
"/usr/local/lib"
"C:/Program Files/GLFW"
"C:/Program Files (x86)/GLFW"
"$ENV{HOME}/.brew/lib/"
"$ENV{HOME}/homebrew/lib/"
)
# Search for the header
find_path(GLFW3_INCLUDE_PATH "GLFW/glfw3.h" PATHS ${_glfw3_HEADER_SEARCH_DIRS})
# Search for the library
find_library(GLFW3_LIBRARY NAMES glfw3 glfw PATHS ${_glfw3_LIB_SEARCH_DIRS})
if (GLFW3_INCLUDE_PATH AND GLFW3_LIBRARY)
set(glfw3_FOUND "YES")
include_directories(${GLFW3_INCLUDE_PATH})
message(STATUS "Found GLFW: ${GLFW3_LIBRARY}")
else()
set(glfw3_FOUND "NO")
message(WARNING "Unable to find dependency: GLFW\nDid you install it?")
endif()

38
mlx/cmake/LinkGLFW.cmake Normal file
View File

@ -0,0 +1,38 @@
# -----------------------------------------------------------------------------
# Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
# See README in the root project for more information.
# -----------------------------------------------------------------------------
include(FetchContent)
macro(LinkGLFW TARGET)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw
GIT_TAG 3.3.8
)
FetchContent_GetProperties(glfw)
if (NOT glfw_POPULATED)
FetchContent_Populate(glfw)
# Just configure GLFW only
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Build Examples" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "Build docs" FORCE)
set(GLFW_INSTALL ON CACHE BOOL "Configure an install" FORCE)
# This excludes glfw from being rebuilt when ALL_BUILD is built
# it will only be built when a target is built that has a dependency on glfw
add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR} EXCLUDE_FROM_ALL)
# Set the target's folders
set_target_properties(glfw PROPERTIES FOLDER ${PROJECT_NAME}/thirdparty)
endif()
target_include_directories(${TARGET} PRIVATE ${glfw_SOURCE_DIR}/include)
target_link_libraries(${TARGET} glfw)
add_dependencies(${TARGET} glfw)
endmacro()

213
mlx/docs/42.md Normal file
View File

@ -0,0 +1,213 @@
<!----------------------------------------------------------------------------
Copyright @ 2021-2022 Codam Coding College. All rights reserved.
See copyright and license notice in the root project for more information.
----------------------------------------------------------------------------->
</br>
<div align="center">
<img src="./assets/logo.png" alt="42MLX_Logo">
</div>
<div align="center" style="margin-top: 8px;">
<sub>Written by <a href="https://portfolio.w2wizard.dev/">W2.Wizard</a> for the 42 Network</sub>
</div>
</br>
<div align="center">
<h1>Welcome to the MLX42, 42Campus documentation</h1>
</div>
# Foreword
If you're considering allowing the use of MLX42 in your campus and wondering why you should do it, how it should work, and what it will take to get it working, then you're in the right place!
MLX42 has been battle-tested multiple times at hackathons and other campuses and has received over 500 commits since 2021. All students share the same sentiment: they enjoy using the library, but it's not too easy to finish the projects. During that time many bugs, leaks, and segfaults have been fixed.
It addresses one of the main problems at 42, which is that although it is a tech school, it does not provide its students with well-maintained tools to improve their education. All a campus wants is to give its students the best they can.
| Campus | Allowed | Additional Notes |
| ----------|:------------:| :------------------|
| Codam | ✅ | |
| Mulhouse | ✅ | |
| Quebec | ✅ | |
| Belo Horizonte | ❓ | |
| São Paulo | ✅ | |
| Rio | ❓ | |
| Malaga | ✅ | |
| Barcelona | ✅ | Would like propose some modifications preferably |
| Nice | ✅ | Banned `mlx_put_pixel` & `mlx_resize_image` otherwise fully authorized 🎊 |
| Berlin | ✅ | Available at `usr/local/bin/minilibx` |
| Heilbronn | ✅ | |
| 1337 | ✅ | 1337 Refers to every campus part of 1337 |
| Angoulême | ✅ | |
| Lausanne | ❓ | No idea how to reach them |
| Prague | ✅ | |
| 19 | ❓ | Inquired and interested on it but no further details |
| Hive | ✅ | |
| Vienna | ❓ | |
| Seoul | ❌ | I didn't really understand why but basically as long as Paris says no they will too |
| Madrid | ❓ | They Tolerate it but it's up to the evaluator to decide because it's not part of the subject. |
| Porto | ❌ | Not Auth from Paris|
| Lisboa | ❌ | Not Auth from Paris|
| Wolfsburg | ❌ | Not Auth from Paris|
| Urduliz | ❌ | Not Auth from Paris|
| Paris | ❌ | Because its Paris 🤡|
Regarding other campuses the status is unknown.
---
# Technical comparison
## MiniLibX
The miniLibX has many problems that have been around for almost 10+ years:
- `Not maintained`: The library is practically dead, and it's unclear who is available to fix the bugs. It hasn't had any changes in a long time, and student pull requests on Github for the X11 version go unnoticed. Issues are also being ignored.
- `Poor documentation`: The documentation consists of a few man pages that are outdated and an online documentation created by another student. It's understandable that students have to learn on their own, but a library with an extensive API requires proper documentation for anyone to start understanding it.
- `Poor execution`: There are multiple versions: OpenGL, Swift, and X11. Instead of becoming better with each new iteration, they stay the same with no real improvement. It should be future-proof and not dependent on a specific platform. People are struggling with the there being so many different versions that they start losing track where the problem actually is.
- `Not cross-platform`: Students constantly encounter the same problem: at school they work with MacOS, but at home they use Linux. Or they write their project on Linux, but want to show it to their parents using Windows or MacOS. At each point, miniLibX fails to fill that gap. The pandemic in 2019 showed just how much students struggled to evaluate each other using different machines and versions.
---
## MLX42
The main goal of MLX42 is to address all of these shortcomings of the original versions. There are some differences, mainly in the way images are rendered, but everything else is basically the same.
So far, all of the drawbacks of miniLibX have been taken care of, and students using it are enjoying it!
### Rendering
One of the biggest differences between the two libraries is the way rendering is handled.
In `miniLibX`, students change the buffer of an image and then push it to the window.
In `MLX42`, students put the image to the window and can change the buffer at any time, resulting in an immediate update to the image.
MLX42 uses instances instead. An image is like the original painting, while instances are individual copies of this painting on the window.
There is no window clearing function because students need to learn how to properly manage their images. They can still delete images and turn instances on or off, of course.
Internally, it uses batched rendering to further improve performance. The actual documentation and the code itself have more details.
### Maintained & Open-source
The main goal of MLX42 is to empower students and pedagogues by giving them the ability to maintain and fix bugs, instead of leaving their complaints unaddressed. By being open-source, students can explore the code and submit pull requests.
### Documentation
The repository comes with a well-maintained [Wiki](https://github.com/codam-coding-college/MLX42/wiki) and documentation in the form of `markdown` files in the repository root.
### Build system
MLX42 initially used `make`, but it was inflexible and caused weird bugs for others. Since version 2.3.0 it uses `cmake` for a truly cross-platform build system.
Students do not need to understand how to use `cmake`, as building the library requires only two shell commands. The instructions on how to build the library are provided to them.
### XPM42
For historical reasons, I included my own file format that mimics XPM3. In the original miniLibX, the way XPM files were handled made no sense, as they were supposed to be compiled into the binary. Instead, miniLibX parsed the files and pasted the data into memory.
In the `tools` folder, there is a python script that converts XPM3 to XPM42. XPM42 is available as an alternative, but it is highly encouraged to use the PNG importer, which does not leak and uses lodepng for parsing.
---
### How can I migrate? What is necessary to change?
Migrating to MLX42 is easy and requires minimal effort, it requires just 2 dependencies in order to work.
#### Dependencies
- [CMake: >= 3.18.0](https://cmake.org/download/)
- [GLFW: >= 3.3.6](https://github.com/glfw/glfw)
It is up to your pedago staff or system administrator to determine how to distribute MLX42 to students.
The options are:
- `A`: Install it on the machine in a location such as /usr/local/lib and use -lmlx42 to link it.
- `B`: Have students clone the repository, preferably as a submodule, and include it in their repository.
There is not much else to do besides these steps. It is a straightforward replacement, and the choice of distribution is up to the campus.
## F.A.Q
Q: **_"It has too many features! I think students should implement some of them themselves including some functions..."_**
A: If there is one frustrating point in this entire F.A.Q then it is this one. Because 42 Network's pedago never actually clarifies what this even means? They don't communicate what is supposededly "too useful". Because if they did then it wouldn't require having to write this entire F.A.Q and pointing out all their flawed arguments. It's been 2 years now and not once have the maintainers been approached by the network's pedago.
***WHAT*** functions are too useful you may wonder? Well really there aren't many if any that we can think of. The majority of additional functions are just GLFW wrappers to enable more extensive customization of the window. This includes setting custom cursors or app icons which really don't add any complexity nor are students able to do this themselves anyway. They are available without impeding their learning.
If there was something too useful that really criticaly hinders the adoption of this library. I would advise that we use communication much like any other species of this planet to resolve it.
---
Q: **_"The `mlx_put_pixel` works too well..."_**
A: Rather than purposefully sabotaging the library to make a point, I deemed it necessary that the library simply works. By default, this function is already banned by all subjects, and the main idea was to force students to use images.
In MLX42 it always starts with an image, and students are forced to face images no matter what. They still face the same learning curve of how to modify the buffer of an image and learn the concept of bit shifting one way or another.
Our proposal is to allow its use in the first three graphics projects (fract-ol, fdf, so_long) and later ban it for the remaining ones (Cub3D, MiniRT), so students can become familiar with it and then need to explore its workings.
---
Q: **_"Are the libraries 1:1 identical?"_**
A: No, there are 100% breaking changes, and changing from miniLibX to MLX42 will not be a simple drop-in replacement. As in their API is slightly different. That was not the idea eitherway, as it would be impossible to fix the problems present in the current miniLibX.
In terms of usage, it's practically identical, while the API Prototypes are slightly different, the usage is roughly the same and the only core difference is the way images are handled.
My suggestion is for students who are using miniLibX to keep using it to finish their project and for new students to prefer the new one or until they reach the next graphical project.
---
Q: **_"With regards to how the rendering is done, won't that make it too easy for students?"_**
A: After almost a year in use, both new students who didn't use the old one and students who used both managed just fine and even appreciated this change in the way rendering works in MLX42.
It is not taking away from the learning experience, it's just shifting a function call from one place to another. Students still find it challenging to finish the actual project, as they still need to learn a whole new library and how it operates.
---
Q: **_"OpenGL? Isn't that a bit old by now?"_**
A: Is OpenGL old? Sure. But in the end, students don't care. You could argue that it's less future-proof and that Vulkan should be used instead. But ask yourself, does one need an artillery cannon to hunt for a rabbit in a forest? If your answer is no, then why does one need Vulkan to render a bunch of quads on a window?
OpenGL is easy to learn, widely supported and it could be argued that it's actually useful for students who are interested in graphics. Anyway, if one day Vulkan is required, a branch and PR can be created and merged!
Just a small reminder that it takes roughly [700+ lines of code](https://github.com/SaschaWillems/Vulkan/blob/master/examples/triangle/triangle.cpp) to render a triangle with vulkan...
Here is the equivalent in [OpenGL](https://learnopengl.com/code_viewer_gh.php?code=src/1.getting_started/2.1.hello_triangle/hello_triangle.cpp).
---
Q: **_"CMake? Won't that confuse them?"_**
A: It is 2 simple commands that are described in the README, and it's a good opportunity to learn a new way to build your projects.
---
Q: **_"Who will maintain MLX42? How long can this be guaranteed?"_**
A: Currently it is being maintained by `lde-la-h` (W2Wizard). However commits from the 42 Pedago or really anyone are very much welcome.
I myself have been taking care of it since the 1st of January 2021 and aim to continue to support it until I can't.
Once the time comes, someone else will take the lead of maintaining the library whoever that may be.
---
Q: **_"Do we need to update translations or subjects, etc??"_**
A: Regarding the subjects, as long as the library not being adopted there's little room for change in this regard. However the good news is that it basically requires zero effort besides updating the links on the intra and maybe changing the name referenced inside the pdf's. There is really nothing necessary to change besides minor things and to adapt these changes would literally just require at most a day of effort.
If you're really unusure, you as a pedago / campus can just choose to adopt it and mention to students that they can git clone it from here.
---
Q: **_"What if we want to ban some functions?"_**
A: Contact the maintainer or make a PR with the suggestion and watch it get merged or rejected. All it requires is communication... Any change is welcome if it so desired. You don't have to accept anything as is, that is the point of all of this. That if something needs to change, it can actually happen.
---
Q: **_"I don't like the fact that it uses GLFW for the window..."_**
A: `¯\_(ツ)_/¯` Well it's better than using the native windowing framework, at least it is portable, at least if something is wrong with it students can actually fix it by making a PR to the respective repository. Additionally GLFW is pretty standard for things like this, simply checkout any graphics demo and somewhere you will end up with GLFW under the hood quite often.

View File

@ -22,14 +22,14 @@ CFLAGS := -Wextra -Wall -Werror -Wunreachable-code -Ofast
LIBMLX := ./lib/MLX42
HEADERS := -I ./include -I $(LIBMLX)/include
LIBS := $(LIBMLX)/libmlx42.a -ldl -lglfw -pthread -lm
LIBS := $(LIBMLX)/build/libmlx42.a -ldl -lglfw -pthread -lm
SRCS := $(shell find ./src -iname "*.c")
OBJS := ${SRCS:.c=.o}
all: libmlx $(NAME)
libmlx:
@$(MAKE) -C $(LIBMLX)
@cmake $(LIBMLX) -B $(LIBMLX)/build && make -C $(LIBMLX)/build -j4
%.o: %.c
@$(CC) $(CFLAGS) -o $@ -c $< $(HEADERS) && printf "Compiling: $(notdir $<)"
@ -38,12 +38,11 @@ $(NAME): $(OBJS)
@$(CC) $(OBJS) $(LIBS) $(HEADERS) -o $(NAME)
clean:
@rm -f $(OBJS)
@$(MAKE) -C $(LIBMLX) clean
@rm -rf $(OBJS)
@rm -rf $(LIBMLX)/build
fclean: clean
@rm -f $(NAME)
@$(MAKE) -C $(LIBMLX) fclean
@rm -rf $(NAME)
re: clean all

View File

@ -12,8 +12,8 @@ Colors are commonly represented as `4-byte` integers. This 4-byte integer is a g
Channel | Description | RGBA representation
:------:|:-------------:|:-------------------:
`R` | Red Channel | `0xFF000000`
`G` | Green Channel | `0x00FF0000`
`B` | Blue Channel | `0x0000FF00`
`G` | Green Channel | `0x00FF0000`
`B` | Blue Channel | `0x0000FF00`
`A` | Alpha Channel | `0x000000FF`
Combining these four channel values into one will result in a non-transparent, white color.

View File

@ -8,7 +8,7 @@ See copyright and license notice in the root project for more information.
Hooks allow you to add your own functions to the main loop execution of the program, aka these functions get executed every frame.
They also serve to intercept certain keypresses such as scrolling or pressing enter.
Only one hook can be set at a time! You cannot attach/have multiple hooks for specialized hooks.
Only one hook can be set at a time! You cannot attach/have multiple specialized hooks.
You can however have multiple generic hooks.
## Specialized Hooks
@ -140,7 +140,7 @@ Generic hooks execute each frame and are useful for stuff that needs to be updat
* @param[in] mlx The MLX instance handle.
* @param[in] f The function.
* @param[in] param The parameter to pass onto the function.
* @returns Wether the hook was added successfuly.
* @returns Wether the hook was added successfully.
*/
bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param);
```
@ -207,7 +207,7 @@ void my_scrollhook(double xdelta, double ydelta, void* param)
else if (ydelta < 0)
puts("Down!");
// Can also detect a mousewheel that go along the X (e.g: MX Master 3)
// Can also detect a mousewheel that goes along the X (e.g: MX Master 3)
if (xdelta < 0)
puts("Sliiiide to the left!");
else if (xdelta > 0)

View File

@ -75,7 +75,7 @@ int32_t main(void)
mlx_loop(mlx);
// Optional, terminate will clean up any left overs, this is just to demonstrate.
// Optional, terminate will clean up any leftovers, this is just to demonstrate.
mlx_delete_image(mlx, img);
mlx_terminate(mlx);
return (EXIT_SUCCESS);
@ -98,7 +98,7 @@ If two instances are on the same z layer and are transparent, the transparency b
To prevent this by default any new instances put onto window will be on their own layer.
## Internals
A noticeable feature of MLX42 is that it partly takes care of the rendering for you, that is, after you created your image you just display it
A noticeable feature of MLX42 is that it partly takes care of the rendering for you, that is, after you've created your image you just display it
and after that feel free to modify it without having to re-put it onto the window. In short MLX takes care of updating your images at all times.
Internally this is done via a render queue, anytime the `mlx_image_to_window` function is used, a new entry is added to a linked list.

View File

@ -5,7 +5,7 @@ See copyright and license notice in the root project for more information.
# Input methods
MLX42 provides various ways of detecting input, you can read about all the available hooks on the hooks page.
MLX42 provides various ways of detecting input, you can read about all the available hooks on the [Hooks](./Hooks.md) page.
## Key Detection

View File

@ -22,7 +22,7 @@ uniform mat4 ProjMatrix;
void main()
{
gl_Position = ProjMatrix * vec4(aPos, 1.0);
TexCoord = aTexCoord;
TexCoord = aTexCoord;
}
```
@ -31,7 +31,7 @@ void main()
Shaders aren't really meant to be used by students but are more there for the convenience of developers. (though some advanced students might make some use of them)
# Compiliation
# Compilation
Shaders are converted into a `.c` appropriate format and then compiled into the library and referenced via a `extern` global variable appropriately named `vert_shader` & `frag_shader`. The reason this is done is to keep the final game/executable portable, that is being able to use it at any given location within a filesystem, while still being easy to work on the shaders instead of having to mess with it in the `.c` files directly.

View File

@ -73,7 +73,7 @@ int32_t main(void)
mlx_loop(mlx);
// Optional, terminate will clean up any left overs, this is just to demonstrate.
// Optional, terminate will clean up any leftovers, this is just to demonstrate.
mlx_delete_image(mlx, img);
mlx_delete_texture(texture);
mlx_terminate(mlx);

View File

@ -5,10 +5,10 @@ See copyright and license notice in the root project for more information.
# XPM42
XPM42 is a custom file format made for MLX42 to provide a easy to use and understand image file format to learn how
XPM42 is a custom file format made for MLX42 to provide an easy to use and understand image file format to learn how
images can be stored. The format is based on the actual [XPM3](https://en.wikipedia.org/wiki/X_PixMap) format.
A XPM file basically stores a look-up table inside of it to fetch which character corresponds to which color. Additionally in the
An XPM file basically stores a look-up table inside of it to fetch which character corresponds to which color. Additionally in the
header there is a character per pixel count, this is due to the limitation of the amount of characters. Each 'Pixel' in the XPM data can
be represented by multiple characters.
@ -34,7 +34,7 @@ The file format looks as follows:
## Inner workings
Reading a XPM42 does a whole bunch of stuff but in essence it reads the file header and inserts each color entry into a hash table for fast lookups of the color value, the hash used is FNV-1a. Why, because it's an easy to use hash and also my favourite. After the header is read and the color values are inserted into the table each line is then read and each character is processed and inserted into the pixel buffer of the XPM. There is no collision checking for the look-up table, so artefacts may be present.
Reading an XPM42 does a whole bunch of stuff but in essence it reads the file header and inserts each color entry into a hash table for fast lookups of the color value, the hash used is FNV-1a. Why, because it's an easy to use hash and also my favourite. After the header is read and the color values are inserted into the table each line is then read and each character is processed and inserted into the pixel buffer of the XPM. There is no collision checking for the lookup table, so artefacts may be present.
## Tools
@ -62,25 +62,25 @@ int32_t main(void)
// Start mlx
mlx_t* mlx = mlx_init(WIDTH, HEIGHT, "Test", true);
if (!mlx)
error();
error();
// Try to load the file
xpm_t* xpm = mlx_load_xpm42("./temp/42.xpm42");
if (!xpm)
error();
error();
// Convert texture to a displayable image
mlx_image_t* img = mlx_texture_to_image(mlx, &xpm->texture);
if (!img)
error();
error();
// Display the image
if (mlx_image_to_window(mlx, img, 0, 0) < 0)
error();
error();
mlx_loop(mlx);
// Optional, terminate will clean up any left overs, this is just to demonstrate.
// Optional, terminate will clean up any leftovers, this is just to demonstrate.
mlx_delete_image(mlx, img);
mlx_delete_xpm42(xpm);
mlx_terminate(mlx);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 348 KiB

BIN
mlx/docs/assets/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 MiB

View File

@ -31,6 +31,7 @@ displaying images from disk or creating a drawing surface to draw pixels on.
* [Basics](./Basics.md)
* [Colors](./Colors.md)
* [Functions](./Functions.md)
* [Hooks](./Hooks.md)
* [Images](./Images.md)
* [Input](./Input.md)
@ -58,7 +59,7 @@ OpenGL function pointers, compiling the shaders and more.
It returns a mlx_t* which is a structure containing the current window instance.
With this instance you can manipulate, hook onto and control what happens inside
your window instance. For example you would use it to send graphical orders such as
your window instance. For example you would use it to send graphical instructions such as
creating an image, which is used to display pixel data. You can also detect key
interactions such as checking if the W, A, S or D key is currently being pressed.
@ -66,7 +67,7 @@ interactions such as checking if the W, A, S or D key is currently being pressed
|-------------------|--------------------------------------------------------------|
| `mlx_init()` | Initialize and run a new window instance. |
| `mlx_loop()` | Keep the window open as long as a shutdown is not requested. |
| `mlx_terminate()` | Destroy and cleanup all images and mlx resources. |
| `mlx_terminate()` | Destroy and clean up all images and mlx resources. |
If mlx_init() fails to set up the connection to the graphical system, it will
return NULL, otherwise a non-null pointer is returned as a handle for the window.
@ -84,12 +85,23 @@ To do this, simply add the following arguments at the linking stage:
**NOTE: For some UNIX systems the flag for glfw might be with or without a 3 at the end.**
## Build options
When building MLX42 you can pass certain build options to cmake.
The options are passed as follows `cmake -DDEBUG=1 -DGLFW_FETCH=0`.
### Available options
* `DEBUG`: Enables assertion macros and compiles with -g in order for debugging with lldb.
* `GLFW_FETCH`: Fetches GLFW if it can't be found on the system at all, allows you to then install it with `sudo make install` under the `build/_deps` folder.
## Debugging
MLX was designed with ease of debugging in mind, therefore if the project is built with
**make DEBUG=1** it will keep in the assertion macros and notify you of any bad input
**cmake -DDEBUG=1** it will keep in the assertion macros and notify you of any bad input
given to functions. Additionally it comes with its own runtime error checking via
**mlx_errno** and **mlx_strerror** to properly identify what went wrong during the runtime
**mlx_errno** and **mlx_strerror** to properly identify what went wrong during the runtime
of the library.
## Notes
@ -102,7 +114,7 @@ it. That is, no proper way of handling multiple windows.
## F.A.Q
Q: **_"ItS NoT In ThE SuBjeCt!"_**
Q: **_"It'S NoT In ThE SuBjeCt!"_**
A: So what? Subjects can change and so if something is not working correctly it should be replaced. Sure you can argue this point but you can also be the reason that it CAN be in the subject instead. Have an open mind :)
@ -112,11 +124,11 @@ A: Officially, _no_. However, ask your head of studies first about using it, see
Q: **_"Is it faster?"_**
A: From my personal projects there was a considerable peformance gain, especially when compiled with `-Ofast`. Projects such as FDF could rotate their maps mindblowingly smooth and even larger maps with a width and height of 1000+ points moved/rotated relatively smooth, in short, yes.
A: From my personal projects there was a considerable performance gain, especially when compiled with `-Ofast`. Projects such as FDF could rotate their maps mindblowingly smooth and even larger maps with a width and height of 1000+ points moved/rotated relatively smooth, so in short, yes.
Q: **_"Can I just drag and drop it into my old project and just not do anything?"_**
A: Well, um uh, no ?? That's not how libraries work. Sure they target and do sort of the same thing but the functions each library provides are too different, even a little bit in terms of behavior. And no there is no easy way to convert from the "old" to the "new" it will be somewhat tedious work.
A: No. That's not how libraries work. Sure they target and do sort of the same thing but the functions each library provides are too different, even a little bit in terms of behavior. And no there is no easy way to convert from the "old" to the "new" it will be somewhat tedious work.
Q: **_"We should be able to deal with the fact that MiniLibX is not perfect, it is by design and makes us better programmers."_**

View File

@ -3,32 +3,254 @@
/* :::::::: */
/* MLX42.h :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/28 00:33:01 by W2Wizard #+# #+# */
/* Updated: 2022/08/10 13:00:48 by lde-la-h ######## odam.nl */
/* Created: 2021/12/28 02:29:06 by W2Wizard #+# #+# */
/* Updated: 2023/03/30 16:23:19 by ntamayo- ######## odam.nl */
/* */
/* ************************************************************************** */
/**
* A cross-platform OpenGL graphics library based on the idea on what MiniLibX
* provides. Just quite a bit better, in terms of code quality & performance.
*
* MLX42 is a cross-platform low level and simple cross-platform graphics
* library written in C and uses OpenGL and GLFW for it's underlying windowing
* and rendering system.
*
* As for the few void* present in some structs and functions and
* why MLX is split into two different headers, so to speak,
* is mainly for abstraction. Most users won't have a need for the inner
* workings of MLX (shaders, ...) and it also helps keep MLX nice and tidy.
* It's a much more up-to-date alternative to the miniLibX which has been
* extensively proven to be fragile, unmaintained, deprecated and just
* plain painfully bad to work with. Also it's code quality is dubious.
*
* Some structs contain potential void* which are to be ignored as they
* simply represent points of abstraction to the hidden internal header.
* This abstraction is crucial as the whole point of this lib so to hide
* all the bells and whistles in the "engine". Most user's have no need
* for the inner workings eitherway (shaders, vertex buffer, ...).
*/
#ifndef MLX42_H
# define MLX42_H
# include <stddef.h>
# include <stdint.h>
# include <stdbool.h>
# include "MLX42_Input.h"
# ifdef __cplusplus
extern "C" {
# endif
//= Types =//
/**
* The input key codes are copied straight from GLFW.
* Any new entries should have the exact same values as defined in the glfw3.h.
*/
/**
* A key action such as pressing or releasing a key.
*
* @param RELEASE Execute when the key is being released.
* @param PRESS Execute when the key is being pressed.
* @param REPEAT Execute when the key is being held down.
*/
typedef enum action
{
MLX_RELEASE = 0,
MLX_PRESS = 1,
MLX_REPEAT = 2,
} action_t;
/**
* Key modifiers, such as shift, control or alt.
* These keys are flags meaning you can combine them to detect
* key combinations such as CTRL + ALT so CTRL | ALT.
*
* @param SHIFT The shift key.
* @param CONTROL The control key.
* @param ALT The alt key.
* @param SUPERKEY The Superkey such as the Windows Key or Command.
* @param CAPSLOCK The capslock key.
* @param NUMLOCK The numlock key.
*/
typedef enum modifier_key
{
MLX_SHIFT = 0x0001,
MLX_CONTROL = 0x0002,
MLX_ALT = 0x0004,
MLX_SUPERKEY = 0x0008,
MLX_CAPSLOCK = 0x0010,
MLX_NUMLOCK = 0x0020,
} modifier_key_t;
/**
* The mouse button keycodes.
* @param LEFT The left mouse button.
* @param RIGHT The right mouse button.
* @param MIDDLE The middle mouse button, aka the Scrollwheel.
*/
typedef enum mouse_key
{
MLX_MOUSE_BUTTON_LEFT = 0,
MLX_MOUSE_BUTTON_RIGHT = 1,
MLX_MOUSE_BUTTON_MIDDLE = 2,
} mouse_key_t;
/**
* Various mouse/cursor states.
* @param NORMAL Simple visible default cursor.
* @param HIDDEN The cursor is not rendered but still functions.
* @param DISABLED The cursor is not rendered, nor is it functional.
*/
typedef enum mouse_mode
{
MLX_MOUSE_NORMAL = 0x00034001,
MLX_MOUSE_HIDDEN = 0x00034002,
MLX_MOUSE_DISABLED = 0x00034003,
} mouse_mode_t;
/**
* Various cursors that are standard.
* @param ARROW The regular arrow cursor.
* @param IBEAM The text input I-beam cursor shape.
* @param CROSSHAIR The crosshair shape cursor.
* @param HAND The hand shape cursor.
* @param HRESIZE The horizontal resize arrow shape.
* @param VRESIZE The vertical resize arrow shape.
*/
typedef enum cursor
{
MLX_CURSOR_ARROW = 0x00036001,
MLX_CURSOR_IBEAM = 0x00036002,
MLX_CURSOR_CROSSHAIR = 0x00036003,
MLX_CURSOR_HAND = 0x00036004,
MLX_CURSOR_HRESIZE = 0x00036005,
MLX_CURSOR_VRESIZE = 0x00036006,
} cursor_t;
/**
* All sorts of keyboard keycodes.
*
* KP = Keypad.
*/
typedef enum keys
{
MLX_KEY_SPACE = 32,
MLX_KEY_APOSTROPHE = 39,
MLX_KEY_COMMA = 44,
MLX_KEY_MINUS = 45,
MLX_KEY_PERIOD = 46,
MLX_KEY_SLASH = 47,
MLX_KEY_0 = 48,
MLX_KEY_1 = 49,
MLX_KEY_2 = 50,
MLX_KEY_3 = 51,
MLX_KEY_4 = 52,
MLX_KEY_5 = 53,
MLX_KEY_6 = 54,
MLX_KEY_7 = 55,
MLX_KEY_8 = 56,
MLX_KEY_9 = 57,
MLX_KEY_SEMICOLON = 59,
MLX_KEY_EQUAL = 61,
MLX_KEY_A = 65,
MLX_KEY_B = 66,
MLX_KEY_C = 67,
MLX_KEY_D = 68,
MLX_KEY_E = 69,
MLX_KEY_F = 70,
MLX_KEY_G = 71,
MLX_KEY_H = 72,
MLX_KEY_I = 73,
MLX_KEY_J = 74,
MLX_KEY_K = 75,
MLX_KEY_L = 76,
MLX_KEY_M = 77,
MLX_KEY_N = 78,
MLX_KEY_O = 79,
MLX_KEY_P = 80,
MLX_KEY_Q = 81,
MLX_KEY_R = 82,
MLX_KEY_S = 83,
MLX_KEY_T = 84,
MLX_KEY_U = 85,
MLX_KEY_V = 86,
MLX_KEY_W = 87,
MLX_KEY_X = 88,
MLX_KEY_Y = 89,
MLX_KEY_Z = 90,
MLX_KEY_LEFT_BRACKET = 91,
MLX_KEY_BACKSLASH = 92,
MLX_KEY_RIGHT_BRACKET = 93,
MLX_KEY_GRAVE_ACCENT = 96,
MLX_KEY_ESCAPE = 256,
MLX_KEY_ENTER = 257,
MLX_KEY_TAB = 258,
MLX_KEY_BACKSPACE = 259,
MLX_KEY_INSERT = 260,
MLX_KEY_DELETE = 261,
MLX_KEY_RIGHT = 262,
MLX_KEY_LEFT = 263,
MLX_KEY_DOWN = 264,
MLX_KEY_UP = 265,
MLX_KEY_PAGE_UP = 266,
MLX_KEY_PAGE_DOWN = 267,
MLX_KEY_HOME = 268,
MLX_KEY_END = 269,
MLX_KEY_CAPS_LOCK = 280,
MLX_KEY_SCROLL_LOCK = 281,
MLX_KEY_NUM_LOCK = 282,
MLX_KEY_PRINT_SCREEN = 283,
MLX_KEY_PAUSE = 284,
MLX_KEY_F1 = 290,
MLX_KEY_F2 = 291,
MLX_KEY_F3 = 292,
MLX_KEY_F4 = 293,
MLX_KEY_F5 = 294,
MLX_KEY_F6 = 295,
MLX_KEY_F7 = 296,
MLX_KEY_F8 = 297,
MLX_KEY_F9 = 298,
MLX_KEY_F10 = 299,
MLX_KEY_F11 = 300,
MLX_KEY_F12 = 301,
MLX_KEY_F13 = 302,
MLX_KEY_F14 = 303,
MLX_KEY_F15 = 304,
MLX_KEY_F16 = 305,
MLX_KEY_F17 = 306,
MLX_KEY_F18 = 307,
MLX_KEY_F19 = 308,
MLX_KEY_F20 = 309,
MLX_KEY_F21 = 310,
MLX_KEY_F22 = 311,
MLX_KEY_F23 = 312,
MLX_KEY_F24 = 313,
MLX_KEY_F25 = 314,
MLX_KEY_KP_0 = 320,
MLX_KEY_KP_1 = 321,
MLX_KEY_KP_2 = 322,
MLX_KEY_KP_3 = 323,
MLX_KEY_KP_4 = 324,
MLX_KEY_KP_5 = 325,
MLX_KEY_KP_6 = 326,
MLX_KEY_KP_7 = 327,
MLX_KEY_KP_8 = 328,
MLX_KEY_KP_9 = 329,
MLX_KEY_KP_DECIMAL = 330,
MLX_KEY_KP_DIVIDE = 331,
MLX_KEY_KP_MULTIPLY = 332,
MLX_KEY_KP_SUBTRACT = 333,
MLX_KEY_KP_ADD = 334,
MLX_KEY_KP_ENTER = 335,
MLX_KEY_KP_EQUAL = 336,
MLX_KEY_LEFT_SHIFT = 340,
MLX_KEY_LEFT_CONTROL = 341,
MLX_KEY_LEFT_ALT = 342,
MLX_KEY_LEFT_SUPER = 343,
MLX_KEY_RIGHT_SHIFT = 344,
MLX_KEY_RIGHT_CONTROL = 345,
MLX_KEY_RIGHT_ALT = 346,
MLX_KEY_RIGHT_SUPER = 347,
MLX_KEY_MENU = 348,
} keys_t;
/**
* Base object for disk loaded textures.
* It contains rudementary information about the texture.
@ -36,7 +258,7 @@ extern "C" {
* @param width The width of the texture.
* @param height The height of the texture.
* @param pixels The literal pixel data.
* @param bytes_per_pixel The amounst of bytes in a pixel, always 4.
* @param bytes_per_pixel The amount of bytes in a pixel, always 4.
*/
typedef struct mlx_texture
{
@ -74,7 +296,7 @@ typedef struct xpm
* @param x The x location.
* @param y The y location.
* @param z The z depth, controls if the image is on the fore or background.
* @param enabled If true, the instance is drawn else its not.
* @param enabled If true, the instance is drawn, else it's not.
*/
typedef struct mlx_instance
{
@ -86,14 +308,14 @@ typedef struct mlx_instance
/**
* Key function callback data.
* Data related the mlx_key_hook function
* Data related to the mlx_key_hook function
*
* @param key The key that was pressed.
* @param action The action that was done with the key.
* @param os_key The os_key is unique for every key, and will have a
* different value/keycode depending on the platform.
* They may be consistent on different platforms.
* @param modifier The modifier key that was pressed, 0 if none.
* @param modifier The modifier key that was pressed, 0 if no key was pressed.
*/
typedef struct mlx_key_data
{
@ -110,9 +332,9 @@ typedef struct mlx_key_data
* @param width The width of the image.
* @param height The height of the image.
* @param pixels The literal pixel data.
* @param instances An instance carries the X, Y, Z location data.
* @param instances An instance carrying the X, Y and Z location data.
* @param count The element count of the instances array.
* @param enabled If true the image is drawn onto the screen, else its not.
* @param enabled If true the image is drawn onto the screen, else it's not.
* @param context Abstracted OpenGL data.
*/
typedef struct mlx_image
@ -121,7 +343,7 @@ typedef struct mlx_image
const uint32_t height;
uint8_t* pixels;
mlx_instance_t* instances;
int32_t count;
size_t count;
bool enabled;
void* context;
} mlx_image_t;
@ -144,14 +366,14 @@ typedef struct mlx
double delta_time;
} mlx_t;
// The error codes used to idenfity the correct error message.
// The error codes used to identify the correct error message.
typedef enum mlx_errno
{
MLX_SUCCESS = 0, // No Errors
MLX_INVEXT, // File has an invalid extension
MLX_INVFILE, // File was invalid / does not exist.
MLX_INVPNG, // Something is wrong the given PNG file.
MLX_INVXPM, // Something is wrong the given XPM file.
MLX_INVPNG, // Something is wrong with the given PNG file.
MLX_INVXPM, // Something is wrong with the given XPM file.
MLX_INVPOS, // The specified X/Y positions are out of bounds.
MLX_INVDIM, // The specified W/H dimensions are out of bounds.
MLX_INVIMG, // The provided image is invalid, might indicate mismanagement of images.
@ -162,7 +384,7 @@ typedef enum mlx_errno
MLX_GLADFAIL, // OpenGL loader has failed.
MLX_GLFWFAIL, // GLFW failed to initialize.
MLX_WINFAIL, // Failed to create a window.
MLX_STRTOBIG, // The string is too big to be drawn.
MLX_STRTOOBIG, // The string is too big to be drawn.
MLX_ERRMAX, // Error count
} mlx_errno_t;
@ -174,7 +396,7 @@ extern mlx_errno_t mlx_errno;
// Set these values, if necessary, before calling `mlx_init` as they define the behaviour of MLX42.
typedef enum mlx_settings
{
MLX_STRETCH_IMAGE = 0, // Should images resize with the window as its being resized or not. Default: false
MLX_STRETCH_IMAGE = 0, // Should images resize with the window as it's being resized or not. Default: false
MLX_FULLSCREEN, // Should the window be in Fullscreen, note it will fullscreen at the given resolution. Default: false
MLX_MAXIMIZED, // Start the window in a maximized state, overwrites the fullscreen state if this is true. Default: false
MLX_DECORATED, // Have the window be decorated with a window bar. Default: true
@ -187,7 +409,7 @@ typedef enum mlx_settings
*
* @param[in] xdelta The mouse x delta.
* @param[in] ydelta The mouse y delta.
* @param[in] param Additional parameter to pass onto the function.
* @param[in] param Additional parameter to pass on to the function.
*/
typedef void (*mlx_scrollfunc)(double xdelta, double ydelta, void* param);
@ -196,17 +418,17 @@ typedef void (*mlx_scrollfunc)(double xdelta, double ydelta, void* param);
*
* @param[in] button The mouse button/key pressed.
* @param[in] action The mouse action that took place.
* @param[in] mods The modifier keys pressed during the mouse key.
* @param[in] param Additional parameter to pass onto the function.
* @param[in] mods The modifier keys pressed together with the mouse key.
* @param[in] param Additional parameter to pass on to the function.
*/
typedef void (*mlx_mousefunc)(mouse_key_t button, action_t action, modifier_key_t mods, void* param);
/**
* Callback function used to handle raw mouse movement.
*
* @param[in] xdelta The mouse x position.
* @param[in] ydelta The mouse y position.
* @param[in] param Additional parameter to pass onto the function.
* @param[in] xpos The mouse x position.
* @param[in] ypos The mouse y position.
* @param[in] param Additional parameter to pass on to the function.
*/
typedef void (*mlx_cursorfunc)(double xpos, double ypos, void* param);
@ -214,7 +436,7 @@ typedef void (*mlx_cursorfunc)(double xpos, double ypos, void* param);
* Callback function used to handle key presses.
*
* @param[in] keydata The callback data, contains info on key, action, ...
* @param[in] param Additional parameter to pass onto the function.
* @param[in] param Additional parameter to pass on to the function.
*/
typedef void (*mlx_keyfunc)(mlx_key_data_t keydata, void* param);
@ -226,7 +448,7 @@ typedef void (*mlx_keyfunc)(mlx_key_data_t keydata, void* param);
*
* @param[in] width The new width of the window.
* @param[in] height The new height of the window.
* @param[in] param Additional parameter to pass onto the function.
* @param[in] param Additional parameter to pass on to the function.
*/
typedef void (*mlx_resizefunc)(int32_t width, int32_t height, void* param);
@ -235,10 +457,19 @@ typedef void (*mlx_resizefunc)(int32_t width, int32_t height, void* param);
* the user attempts to close the window, for example by clicking the
* close widget in the title bar.
*
* @param[in] param Additional parameter to pass onto the function.
* @param[in] param Additional parameter to pass on to the function.
*/
typedef void (*mlx_closefunc)(void* param);
/**
* Typedef for a window cursor object, these eventually expand to
* the native cursor object, but are hidden from the user.
*
* Under GLFW they are named GLFWcursor and have a wrapper for each implementation.
* You can find the ACTUAL cursor in the following files at GLFW named under *_platform.h
*/
typedef void mlx_win_cursor_t;
//= Error Functions =//
/**
@ -252,7 +483,7 @@ const char* mlx_strerror(mlx_errno_t val);
//= Generic Functions =//
/**
* Initilizes a new MLX42 Instance.
* Initializes a new MLX42 Instance.
*
* @param[in] width The width of the window.
* @param[in] height The height of the window.
@ -267,7 +498,7 @@ mlx_t* mlx_init(int32_t width, int32_t height, const char* title, bool resize);
* Settings can manipulate the core behaviour of the engine.
*
* @param[in] setting The settings value, See mlx_settings_t type.
* @param[in] value Settings value to determine the state of the setting. Can be a boolean or a enum / macro.
* @param[in] value Settings value to determine the state of the setting. Can be a boolean or an enum / macro.
*/
void mlx_set_setting(mlx_settings_t setting, int32_t value);
@ -316,13 +547,13 @@ void mlx_terminate(mlx_t* mlx);
*/
double mlx_get_time(void);
//= Window/Monitor Functions
//= Window/Monitor Functions =//
/**
* This function brings the specified window to front and sets input focus.
*
* Do not use this function to steal focus from other applications unless
* you are certain that is what the user wants. Focus stealing can be
* you are certain that is what the user wants. Focus stealing can be
* extremely disruptive.
*
* @param[in] mlx The MLX instance handle.
@ -332,14 +563,14 @@ void mlx_focus(mlx_t* mlx);
/**
* Gets the size of the specified monitor.
*
* @param[in] index Normally 0, incase of multiple windows, can be specified
* @param[in] index Normally 0, in case of multiple windows, can be specified
* @param[in] width The width of the window.
* @param[in] height The height of the window.
*/
void mlx_get_monitor_size(int32_t index, int32_t* width, int32_t* height);
/**
* Sets the windows position.
* Sets the window's position.
*
* Do not use this function to move an already visible window unless you
* have very good reasons for doing so, as it will confuse and annoy the user.
@ -351,7 +582,7 @@ void mlx_get_monitor_size(int32_t index, int32_t* width, int32_t* height);
void mlx_set_window_pos(mlx_t* mlx, int32_t xpos, int32_t ypos);
/**
* Gets the windows position.
* Gets the window's position.
*
* @param[in] mlx The MLX instance handle.
* @param[out] xpos The x position.
@ -361,7 +592,7 @@ void mlx_get_window_pos(mlx_t* mlx, int32_t* xpos, int32_t* ypos);
/**
* Changes the window size to the newly specified values.
* Use this to update the the window width and heigth values in the mlx ptr.
* Use this to update the window width and height values in the mlx handle.
*
* @param[in] mlx The MLX instance handle.
* @param[in] new_width The new desired width.
@ -373,6 +604,9 @@ void mlx_set_window_size(mlx_t* mlx, int32_t new_width, int32_t new_height);
* Sets the size limits of the specified window.
* Will force the window to not be resizable past or below the given values.
*
* Pass -1 for no limit to any of the min/max parameters to ignore that boundary.
* For instance if you want a min window size but the max window size can be whatever.
*
* @param[in] mlx The MLX instance handle.
* @param[in] min_w The min width of the window.
* @param[in] max_w The max width of the window.
@ -418,7 +652,7 @@ bool mlx_is_mouse_down(mlx_t* mlx, mouse_key_t key);
*
* @param[in] mlx The MLX instance handle.
* @param[out] x The position.
* @param[out] x The position.
* @param[out] y The position.
*/
void mlx_get_mouse_pos(mlx_t* mlx, int32_t* x, int32_t* y);
@ -431,10 +665,7 @@ void mlx_get_mouse_pos(mlx_t* mlx, int32_t* x, int32_t* y);
void mlx_set_mouse_pos(mlx_t* mlx, int32_t x, int32_t y);
/**
* Defines the state for the cursor, which can be:
* - Normal
* - Hidden
* - Disabled
* Defines the state for the cursor.
*
* @param[in] mlx The MLX instance handle.
* @param[in] mode A specified mouse mode.
@ -442,12 +673,12 @@ void mlx_set_mouse_pos(mlx_t* mlx, int32_t x, int32_t y);
void mlx_set_cursor_mode(mlx_t* mlx, mouse_mode_t mode);
/**
* Retrieves the system standart cursor.
* Retrieves the system standard cursor.
*
* @param[in] type The standart cursor type to create.
* @param[in] type The standard cursor type to create.
* @return The cursor object or null on failure.
*/
void* mlx_create_std_cursor(cursor_t type);
mlx_win_cursor_t* mlx_create_std_cursor(cursor_t type);
/**
* Allows for the creation of custom cursors with a given texture.
@ -458,7 +689,14 @@ void* mlx_create_std_cursor(cursor_t type);
* @param[in] texture The texture to use as cursor.
* @returns The cursor object or null on failure.
*/
void* mlx_create_cursor(mlx_texture_t* texture);
mlx_win_cursor_t* mlx_create_cursor(mlx_texture_t* texture);
/**
* Destroys the given cursor object.
*
* @param[in] cursor The cursor object to destroy.
*/
void mlx_destroy_cursor(mlx_win_cursor_t* cursor);
/**
* Sets the current cursor to the given custom cursor.
@ -466,7 +704,7 @@ void* mlx_create_cursor(mlx_texture_t* texture);
* @param[in] mlx The MLX instance handle.
* @param[in] cursor The cursor object to display, if null default cursor is selected.
*/
void mlx_set_cursor(mlx_t* mlx, void* cursor);
void mlx_set_cursor(mlx_t* mlx, mlx_win_cursor_t* cursor);
//= Hooks =//
@ -491,7 +729,7 @@ void mlx_scroll_hook(mlx_t* mlx, mlx_scrollfunc func, void* param);
void mlx_mouse_hook(mlx_t* mlx, mlx_mousefunc func, void* param);
/**
* This function sets the cursor callback, which is called when a the
* This function sets the cursor callback, which is called when the
* mouse position changes. Position is relative to the window.
*
* @param[in] mlx The MLX instance handle.
@ -502,10 +740,10 @@ void mlx_cursor_hook(mlx_t* mlx, mlx_cursorfunc func, void* param);
/**
* This function sets the key callback, which is called when a key is pressed
* on the keyboard. Useful for single key press detection.
* on the keyboard. Useful for single keypress detection.
*
* @param[in] mlx The MLX instance handle.
* @param[in] func The key press callback function.
* @param[in] func The keypress callback function.
* @param[in] param An additional optional parameter.
*/
void mlx_key_hook(mlx_t* mlx, mlx_keyfunc func, void* param);
@ -536,15 +774,15 @@ void mlx_resize_hook(mlx_t* mlx, mlx_resizefunc func, void* param);
*
* @param[in] mlx The MLX instance handle.
* @param[in] f The function.
* @param[in] param The parameter to pass onto the function.
* @returns Wether the hook was added successfuly.
* @param[in] param The parameter to pass on to the function.
* @returns Whether or not the hook was added successfully.
*/
bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param);
//= Texture Functions =//
/**
* Decode/load a PNG file onto a buffer.
* Decode/load a PNG file into a buffer.
*
* @param[in] path Path to the PNG file.
* @return If successful the texture data is returned, else NULL.
@ -554,7 +792,7 @@ mlx_texture_t* mlx_load_png(const char* path);
/**
* Loads an XPM42 texture from the given file path.
*
* @param[in] path The file path to the XPM image.
* @param[in] path The file path to the XPM texture.
* @returns The XPM texture struct containing its information.
*/
xpm_t* mlx_load_xpm42(const char* path);
@ -585,31 +823,6 @@ void mlx_delete_xpm42(xpm_t* xpm);
*/
mlx_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture);
/**
* Given an X & Y coordinate and a Width and Height from a section of a
* texture a new image is created, useful for texture atlases.
*
* Basically a cropping tool.
*
* @param[in] mlx The MLX instance handle.
* @param[in] texture The texture to use to create the image from.
* @param[in] xy The X & Y location.
* @param[in] wh The Width & Height.
* @return mlx_image_t* The image created from the texture area.
*/
mlx_image_t* mlx_texture_area_to_image(mlx_t* mlx, mlx_texture_t* texture, uint32_t xy[2], uint32_t wh[2]);
/**
* Draws the texture on an already existing image.
*
* @param[in] image The image to draw on.
* @param[in] texture The texture to use to draw on the image.
* @param[in] x X position relative to the image.
* @param[in] y Y position relative to the image.
* @return In-case of any issues, false else true.
*/
bool mlx_draw_texture(mlx_image_t* image, mlx_texture_t* texture, uint32_t x, uint32_t y);
//= Image Functions =//
/**
@ -639,15 +852,15 @@ mlx_image_t* mlx_new_image(mlx_t* mlx, uint32_t width, uint32_t height);
* Draws a new instance of an image, it will then share the same
* pixel buffer as the image.
*
* NOTE: Keep in mind that the instance array gets reallocated, try to
* NOTE: Keep in mind that the instance array gets reallocated, try
* to store the return value to the instance!
* NOT the pointer! It will become invalid!
*
* WARNING: Try to display as few images onto the window as possible,
* drawing too many images will cause a loss in peformance!
* WARNING: Try to display as few images on the window as possible,
* drawing too many images will cause a loss in performance!
*
* @param[in] mlx The MLX instance handle.
* @param[in] img The image to draw onto the screen.
* @param[in] img The image to draw on the screen.
* @param[in] x The X position.
* @param[in] y The Y position.
* @return Index to the instance, or -1 on failure.
@ -668,24 +881,24 @@ int32_t mlx_image_to_window(mlx_t* mlx, mlx_image_t* img, int32_t x, int32_t y);
void mlx_delete_image(mlx_t* mlx, mlx_image_t* image);
/**
* Allows you to resize an image to a new size, the pixel buffer is re-allocated
* to fit & the previous data is copied over. New pixels are zeroed.
* Allows you to resize an image, a new pixel buffer is allocated
* to fit & the previous data is scaled to fit the new size.
*
* @param[in] img The image to resize.
* @param[in] nwidth The new width.
* @param[in] nheight The new height.
* @return True if image was resize or false on error.
* @return True if image was resized or false on error.
*/
bool mlx_resize_image(mlx_image_t* img, uint32_t nwidth, uint32_t nheight);
/**
* Sets the depth / Z axis value of an instance.
*
* NOTE: Keep in mind that images that are on the same Z layer, cut each other off.
* so if you don't see your image anymore make sure its not conflicting by being on
* NOTE: Keep in mind that images that are on the same Z layer cut each other off.
* so if you don't see your image anymore make sure it's not conflicting by being on
* the same layer as another image.
*
* @param[in] instance The instane on which to change the depth.
* @param[in] instance The instance on which to change the depth.
* @param[in] zdepth The new depth value.
*/
void mlx_set_instance_depth(mlx_instance_t* instance, int32_t zdepth);
@ -693,7 +906,7 @@ void mlx_set_instance_depth(mlx_instance_t* instance, int32_t zdepth);
//= String Functions =//
/**
* Draws a string onto an image and then outputs it onto the window.
* Draws a string on an image and then outputs it to the window.
*
* @param[in] mlx The MLX instance handle.
* @param[in] str The string to draw.

Binary file not shown.

View File

@ -1,231 +0,0 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* MLX42_Keys.h :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* +#+ */
/* Created: 2021/12/28 02:29:06 by W2Wizard #+# #+# */
/* Updated: 2022/03/02 16:48:27 by lde-la-h ######## odam.nl */
/* */
/* ************************************************************************** */
/**
* These are copied from GLFW.
*
* Any new entries should have the exact same values as defined
* over in the glfw3.h file.
*/
#ifndef MLX42_INPUT_H
# define MLX42_INPUT_H
/**
* A key action such as pressing or releasing a key.
*
* @param RELEASE Execute when the key is being released.
* @param PRESS Execute when the key is being pressed.
* @param REPEAT Execute when the key is being held down.
*/
typedef enum action
{
MLX_RELEASE = 0,
MLX_PRESS = 1,
MLX_REPEAT = 2,
} action_t;
/**
* Key modifiers, such as shift, control or alt.
* These keys are flags meaning you can combine them to detect
* key combinations such as CTRL + ALT so CTRL | ALT.
*
* @param SHIFT The shift key.
* @param CONTROL The control key.
* @param ALT The alt key.
* @param SUPERKEY The Superkey such as the Windows Key or Command.
* @param CAPSLOCK The capslock key.
* @param NUMLOCK The numlock key.
*/
typedef enum modifier_key
{
MLX_SHIFT = 0x0001,
MLX_CONTROL = 0x0002,
MLX_ALT = 0x0004,
MLX_SUPERKEY = 0x0008,
MLX_CAPSLOCK = 0x0010,
MLX_NUMLOCK = 0x0020,
} modifier_key_t;
/**
* The mouse button keycodes.
* @param LEFT The left mouse button.
* @param RIGHT The right mouse button.
* @param MIDDLE The middle mouse button, aka the Scrollwheel.
*/
typedef enum mouse_key
{
MLX_MOUSE_BUTTON_LEFT = 0,
MLX_MOUSE_BUTTON_RIGHT = 1,
MLX_MOUSE_BUTTON_MIDDLE = 2,
} mouse_key_t;
/**
* Various mouse/cursor states.
* @param NORMAL Simple visibile default cursor.
* @param HIDDEN The cursor is not rendered, still functions however.
* @param DISABLED The cursor is not rendered, nor is it functional.
*/
typedef enum mouse_mode
{
MLX_MOUSE_NORMAL = 0x00034001,
MLX_MOUSE_HIDDEN = 0x00034002,
MLX_MOUSE_DISABLED = 0x00034003,
} mouse_mode_t;
/**
* Various cursors that are standart.
* @param ARROW The regular arrow cursor.
* @param IBEAM The text input I-beam cursor shape.
* @param CROSSHAIR The crosshair shape cursor.
* @param HAND The hand shape cursos.
* @param HRESIZE The horizontal resize arrow shape.
* @param VRESIZE The vertical resize arrow shape.
*/
typedef enum cursor
{
MLX_CURSOR_ARROW = 0x00036001,
MLX_CURSOR_IBEAM = 0x00036002,
MLX_CURSOR_CROSSHAIR = 0x00036003,
MLX_CURSOR_HAND = 0x00036004,
MLX_CURSOR_HRESIZE = 0x00036005,
MLX_CURSOR_VRESIZE = 0x00036006,
} cursor_t;
/**
* All sorts of keyboard keycodes.
*
* KP = Keypad.
*/
typedef enum keys
{
MLX_KEY_SPACE = 32,
MLX_KEY_APOSTROPHE = 39,
MLX_KEY_COMMA = 44,
MLX_KEY_MINUS = 45,
MLX_KEY_PERIOD = 46,
MLX_KEY_SLASH = 47,
MLX_KEY_0 = 48,
MLX_KEY_1 = 49,
MLX_KEY_2 = 50,
MLX_KEY_3 = 51,
MLX_KEY_4 = 52,
MLX_KEY_5 = 53,
MLX_KEY_6 = 54,
MLX_KEY_7 = 55,
MLX_KEY_8 = 56,
MLX_KEY_9 = 57,
MLX_KEY_SEMICOLON = 59,
MLX_KEY_EQUAL = 61,
MLX_KEY_A = 65,
MLX_KEY_B = 66,
MLX_KEY_C = 67,
MLX_KEY_D = 68,
MLX_KEY_E = 69,
MLX_KEY_F = 70,
MLX_KEY_G = 71,
MLX_KEY_H = 72,
MLX_KEY_I = 73,
MLX_KEY_J = 74,
MLX_KEY_K = 75,
MLX_KEY_L = 76,
MLX_KEY_M = 77,
MLX_KEY_N = 78,
MLX_KEY_O = 79,
MLX_KEY_P = 80,
MLX_KEY_Q = 81,
MLX_KEY_R = 82,
MLX_KEY_S = 83,
MLX_KEY_T = 84,
MLX_KEY_U = 85,
MLX_KEY_V = 86,
MLX_KEY_W = 87,
MLX_KEY_X = 88,
MLX_KEY_Y = 89,
MLX_KEY_Z = 90,
MLX_KEY_LEFT_BRACKET = 91,
MLX_KEY_BACKSLASH = 92,
MLX_KEY_RIGHT_BRACKET = 93,
MLX_KEY_GRAVE_ACCENT = 96,
MLX_KEY_ESCAPE = 256,
MLX_KEY_ENTER = 257,
MLX_KEY_TAB = 258,
MLX_KEY_BACKSPACE = 259,
MLX_KEY_INSERT = 260,
MLX_KEY_DELETE = 261,
MLX_KEY_RIGHT = 262,
MLX_KEY_LEFT = 263,
MLX_KEY_DOWN = 264,
MLX_KEY_UP = 265,
MLX_KEY_PAGE_UP = 266,
MLX_KEY_PAGE_DOWN = 267,
MLX_KEY_HOME = 268,
MLX_KEY_END = 269,
MLX_KEY_CAPS_LOCK = 280,
MLX_KEY_SCROLL_LOCK = 281,
MLX_KEY_NUM_LOCK = 282,
MLX_KEY_PRINT_SCREEN = 283,
MLX_KEY_PAUSE = 284,
MLX_KEY_F1 = 290,
MLX_KEY_F2 = 291,
MLX_KEY_F3 = 292,
MLX_KEY_F4 = 293,
MLX_KEY_F5 = 294,
MLX_KEY_F6 = 295,
MLX_KEY_F7 = 296,
MLX_KEY_F8 = 297,
MLX_KEY_F9 = 298,
MLX_KEY_F10 = 299,
MLX_KEY_F11 = 300,
MLX_KEY_F12 = 301,
MLX_KEY_F13 = 302,
MLX_KEY_F14 = 303,
MLX_KEY_F15 = 304,
MLX_KEY_F16 = 305,
MLX_KEY_F17 = 306,
MLX_KEY_F18 = 307,
MLX_KEY_F19 = 308,
MLX_KEY_F20 = 309,
MLX_KEY_F21 = 310,
MLX_KEY_F22 = 311,
MLX_KEY_F23 = 312,
MLX_KEY_F24 = 313,
MLX_KEY_F25 = 314,
MLX_KEY_KP_0 = 320,
MLX_KEY_KP_1 = 321,
MLX_KEY_KP_2 = 322,
MLX_KEY_KP_3 = 323,
MLX_KEY_KP_4 = 324,
MLX_KEY_KP_5 = 325,
MLX_KEY_KP_6 = 326,
MLX_KEY_KP_7 = 327,
MLX_KEY_KP_8 = 328,
MLX_KEY_KP_9 = 329,
MLX_KEY_KP_DECIMAL = 330,
MLX_KEY_KP_DIVIDE = 331,
MLX_KEY_KP_MULTIPLY = 332,
MLX_KEY_KP_SUBTRACT = 333,
MLX_KEY_KP_ADD = 334,
MLX_KEY_KP_ENTER = 335,
MLX_KEY_KP_EQUAL = 336,
MLX_KEY_LEFT_SHIFT = 340,
MLX_KEY_LEFT_CONTROL = 341,
MLX_KEY_LEFT_ALT = 342,
MLX_KEY_LEFT_SUPER = 343,
MLX_KEY_RIGHT_SHIFT = 344,
MLX_KEY_RIGHT_CONTROL = 345,
MLX_KEY_RIGHT_ALT = 346,
MLX_KEY_RIGHT_SUPER = 347,
MLX_KEY_MENU = 348,
} keys_t;
#endif

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* MLX42_Int.h :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/27 23:55:34 by W2Wizard #+# #+# */
/* Updated: 2022/07/21 10:46:43 by sbos ######## odam.nl */
@ -29,11 +29,6 @@
# else
# include <limits.h>
# endif
# if defined(_WIN32)
# include <windows.h>
# else
# include <err.h>
# endif
# include <ctype.h> /* isspace, isprint, ... */
# include <string.h> /* strlen, memmove, ... */
# include <stdarg.h> /* va_arg, va_end, ... */
@ -52,7 +47,7 @@
/**
* The shader code is extracted from the shader files
* and converted into a .c file as a single string at
* and converted to a .c file as a single string at
* compile time. This keeps shader files external but
* still integrated into the program letting you use
* the executable anywhere without having to take the
@ -98,7 +93,7 @@ typedef struct mlx_list
/**
* There are 2 types of hooks, special and generics.
*
* Specials: Are specific callback functions to a specific action
* Specials: Specials are specific callback functions to a specific action
* such as window resizing or key presses. These are attached to the
* callbacks of glfw. In case MLX itself needs the callback we call
* the specials in that callback since there can only ever be a single
@ -106,13 +101,13 @@ typedef struct mlx_list
*
* Generics: Generics are MLX42 specific hooks and can have multiple
* hooks at the same time, these are executed every frame and can be
* used as an alternative for key presses or animations for instance.
* used as an alternative for keypresses or animations for instance.
*
* NOTE: Hooks could be achieved with va_args to have any amount
* of args sized functor but we can't/don't want to let the user
* deal with va_args and having to look up what args are what, etc...
*
* We want to keep it straight forward with functors already describing
* We want to keep it straightforward with functors already describing
* what params they have.
*/
@ -160,13 +155,13 @@ typedef struct mlx_hook
//= Rendering =//
/**
* For rendering we need to store most of OpenGLs stuff
* For rendering we need to store most of OpenGL's stuff
* such as the vertex array object, vertex buffer object &
* the shader program. As well as hooks and the zdepth level.
* the shader program as well as hooks and the zdepth level.
*
* Additionally we represent draw calls with a linked list
* queue that point to the image and the index of which instance.
* Again, instances only carry xyz data, so coupled with the image it
* queue that points to the image and the index of its instance.
* Again, instances only carry XYZ data, so coupled with the image it
* lets us know where to draw a copy of the image.
*
* Texture contexts are kept in a struct alongside the capacity
@ -180,8 +175,8 @@ typedef struct mlx_ctx
GLuint vbo;
GLuint shaderprogram;
uint32_t initialWidth;
uint32_t initialHeight;
int32_t initialWidth;
int32_t initialHeight;
mlx_list_t* hooks;
mlx_list_t* images;
@ -244,7 +239,7 @@ bool mlx_freen(int32_t count, ...);
//= OpenGL Functions =//
void mlx_update_matrix(const mlx_t* mlx, int32_t width, int32_t height);
void mlx_update_matrix(const mlx_t* mlx);
void mlx_draw_instance(mlx_ctx_t* mlx, mlx_image_t* img, mlx_instance_t* instance);
void mlx_flush_batch(mlx_ctx_t* mlx);

View File

@ -1,7 +1,7 @@
/*
LodePNG version 20220717
LodePNG version 20230410
Copyright (c) 2005-2022 Lode Vandevenne
Copyright (c) 2005-2023 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -92,7 +92,10 @@ or comment out LODEPNG_COMPILE_ALLOCATORS below*/
#endif
/*Disable built-in CRC function, in that case a custom implementation of
lodepng_crc32 must be defined externally so that it can be linked in.*/
lodepng_crc32 must be defined externally so that it can be linked in.
The default built-in CRC code comes with 8KB of lookup tables, so for memory constrained environment you may want it
disabled and provide a much smaller implementation externally as said above. You can find such an example implementation
in a comment in the lodepng.c(pp) file in the 'else' case of the searchable LODEPNG_COMPILE_CRC section.*/
#ifndef LODEPNG_NO_COMPILE_CRC
/*pass -DLODEPNG_NO_COMPILE_CRC to the compiler to disable the built-in one,
or comment out LODEPNG_COMPILE_CRC below*/
@ -764,7 +767,7 @@ void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings);
typedef enum LodePNGFilterStrategy {
/*every filter at zero*/
LFS_ZERO = 0,
/*every filter at 1, 2, 3 or 4 (paeth), unlike LFS_ZERO not a good choice, but for testing*/
/*every filter at 1, 2, 3 or 4 (path), unlike LFS_ZERO not a good choice, but for testing*/
LFS_ONE = 1,
LFS_TWO = 2,
LFS_THREE = 3,
@ -832,7 +835,7 @@ typedef struct LodePNGEncoderSettings {
const unsigned char* predefined_filters;
/*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette).
If colortype is 3, PLTE is always created. If color type is explicitely set
If colortype is 3, PLTE is always created. If color type is explicitly set
to a grayscale type (1 or 4), this is not done and is ignored. If enabling this,
a palette must be present in the info_png.
NOTE: enabling this may worsen compression if auto_convert is used to choose
@ -1871,7 +1874,7 @@ state.decoder.remember_unknown_chunks: whether to read in unknown chunks
state.info_raw.colortype: desired color type for decoded image
state.info_raw.bitdepth: desired bit depth for decoded image
state.info_raw....: more color settings, see struct LodePNGColorMode
state.info_png....: no settings for decoder but ouput, see struct LodePNGInfo
state.info_png....: no settings for decoder but output, see struct LodePNGInfo
For encoding:
@ -1909,6 +1912,7 @@ symbol.
Not all changes are listed here, the commit history in github lists more:
https://github.com/lvandeve/lodepng
*) 10 apr 2023: faster CRC32 implementation, but with larger lookup table.
*) 13 jun 2022: added support for the sBIT chunk.
*) 09 jan 2022: minor decoder speed improvements.
*) 27 jun 2021: added warnings that file reading/writing functions don't support

View File

@ -1,7 +1,7 @@
/*
LodePNG version 20220717
LodePNG version 20230410
Copyright (c) 2005-2022 Lode Vandevenne
Copyright (c) 2005-2023 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -44,7 +44,7 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for
#pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/
#endif /*_MSC_VER */
const char* LODEPNG_VERSION_STRING = "20220717";
const char* LODEPNG_VERSION_STRING = "20230410";
/*
This source file is divided into the following large parts. The code sections
@ -140,7 +140,6 @@ static size_t lodepng_strlen(const char* a) {
#define LODEPNG_MAX(a, b) (((a) > (b)) ? (a) : (b))
#define LODEPNG_MIN(a, b) (((a) < (b)) ? (a) : (b))
#define LODEPNG_ABS(x) ((x) < 0 ? -(x) : (x))
#if defined(LODEPNG_COMPILE_PNG) || defined(LODEPNG_COMPILE_DECODER)
/* Safely check if adding two integers will overflow (no undefined
@ -1368,7 +1367,7 @@ static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader,
/*read the literal data: LEN bytes are now stored in the out buffer*/
if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/
/*out->data can be NULL (when LEN is zero), and arithmetics on NULL ptr is undefined*/
/*out->data can be NULL (when LEN is zero), and arithmetic on NULL ptr is undefined*/
if (LEN) {
lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
bytepos += LEN;
@ -2374,54 +2373,328 @@ const LodePNGDecompressSettings lodepng_default_decompress_settings = {0, 0, 0,
#ifdef LODEPNG_COMPILE_CRC
/* CRC polynomial: 0xedb88320 */
static unsigned lodepng_crc32_table[256] = {
0u, 1996959894u, 3993919788u, 2567524794u, 124634137u, 1886057615u, 3915621685u, 2657392035u,
249268274u, 2044508324u, 3772115230u, 2547177864u, 162941995u, 2125561021u, 3887607047u, 2428444049u,
498536548u, 1789927666u, 4089016648u, 2227061214u, 450548861u, 1843258603u, 4107580753u, 2211677639u,
325883990u, 1684777152u, 4251122042u, 2321926636u, 335633487u, 1661365465u, 4195302755u, 2366115317u,
997073096u, 1281953886u, 3579855332u, 2724688242u, 1006888145u, 1258607687u, 3524101629u, 2768942443u,
901097722u, 1119000684u, 3686517206u, 2898065728u, 853044451u, 1172266101u, 3705015759u, 2882616665u,
651767980u, 1373503546u, 3369554304u, 3218104598u, 565507253u, 1454621731u, 3485111705u, 3099436303u,
671266974u, 1594198024u, 3322730930u, 2970347812u, 795835527u, 1483230225u, 3244367275u, 3060149565u,
1994146192u, 31158534u, 2563907772u, 4023717930u, 1907459465u, 112637215u, 2680153253u, 3904427059u,
2013776290u, 251722036u, 2517215374u, 3775830040u, 2137656763u, 141376813u, 2439277719u, 3865271297u,
1802195444u, 476864866u, 2238001368u, 4066508878u, 1812370925u, 453092731u, 2181625025u, 4111451223u,
1706088902u, 314042704u, 2344532202u, 4240017532u, 1658658271u, 366619977u, 2362670323u, 4224994405u,
1303535960u, 984961486u, 2747007092u, 3569037538u, 1256170817u, 1037604311u, 2765210733u, 3554079995u,
1131014506u, 879679996u, 2909243462u, 3663771856u, 1141124467u, 855842277u, 2852801631u, 3708648649u,
1342533948u, 654459306u, 3188396048u, 3373015174u, 1466479909u, 544179635u, 3110523913u, 3462522015u,
1591671054u, 702138776u, 2966460450u, 3352799412u, 1504918807u, 783551873u, 3082640443u, 3233442989u,
3988292384u, 2596254646u, 62317068u, 1957810842u, 3939845945u, 2647816111u, 81470997u, 1943803523u,
3814918930u, 2489596804u, 225274430u, 2053790376u, 3826175755u, 2466906013u, 167816743u, 2097651377u,
4027552580u, 2265490386u, 503444072u, 1762050814u, 4150417245u, 2154129355u, 426522225u, 1852507879u,
4275313526u, 2312317920u, 282753626u, 1742555852u, 4189708143u, 2394877945u, 397917763u, 1622183637u,
3604390888u, 2714866558u, 953729732u, 1340076626u, 3518719985u, 2797360999u, 1068828381u, 1219638859u,
3624741850u, 2936675148u, 906185462u, 1090812512u, 3747672003u, 2825379669u, 829329135u, 1181335161u,
3412177804u, 3160834842u, 628085408u, 1382605366u, 3423369109u, 3138078467u, 570562233u, 1426400815u,
3317316542u, 2998733608u, 733239954u, 1555261956u, 3268935591u, 3050360625u, 752459403u, 1541320221u,
2607071920u, 3965973030u, 1969922972u, 40735498u, 2617837225u, 3943577151u, 1913087877u, 83908371u,
2512341634u, 3803740692u, 2075208622u, 213261112u, 2463272603u, 3855990285u, 2094854071u, 198958881u,
2262029012u, 4057260610u, 1759359992u, 534414190u, 2176718541u, 4139329115u, 1873836001u, 414664567u,
2282248934u, 4279200368u, 1711684554u, 285281116u, 2405801727u, 4167216745u, 1634467795u, 376229701u,
2685067896u, 3608007406u, 1308918612u, 956543938u, 2808555105u, 3495958263u, 1231636301u, 1047427035u,
2932959818u, 3654703836u, 1088359270u, 936918000u, 2847714899u, 3736837829u, 1202900863u, 817233897u,
3183342108u, 3401237130u, 1404277552u, 615818150u, 3134207493u, 3453421203u, 1423857449u, 601450431u,
3009837614u, 3294710456u, 1567103746u, 711928724u, 3020668471u, 3272380065u, 1510334235u, 755167117u
static const unsigned lodepng_crc32_table0[256] = {
0x00000000u, 0x77073096u, 0xee0e612cu, 0x990951bau, 0x076dc419u, 0x706af48fu, 0xe963a535u, 0x9e6495a3u,
0x0edb8832u, 0x79dcb8a4u, 0xe0d5e91eu, 0x97d2d988u, 0x09b64c2bu, 0x7eb17cbdu, 0xe7b82d07u, 0x90bf1d91u,
0x1db71064u, 0x6ab020f2u, 0xf3b97148u, 0x84be41deu, 0x1adad47du, 0x6ddde4ebu, 0xf4d4b551u, 0x83d385c7u,
0x136c9856u, 0x646ba8c0u, 0xfd62f97au, 0x8a65c9ecu, 0x14015c4fu, 0x63066cd9u, 0xfa0f3d63u, 0x8d080df5u,
0x3b6e20c8u, 0x4c69105eu, 0xd56041e4u, 0xa2677172u, 0x3c03e4d1u, 0x4b04d447u, 0xd20d85fdu, 0xa50ab56bu,
0x35b5a8fau, 0x42b2986cu, 0xdbbbc9d6u, 0xacbcf940u, 0x32d86ce3u, 0x45df5c75u, 0xdcd60dcfu, 0xabd13d59u,
0x26d930acu, 0x51de003au, 0xc8d75180u, 0xbfd06116u, 0x21b4f4b5u, 0x56b3c423u, 0xcfba9599u, 0xb8bda50fu,
0x2802b89eu, 0x5f058808u, 0xc60cd9b2u, 0xb10be924u, 0x2f6f7c87u, 0x58684c11u, 0xc1611dabu, 0xb6662d3du,
0x76dc4190u, 0x01db7106u, 0x98d220bcu, 0xefd5102au, 0x71b18589u, 0x06b6b51fu, 0x9fbfe4a5u, 0xe8b8d433u,
0x7807c9a2u, 0x0f00f934u, 0x9609a88eu, 0xe10e9818u, 0x7f6a0dbbu, 0x086d3d2du, 0x91646c97u, 0xe6635c01u,
0x6b6b51f4u, 0x1c6c6162u, 0x856530d8u, 0xf262004eu, 0x6c0695edu, 0x1b01a57bu, 0x8208f4c1u, 0xf50fc457u,
0x65b0d9c6u, 0x12b7e950u, 0x8bbeb8eau, 0xfcb9887cu, 0x62dd1ddfu, 0x15da2d49u, 0x8cd37cf3u, 0xfbd44c65u,
0x4db26158u, 0x3ab551ceu, 0xa3bc0074u, 0xd4bb30e2u, 0x4adfa541u, 0x3dd895d7u, 0xa4d1c46du, 0xd3d6f4fbu,
0x4369e96au, 0x346ed9fcu, 0xad678846u, 0xda60b8d0u, 0x44042d73u, 0x33031de5u, 0xaa0a4c5fu, 0xdd0d7cc9u,
0x5005713cu, 0x270241aau, 0xbe0b1010u, 0xc90c2086u, 0x5768b525u, 0x206f85b3u, 0xb966d409u, 0xce61e49fu,
0x5edef90eu, 0x29d9c998u, 0xb0d09822u, 0xc7d7a8b4u, 0x59b33d17u, 0x2eb40d81u, 0xb7bd5c3bu, 0xc0ba6cadu,
0xedb88320u, 0x9abfb3b6u, 0x03b6e20cu, 0x74b1d29au, 0xead54739u, 0x9dd277afu, 0x04db2615u, 0x73dc1683u,
0xe3630b12u, 0x94643b84u, 0x0d6d6a3eu, 0x7a6a5aa8u, 0xe40ecf0bu, 0x9309ff9du, 0x0a00ae27u, 0x7d079eb1u,
0xf00f9344u, 0x8708a3d2u, 0x1e01f268u, 0x6906c2feu, 0xf762575du, 0x806567cbu, 0x196c3671u, 0x6e6b06e7u,
0xfed41b76u, 0x89d32be0u, 0x10da7a5au, 0x67dd4accu, 0xf9b9df6fu, 0x8ebeeff9u, 0x17b7be43u, 0x60b08ed5u,
0xd6d6a3e8u, 0xa1d1937eu, 0x38d8c2c4u, 0x4fdff252u, 0xd1bb67f1u, 0xa6bc5767u, 0x3fb506ddu, 0x48b2364bu,
0xd80d2bdau, 0xaf0a1b4cu, 0x36034af6u, 0x41047a60u, 0xdf60efc3u, 0xa867df55u, 0x316e8eefu, 0x4669be79u,
0xcb61b38cu, 0xbc66831au, 0x256fd2a0u, 0x5268e236u, 0xcc0c7795u, 0xbb0b4703u, 0x220216b9u, 0x5505262fu,
0xc5ba3bbeu, 0xb2bd0b28u, 0x2bb45a92u, 0x5cb36a04u, 0xc2d7ffa7u, 0xb5d0cf31u, 0x2cd99e8bu, 0x5bdeae1du,
0x9b64c2b0u, 0xec63f226u, 0x756aa39cu, 0x026d930au, 0x9c0906a9u, 0xeb0e363fu, 0x72076785u, 0x05005713u,
0x95bf4a82u, 0xe2b87a14u, 0x7bb12baeu, 0x0cb61b38u, 0x92d28e9bu, 0xe5d5be0du, 0x7cdcefb7u, 0x0bdbdf21u,
0x86d3d2d4u, 0xf1d4e242u, 0x68ddb3f8u, 0x1fda836eu, 0x81be16cdu, 0xf6b9265bu, 0x6fb077e1u, 0x18b74777u,
0x88085ae6u, 0xff0f6a70u, 0x66063bcau, 0x11010b5cu, 0x8f659effu, 0xf862ae69u, 0x616bffd3u, 0x166ccf45u,
0xa00ae278u, 0xd70dd2eeu, 0x4e048354u, 0x3903b3c2u, 0xa7672661u, 0xd06016f7u, 0x4969474du, 0x3e6e77dbu,
0xaed16a4au, 0xd9d65adcu, 0x40df0b66u, 0x37d83bf0u, 0xa9bcae53u, 0xdebb9ec5u, 0x47b2cf7fu, 0x30b5ffe9u,
0xbdbdf21cu, 0xcabac28au, 0x53b39330u, 0x24b4a3a6u, 0xbad03605u, 0xcdd70693u, 0x54de5729u, 0x23d967bfu,
0xb3667a2eu, 0xc4614ab8u, 0x5d681b02u, 0x2a6f2b94u, 0xb40bbe37u, 0xc30c8ea1u, 0x5a05df1bu, 0x2d02ef8du
};
/*Return the CRC of the bytes buf[0..len-1].*/
static const unsigned lodepng_crc32_table1[256] = {
0x00000000u, 0x191b3141u, 0x32366282u, 0x2b2d53c3u, 0x646cc504u, 0x7d77f445u, 0x565aa786u, 0x4f4196c7u,
0xc8d98a08u, 0xd1c2bb49u, 0xfaefe88au, 0xe3f4d9cbu, 0xacb54f0cu, 0xb5ae7e4du, 0x9e832d8eu, 0x87981ccfu,
0x4ac21251u, 0x53d92310u, 0x78f470d3u, 0x61ef4192u, 0x2eaed755u, 0x37b5e614u, 0x1c98b5d7u, 0x05838496u,
0x821b9859u, 0x9b00a918u, 0xb02dfadbu, 0xa936cb9au, 0xe6775d5du, 0xff6c6c1cu, 0xd4413fdfu, 0xcd5a0e9eu,
0x958424a2u, 0x8c9f15e3u, 0xa7b24620u, 0xbea97761u, 0xf1e8e1a6u, 0xe8f3d0e7u, 0xc3de8324u, 0xdac5b265u,
0x5d5daeaau, 0x44469febu, 0x6f6bcc28u, 0x7670fd69u, 0x39316baeu, 0x202a5aefu, 0x0b07092cu, 0x121c386du,
0xdf4636f3u, 0xc65d07b2u, 0xed705471u, 0xf46b6530u, 0xbb2af3f7u, 0xa231c2b6u, 0x891c9175u, 0x9007a034u,
0x179fbcfbu, 0x0e848dbau, 0x25a9de79u, 0x3cb2ef38u, 0x73f379ffu, 0x6ae848beu, 0x41c51b7du, 0x58de2a3cu,
0xf0794f05u, 0xe9627e44u, 0xc24f2d87u, 0xdb541cc6u, 0x94158a01u, 0x8d0ebb40u, 0xa623e883u, 0xbf38d9c2u,
0x38a0c50du, 0x21bbf44cu, 0x0a96a78fu, 0x138d96ceu, 0x5ccc0009u, 0x45d73148u, 0x6efa628bu, 0x77e153cau,
0xbabb5d54u, 0xa3a06c15u, 0x888d3fd6u, 0x91960e97u, 0xded79850u, 0xc7cca911u, 0xece1fad2u, 0xf5facb93u,
0x7262d75cu, 0x6b79e61du, 0x4054b5deu, 0x594f849fu, 0x160e1258u, 0x0f152319u, 0x243870dau, 0x3d23419bu,
0x65fd6ba7u, 0x7ce65ae6u, 0x57cb0925u, 0x4ed03864u, 0x0191aea3u, 0x188a9fe2u, 0x33a7cc21u, 0x2abcfd60u,
0xad24e1afu, 0xb43fd0eeu, 0x9f12832du, 0x8609b26cu, 0xc94824abu, 0xd05315eau, 0xfb7e4629u, 0xe2657768u,
0x2f3f79f6u, 0x362448b7u, 0x1d091b74u, 0x04122a35u, 0x4b53bcf2u, 0x52488db3u, 0x7965de70u, 0x607eef31u,
0xe7e6f3feu, 0xfefdc2bfu, 0xd5d0917cu, 0xcccba03du, 0x838a36fau, 0x9a9107bbu, 0xb1bc5478u, 0xa8a76539u,
0x3b83984bu, 0x2298a90au, 0x09b5fac9u, 0x10aecb88u, 0x5fef5d4fu, 0x46f46c0eu, 0x6dd93fcdu, 0x74c20e8cu,
0xf35a1243u, 0xea412302u, 0xc16c70c1u, 0xd8774180u, 0x9736d747u, 0x8e2de606u, 0xa500b5c5u, 0xbc1b8484u,
0x71418a1au, 0x685abb5bu, 0x4377e898u, 0x5a6cd9d9u, 0x152d4f1eu, 0x0c367e5fu, 0x271b2d9cu, 0x3e001cddu,
0xb9980012u, 0xa0833153u, 0x8bae6290u, 0x92b553d1u, 0xddf4c516u, 0xc4eff457u, 0xefc2a794u, 0xf6d996d5u,
0xae07bce9u, 0xb71c8da8u, 0x9c31de6bu, 0x852aef2au, 0xca6b79edu, 0xd37048acu, 0xf85d1b6fu, 0xe1462a2eu,
0x66de36e1u, 0x7fc507a0u, 0x54e85463u, 0x4df36522u, 0x02b2f3e5u, 0x1ba9c2a4u, 0x30849167u, 0x299fa026u,
0xe4c5aeb8u, 0xfdde9ff9u, 0xd6f3cc3au, 0xcfe8fd7bu, 0x80a96bbcu, 0x99b25afdu, 0xb29f093eu, 0xab84387fu,
0x2c1c24b0u, 0x350715f1u, 0x1e2a4632u, 0x07317773u, 0x4870e1b4u, 0x516bd0f5u, 0x7a468336u, 0x635db277u,
0xcbfad74eu, 0xd2e1e60fu, 0xf9ccb5ccu, 0xe0d7848du, 0xaf96124au, 0xb68d230bu, 0x9da070c8u, 0x84bb4189u,
0x03235d46u, 0x1a386c07u, 0x31153fc4u, 0x280e0e85u, 0x674f9842u, 0x7e54a903u, 0x5579fac0u, 0x4c62cb81u,
0x8138c51fu, 0x9823f45eu, 0xb30ea79du, 0xaa1596dcu, 0xe554001bu, 0xfc4f315au, 0xd7626299u, 0xce7953d8u,
0x49e14f17u, 0x50fa7e56u, 0x7bd72d95u, 0x62cc1cd4u, 0x2d8d8a13u, 0x3496bb52u, 0x1fbbe891u, 0x06a0d9d0u,
0x5e7ef3ecu, 0x4765c2adu, 0x6c48916eu, 0x7553a02fu, 0x3a1236e8u, 0x230907a9u, 0x0824546au, 0x113f652bu,
0x96a779e4u, 0x8fbc48a5u, 0xa4911b66u, 0xbd8a2a27u, 0xf2cbbce0u, 0xebd08da1u, 0xc0fdde62u, 0xd9e6ef23u,
0x14bce1bdu, 0x0da7d0fcu, 0x268a833fu, 0x3f91b27eu, 0x70d024b9u, 0x69cb15f8u, 0x42e6463bu, 0x5bfd777au,
0xdc656bb5u, 0xc57e5af4u, 0xee530937u, 0xf7483876u, 0xb809aeb1u, 0xa1129ff0u, 0x8a3fcc33u, 0x9324fd72u
};
static const unsigned lodepng_crc32_table2[256] = {
0x00000000u, 0x01c26a37u, 0x0384d46eu, 0x0246be59u, 0x0709a8dcu, 0x06cbc2ebu, 0x048d7cb2u, 0x054f1685u,
0x0e1351b8u, 0x0fd13b8fu, 0x0d9785d6u, 0x0c55efe1u, 0x091af964u, 0x08d89353u, 0x0a9e2d0au, 0x0b5c473du,
0x1c26a370u, 0x1de4c947u, 0x1fa2771eu, 0x1e601d29u, 0x1b2f0bacu, 0x1aed619bu, 0x18abdfc2u, 0x1969b5f5u,
0x1235f2c8u, 0x13f798ffu, 0x11b126a6u, 0x10734c91u, 0x153c5a14u, 0x14fe3023u, 0x16b88e7au, 0x177ae44du,
0x384d46e0u, 0x398f2cd7u, 0x3bc9928eu, 0x3a0bf8b9u, 0x3f44ee3cu, 0x3e86840bu, 0x3cc03a52u, 0x3d025065u,
0x365e1758u, 0x379c7d6fu, 0x35dac336u, 0x3418a901u, 0x3157bf84u, 0x3095d5b3u, 0x32d36beau, 0x331101ddu,
0x246be590u, 0x25a98fa7u, 0x27ef31feu, 0x262d5bc9u, 0x23624d4cu, 0x22a0277bu, 0x20e69922u, 0x2124f315u,
0x2a78b428u, 0x2bbade1fu, 0x29fc6046u, 0x283e0a71u, 0x2d711cf4u, 0x2cb376c3u, 0x2ef5c89au, 0x2f37a2adu,
0x709a8dc0u, 0x7158e7f7u, 0x731e59aeu, 0x72dc3399u, 0x7793251cu, 0x76514f2bu, 0x7417f172u, 0x75d59b45u,
0x7e89dc78u, 0x7f4bb64fu, 0x7d0d0816u, 0x7ccf6221u, 0x798074a4u, 0x78421e93u, 0x7a04a0cau, 0x7bc6cafdu,
0x6cbc2eb0u, 0x6d7e4487u, 0x6f38fadeu, 0x6efa90e9u, 0x6bb5866cu, 0x6a77ec5bu, 0x68315202u, 0x69f33835u,
0x62af7f08u, 0x636d153fu, 0x612bab66u, 0x60e9c151u, 0x65a6d7d4u, 0x6464bde3u, 0x662203bau, 0x67e0698du,
0x48d7cb20u, 0x4915a117u, 0x4b531f4eu, 0x4a917579u, 0x4fde63fcu, 0x4e1c09cbu, 0x4c5ab792u, 0x4d98dda5u,
0x46c49a98u, 0x4706f0afu, 0x45404ef6u, 0x448224c1u, 0x41cd3244u, 0x400f5873u, 0x4249e62au, 0x438b8c1du,
0x54f16850u, 0x55330267u, 0x5775bc3eu, 0x56b7d609u, 0x53f8c08cu, 0x523aaabbu, 0x507c14e2u, 0x51be7ed5u,
0x5ae239e8u, 0x5b2053dfu, 0x5966ed86u, 0x58a487b1u, 0x5deb9134u, 0x5c29fb03u, 0x5e6f455au, 0x5fad2f6du,
0xe1351b80u, 0xe0f771b7u, 0xe2b1cfeeu, 0xe373a5d9u, 0xe63cb35cu, 0xe7fed96bu, 0xe5b86732u, 0xe47a0d05u,
0xef264a38u, 0xeee4200fu, 0xeca29e56u, 0xed60f461u, 0xe82fe2e4u, 0xe9ed88d3u, 0xebab368au, 0xea695cbdu,
0xfd13b8f0u, 0xfcd1d2c7u, 0xfe976c9eu, 0xff5506a9u, 0xfa1a102cu, 0xfbd87a1bu, 0xf99ec442u, 0xf85cae75u,
0xf300e948u, 0xf2c2837fu, 0xf0843d26u, 0xf1465711u, 0xf4094194u, 0xf5cb2ba3u, 0xf78d95fau, 0xf64fffcdu,
0xd9785d60u, 0xd8ba3757u, 0xdafc890eu, 0xdb3ee339u, 0xde71f5bcu, 0xdfb39f8bu, 0xddf521d2u, 0xdc374be5u,
0xd76b0cd8u, 0xd6a966efu, 0xd4efd8b6u, 0xd52db281u, 0xd062a404u, 0xd1a0ce33u, 0xd3e6706au, 0xd2241a5du,
0xc55efe10u, 0xc49c9427u, 0xc6da2a7eu, 0xc7184049u, 0xc25756ccu, 0xc3953cfbu, 0xc1d382a2u, 0xc011e895u,
0xcb4dafa8u, 0xca8fc59fu, 0xc8c97bc6u, 0xc90b11f1u, 0xcc440774u, 0xcd866d43u, 0xcfc0d31au, 0xce02b92du,
0x91af9640u, 0x906dfc77u, 0x922b422eu, 0x93e92819u, 0x96a63e9cu, 0x976454abu, 0x9522eaf2u, 0x94e080c5u,
0x9fbcc7f8u, 0x9e7eadcfu, 0x9c381396u, 0x9dfa79a1u, 0x98b56f24u, 0x99770513u, 0x9b31bb4au, 0x9af3d17du,
0x8d893530u, 0x8c4b5f07u, 0x8e0de15eu, 0x8fcf8b69u, 0x8a809decu, 0x8b42f7dbu, 0x89044982u, 0x88c623b5u,
0x839a6488u, 0x82580ebfu, 0x801eb0e6u, 0x81dcdad1u, 0x8493cc54u, 0x8551a663u, 0x8717183au, 0x86d5720du,
0xa9e2d0a0u, 0xa820ba97u, 0xaa6604ceu, 0xaba46ef9u, 0xaeeb787cu, 0xaf29124bu, 0xad6fac12u, 0xacadc625u,
0xa7f18118u, 0xa633eb2fu, 0xa4755576u, 0xa5b73f41u, 0xa0f829c4u, 0xa13a43f3u, 0xa37cfdaau, 0xa2be979du,
0xb5c473d0u, 0xb40619e7u, 0xb640a7beu, 0xb782cd89u, 0xb2cddb0cu, 0xb30fb13bu, 0xb1490f62u, 0xb08b6555u,
0xbbd72268u, 0xba15485fu, 0xb853f606u, 0xb9919c31u, 0xbcde8ab4u, 0xbd1ce083u, 0xbf5a5edau, 0xbe9834edu
};
static const unsigned lodepng_crc32_table3[256] = {
0x00000000u, 0xb8bc6765u, 0xaa09c88bu, 0x12b5afeeu, 0x8f629757u, 0x37def032u, 0x256b5fdcu, 0x9dd738b9u,
0xc5b428efu, 0x7d084f8au, 0x6fbde064u, 0xd7018701u, 0x4ad6bfb8u, 0xf26ad8ddu, 0xe0df7733u, 0x58631056u,
0x5019579fu, 0xe8a530fau, 0xfa109f14u, 0x42acf871u, 0xdf7bc0c8u, 0x67c7a7adu, 0x75720843u, 0xcdce6f26u,
0x95ad7f70u, 0x2d111815u, 0x3fa4b7fbu, 0x8718d09eu, 0x1acfe827u, 0xa2738f42u, 0xb0c620acu, 0x087a47c9u,
0xa032af3eu, 0x188ec85bu, 0x0a3b67b5u, 0xb28700d0u, 0x2f503869u, 0x97ec5f0cu, 0x8559f0e2u, 0x3de59787u,
0x658687d1u, 0xdd3ae0b4u, 0xcf8f4f5au, 0x7733283fu, 0xeae41086u, 0x525877e3u, 0x40edd80du, 0xf851bf68u,
0xf02bf8a1u, 0x48979fc4u, 0x5a22302au, 0xe29e574fu, 0x7f496ff6u, 0xc7f50893u, 0xd540a77du, 0x6dfcc018u,
0x359fd04eu, 0x8d23b72bu, 0x9f9618c5u, 0x272a7fa0u, 0xbafd4719u, 0x0241207cu, 0x10f48f92u, 0xa848e8f7u,
0x9b14583du, 0x23a83f58u, 0x311d90b6u, 0x89a1f7d3u, 0x1476cf6au, 0xaccaa80fu, 0xbe7f07e1u, 0x06c36084u,
0x5ea070d2u, 0xe61c17b7u, 0xf4a9b859u, 0x4c15df3cu, 0xd1c2e785u, 0x697e80e0u, 0x7bcb2f0eu, 0xc377486bu,
0xcb0d0fa2u, 0x73b168c7u, 0x6104c729u, 0xd9b8a04cu, 0x446f98f5u, 0xfcd3ff90u, 0xee66507eu, 0x56da371bu,
0x0eb9274du, 0xb6054028u, 0xa4b0efc6u, 0x1c0c88a3u, 0x81dbb01au, 0x3967d77fu, 0x2bd27891u, 0x936e1ff4u,
0x3b26f703u, 0x839a9066u, 0x912f3f88u, 0x299358edu, 0xb4446054u, 0x0cf80731u, 0x1e4da8dfu, 0xa6f1cfbau,
0xfe92dfecu, 0x462eb889u, 0x549b1767u, 0xec277002u, 0x71f048bbu, 0xc94c2fdeu, 0xdbf98030u, 0x6345e755u,
0x6b3fa09cu, 0xd383c7f9u, 0xc1366817u, 0x798a0f72u, 0xe45d37cbu, 0x5ce150aeu, 0x4e54ff40u, 0xf6e89825u,
0xae8b8873u, 0x1637ef16u, 0x048240f8u, 0xbc3e279du, 0x21e91f24u, 0x99557841u, 0x8be0d7afu, 0x335cb0cau,
0xed59b63bu, 0x55e5d15eu, 0x47507eb0u, 0xffec19d5u, 0x623b216cu, 0xda874609u, 0xc832e9e7u, 0x708e8e82u,
0x28ed9ed4u, 0x9051f9b1u, 0x82e4565fu, 0x3a58313au, 0xa78f0983u, 0x1f336ee6u, 0x0d86c108u, 0xb53aa66du,
0xbd40e1a4u, 0x05fc86c1u, 0x1749292fu, 0xaff54e4au, 0x322276f3u, 0x8a9e1196u, 0x982bbe78u, 0x2097d91du,
0x78f4c94bu, 0xc048ae2eu, 0xd2fd01c0u, 0x6a4166a5u, 0xf7965e1cu, 0x4f2a3979u, 0x5d9f9697u, 0xe523f1f2u,
0x4d6b1905u, 0xf5d77e60u, 0xe762d18eu, 0x5fdeb6ebu, 0xc2098e52u, 0x7ab5e937u, 0x680046d9u, 0xd0bc21bcu,
0x88df31eau, 0x3063568fu, 0x22d6f961u, 0x9a6a9e04u, 0x07bda6bdu, 0xbf01c1d8u, 0xadb46e36u, 0x15080953u,
0x1d724e9au, 0xa5ce29ffu, 0xb77b8611u, 0x0fc7e174u, 0x9210d9cdu, 0x2aacbea8u, 0x38191146u, 0x80a57623u,
0xd8c66675u, 0x607a0110u, 0x72cfaefeu, 0xca73c99bu, 0x57a4f122u, 0xef189647u, 0xfdad39a9u, 0x45115eccu,
0x764dee06u, 0xcef18963u, 0xdc44268du, 0x64f841e8u, 0xf92f7951u, 0x41931e34u, 0x5326b1dau, 0xeb9ad6bfu,
0xb3f9c6e9u, 0x0b45a18cu, 0x19f00e62u, 0xa14c6907u, 0x3c9b51beu, 0x842736dbu, 0x96929935u, 0x2e2efe50u,
0x2654b999u, 0x9ee8defcu, 0x8c5d7112u, 0x34e11677u, 0xa9362eceu, 0x118a49abu, 0x033fe645u, 0xbb838120u,
0xe3e09176u, 0x5b5cf613u, 0x49e959fdu, 0xf1553e98u, 0x6c820621u, 0xd43e6144u, 0xc68bceaau, 0x7e37a9cfu,
0xd67f4138u, 0x6ec3265du, 0x7c7689b3u, 0xc4caeed6u, 0x591dd66fu, 0xe1a1b10au, 0xf3141ee4u, 0x4ba87981u,
0x13cb69d7u, 0xab770eb2u, 0xb9c2a15cu, 0x017ec639u, 0x9ca9fe80u, 0x241599e5u, 0x36a0360bu, 0x8e1c516eu,
0x866616a7u, 0x3eda71c2u, 0x2c6fde2cu, 0x94d3b949u, 0x090481f0u, 0xb1b8e695u, 0xa30d497bu, 0x1bb12e1eu,
0x43d23e48u, 0xfb6e592du, 0xe9dbf6c3u, 0x516791a6u, 0xccb0a91fu, 0x740cce7au, 0x66b96194u, 0xde0506f1u
};
static const unsigned lodepng_crc32_table4[256] = {
0x00000000u, 0x3d6029b0u, 0x7ac05360u, 0x47a07ad0u, 0xf580a6c0u, 0xc8e08f70u, 0x8f40f5a0u, 0xb220dc10u,
0x30704bc1u, 0x0d106271u, 0x4ab018a1u, 0x77d03111u, 0xc5f0ed01u, 0xf890c4b1u, 0xbf30be61u, 0x825097d1u,
0x60e09782u, 0x5d80be32u, 0x1a20c4e2u, 0x2740ed52u, 0x95603142u, 0xa80018f2u, 0xefa06222u, 0xd2c04b92u,
0x5090dc43u, 0x6df0f5f3u, 0x2a508f23u, 0x1730a693u, 0xa5107a83u, 0x98705333u, 0xdfd029e3u, 0xe2b00053u,
0xc1c12f04u, 0xfca106b4u, 0xbb017c64u, 0x866155d4u, 0x344189c4u, 0x0921a074u, 0x4e81daa4u, 0x73e1f314u,
0xf1b164c5u, 0xccd14d75u, 0x8b7137a5u, 0xb6111e15u, 0x0431c205u, 0x3951ebb5u, 0x7ef19165u, 0x4391b8d5u,
0xa121b886u, 0x9c419136u, 0xdbe1ebe6u, 0xe681c256u, 0x54a11e46u, 0x69c137f6u, 0x2e614d26u, 0x13016496u,
0x9151f347u, 0xac31daf7u, 0xeb91a027u, 0xd6f18997u, 0x64d15587u, 0x59b17c37u, 0x1e1106e7u, 0x23712f57u,
0x58f35849u, 0x659371f9u, 0x22330b29u, 0x1f532299u, 0xad73fe89u, 0x9013d739u, 0xd7b3ade9u, 0xead38459u,
0x68831388u, 0x55e33a38u, 0x124340e8u, 0x2f236958u, 0x9d03b548u, 0xa0639cf8u, 0xe7c3e628u, 0xdaa3cf98u,
0x3813cfcbu, 0x0573e67bu, 0x42d39cabu, 0x7fb3b51bu, 0xcd93690bu, 0xf0f340bbu, 0xb7533a6bu, 0x8a3313dbu,
0x0863840au, 0x3503adbau, 0x72a3d76au, 0x4fc3fedau, 0xfde322cau, 0xc0830b7au, 0x872371aau, 0xba43581au,
0x9932774du, 0xa4525efdu, 0xe3f2242du, 0xde920d9du, 0x6cb2d18du, 0x51d2f83du, 0x167282edu, 0x2b12ab5du,
0xa9423c8cu, 0x9422153cu, 0xd3826fecu, 0xeee2465cu, 0x5cc29a4cu, 0x61a2b3fcu, 0x2602c92cu, 0x1b62e09cu,
0xf9d2e0cfu, 0xc4b2c97fu, 0x8312b3afu, 0xbe729a1fu, 0x0c52460fu, 0x31326fbfu, 0x7692156fu, 0x4bf23cdfu,
0xc9a2ab0eu, 0xf4c282beu, 0xb362f86eu, 0x8e02d1deu, 0x3c220dceu, 0x0142247eu, 0x46e25eaeu, 0x7b82771eu,
0xb1e6b092u, 0x8c869922u, 0xcb26e3f2u, 0xf646ca42u, 0x44661652u, 0x79063fe2u, 0x3ea64532u, 0x03c66c82u,
0x8196fb53u, 0xbcf6d2e3u, 0xfb56a833u, 0xc6368183u, 0x74165d93u, 0x49767423u, 0x0ed60ef3u, 0x33b62743u,
0xd1062710u, 0xec660ea0u, 0xabc67470u, 0x96a65dc0u, 0x248681d0u, 0x19e6a860u, 0x5e46d2b0u, 0x6326fb00u,
0xe1766cd1u, 0xdc164561u, 0x9bb63fb1u, 0xa6d61601u, 0x14f6ca11u, 0x2996e3a1u, 0x6e369971u, 0x5356b0c1u,
0x70279f96u, 0x4d47b626u, 0x0ae7ccf6u, 0x3787e546u, 0x85a73956u, 0xb8c710e6u, 0xff676a36u, 0xc2074386u,
0x4057d457u, 0x7d37fde7u, 0x3a978737u, 0x07f7ae87u, 0xb5d77297u, 0x88b75b27u, 0xcf1721f7u, 0xf2770847u,
0x10c70814u, 0x2da721a4u, 0x6a075b74u, 0x576772c4u, 0xe547aed4u, 0xd8278764u, 0x9f87fdb4u, 0xa2e7d404u,
0x20b743d5u, 0x1dd76a65u, 0x5a7710b5u, 0x67173905u, 0xd537e515u, 0xe857cca5u, 0xaff7b675u, 0x92979fc5u,
0xe915e8dbu, 0xd475c16bu, 0x93d5bbbbu, 0xaeb5920bu, 0x1c954e1bu, 0x21f567abu, 0x66551d7bu, 0x5b3534cbu,
0xd965a31au, 0xe4058aaau, 0xa3a5f07au, 0x9ec5d9cau, 0x2ce505dau, 0x11852c6au, 0x562556bau, 0x6b457f0au,
0x89f57f59u, 0xb49556e9u, 0xf3352c39u, 0xce550589u, 0x7c75d999u, 0x4115f029u, 0x06b58af9u, 0x3bd5a349u,
0xb9853498u, 0x84e51d28u, 0xc34567f8u, 0xfe254e48u, 0x4c059258u, 0x7165bbe8u, 0x36c5c138u, 0x0ba5e888u,
0x28d4c7dfu, 0x15b4ee6fu, 0x521494bfu, 0x6f74bd0fu, 0xdd54611fu, 0xe03448afu, 0xa794327fu, 0x9af41bcfu,
0x18a48c1eu, 0x25c4a5aeu, 0x6264df7eu, 0x5f04f6ceu, 0xed242adeu, 0xd044036eu, 0x97e479beu, 0xaa84500eu,
0x4834505du, 0x755479edu, 0x32f4033du, 0x0f942a8du, 0xbdb4f69du, 0x80d4df2du, 0xc774a5fdu, 0xfa148c4du,
0x78441b9cu, 0x4524322cu, 0x028448fcu, 0x3fe4614cu, 0x8dc4bd5cu, 0xb0a494ecu, 0xf704ee3cu, 0xca64c78cu
};
static const unsigned lodepng_crc32_table5[256] = {
0x00000000u, 0xcb5cd3a5u, 0x4dc8a10bu, 0x869472aeu, 0x9b914216u, 0x50cd91b3u, 0xd659e31du, 0x1d0530b8u,
0xec53826du, 0x270f51c8u, 0xa19b2366u, 0x6ac7f0c3u, 0x77c2c07bu, 0xbc9e13deu, 0x3a0a6170u, 0xf156b2d5u,
0x03d6029bu, 0xc88ad13eu, 0x4e1ea390u, 0x85427035u, 0x9847408du, 0x531b9328u, 0xd58fe186u, 0x1ed33223u,
0xef8580f6u, 0x24d95353u, 0xa24d21fdu, 0x6911f258u, 0x7414c2e0u, 0xbf481145u, 0x39dc63ebu, 0xf280b04eu,
0x07ac0536u, 0xccf0d693u, 0x4a64a43du, 0x81387798u, 0x9c3d4720u, 0x57619485u, 0xd1f5e62bu, 0x1aa9358eu,
0xebff875bu, 0x20a354feu, 0xa6372650u, 0x6d6bf5f5u, 0x706ec54du, 0xbb3216e8u, 0x3da66446u, 0xf6fab7e3u,
0x047a07adu, 0xcf26d408u, 0x49b2a6a6u, 0x82ee7503u, 0x9feb45bbu, 0x54b7961eu, 0xd223e4b0u, 0x197f3715u,
0xe82985c0u, 0x23755665u, 0xa5e124cbu, 0x6ebdf76eu, 0x73b8c7d6u, 0xb8e41473u, 0x3e7066ddu, 0xf52cb578u,
0x0f580a6cu, 0xc404d9c9u, 0x4290ab67u, 0x89cc78c2u, 0x94c9487au, 0x5f959bdfu, 0xd901e971u, 0x125d3ad4u,
0xe30b8801u, 0x28575ba4u, 0xaec3290au, 0x659ffaafu, 0x789aca17u, 0xb3c619b2u, 0x35526b1cu, 0xfe0eb8b9u,
0x0c8e08f7u, 0xc7d2db52u, 0x4146a9fcu, 0x8a1a7a59u, 0x971f4ae1u, 0x5c439944u, 0xdad7ebeau, 0x118b384fu,
0xe0dd8a9au, 0x2b81593fu, 0xad152b91u, 0x6649f834u, 0x7b4cc88cu, 0xb0101b29u, 0x36846987u, 0xfdd8ba22u,
0x08f40f5au, 0xc3a8dcffu, 0x453cae51u, 0x8e607df4u, 0x93654d4cu, 0x58399ee9u, 0xdeadec47u, 0x15f13fe2u,
0xe4a78d37u, 0x2ffb5e92u, 0xa96f2c3cu, 0x6233ff99u, 0x7f36cf21u, 0xb46a1c84u, 0x32fe6e2au, 0xf9a2bd8fu,
0x0b220dc1u, 0xc07ede64u, 0x46eaaccau, 0x8db67f6fu, 0x90b34fd7u, 0x5bef9c72u, 0xdd7beedcu, 0x16273d79u,
0xe7718facu, 0x2c2d5c09u, 0xaab92ea7u, 0x61e5fd02u, 0x7ce0cdbau, 0xb7bc1e1fu, 0x31286cb1u, 0xfa74bf14u,
0x1eb014d8u, 0xd5ecc77du, 0x5378b5d3u, 0x98246676u, 0x852156ceu, 0x4e7d856bu, 0xc8e9f7c5u, 0x03b52460u,
0xf2e396b5u, 0x39bf4510u, 0xbf2b37beu, 0x7477e41bu, 0x6972d4a3u, 0xa22e0706u, 0x24ba75a8u, 0xefe6a60du,
0x1d661643u, 0xd63ac5e6u, 0x50aeb748u, 0x9bf264edu, 0x86f75455u, 0x4dab87f0u, 0xcb3ff55eu, 0x006326fbu,
0xf135942eu, 0x3a69478bu, 0xbcfd3525u, 0x77a1e680u, 0x6aa4d638u, 0xa1f8059du, 0x276c7733u, 0xec30a496u,
0x191c11eeu, 0xd240c24bu, 0x54d4b0e5u, 0x9f886340u, 0x828d53f8u, 0x49d1805du, 0xcf45f2f3u, 0x04192156u,
0xf54f9383u, 0x3e134026u, 0xb8873288u, 0x73dbe12du, 0x6eded195u, 0xa5820230u, 0x2316709eu, 0xe84aa33bu,
0x1aca1375u, 0xd196c0d0u, 0x5702b27eu, 0x9c5e61dbu, 0x815b5163u, 0x4a0782c6u, 0xcc93f068u, 0x07cf23cdu,
0xf6999118u, 0x3dc542bdu, 0xbb513013u, 0x700de3b6u, 0x6d08d30eu, 0xa65400abu, 0x20c07205u, 0xeb9ca1a0u,
0x11e81eb4u, 0xdab4cd11u, 0x5c20bfbfu, 0x977c6c1au, 0x8a795ca2u, 0x41258f07u, 0xc7b1fda9u, 0x0ced2e0cu,
0xfdbb9cd9u, 0x36e74f7cu, 0xb0733dd2u, 0x7b2fee77u, 0x662adecfu, 0xad760d6au, 0x2be27fc4u, 0xe0beac61u,
0x123e1c2fu, 0xd962cf8au, 0x5ff6bd24u, 0x94aa6e81u, 0x89af5e39u, 0x42f38d9cu, 0xc467ff32u, 0x0f3b2c97u,
0xfe6d9e42u, 0x35314de7u, 0xb3a53f49u, 0x78f9ececu, 0x65fcdc54u, 0xaea00ff1u, 0x28347d5fu, 0xe368aefau,
0x16441b82u, 0xdd18c827u, 0x5b8cba89u, 0x90d0692cu, 0x8dd55994u, 0x46898a31u, 0xc01df89fu, 0x0b412b3au,
0xfa1799efu, 0x314b4a4au, 0xb7df38e4u, 0x7c83eb41u, 0x6186dbf9u, 0xaada085cu, 0x2c4e7af2u, 0xe712a957u,
0x15921919u, 0xdececabcu, 0x585ab812u, 0x93066bb7u, 0x8e035b0fu, 0x455f88aau, 0xc3cbfa04u, 0x089729a1u,
0xf9c19b74u, 0x329d48d1u, 0xb4093a7fu, 0x7f55e9dau, 0x6250d962u, 0xa90c0ac7u, 0x2f987869u, 0xe4c4abccu
};
static const unsigned lodepng_crc32_table6[256] = {
0x00000000u, 0xa6770bb4u, 0x979f1129u, 0x31e81a9du, 0xf44f2413u, 0x52382fa7u, 0x63d0353au, 0xc5a73e8eu,
0x33ef4e67u, 0x959845d3u, 0xa4705f4eu, 0x020754fau, 0xc7a06a74u, 0x61d761c0u, 0x503f7b5du, 0xf64870e9u,
0x67de9cceu, 0xc1a9977au, 0xf0418de7u, 0x56368653u, 0x9391b8ddu, 0x35e6b369u, 0x040ea9f4u, 0xa279a240u,
0x5431d2a9u, 0xf246d91du, 0xc3aec380u, 0x65d9c834u, 0xa07ef6bau, 0x0609fd0eu, 0x37e1e793u, 0x9196ec27u,
0xcfbd399cu, 0x69ca3228u, 0x582228b5u, 0xfe552301u, 0x3bf21d8fu, 0x9d85163bu, 0xac6d0ca6u, 0x0a1a0712u,
0xfc5277fbu, 0x5a257c4fu, 0x6bcd66d2u, 0xcdba6d66u, 0x081d53e8u, 0xae6a585cu, 0x9f8242c1u, 0x39f54975u,
0xa863a552u, 0x0e14aee6u, 0x3ffcb47bu, 0x998bbfcfu, 0x5c2c8141u, 0xfa5b8af5u, 0xcbb39068u, 0x6dc49bdcu,
0x9b8ceb35u, 0x3dfbe081u, 0x0c13fa1cu, 0xaa64f1a8u, 0x6fc3cf26u, 0xc9b4c492u, 0xf85cde0fu, 0x5e2bd5bbu,
0x440b7579u, 0xe27c7ecdu, 0xd3946450u, 0x75e36fe4u, 0xb044516au, 0x16335adeu, 0x27db4043u, 0x81ac4bf7u,
0x77e43b1eu, 0xd19330aau, 0xe07b2a37u, 0x460c2183u, 0x83ab1f0du, 0x25dc14b9u, 0x14340e24u, 0xb2430590u,
0x23d5e9b7u, 0x85a2e203u, 0xb44af89eu, 0x123df32au, 0xd79acda4u, 0x71edc610u, 0x4005dc8du, 0xe672d739u,
0x103aa7d0u, 0xb64dac64u, 0x87a5b6f9u, 0x21d2bd4du, 0xe47583c3u, 0x42028877u, 0x73ea92eau, 0xd59d995eu,
0x8bb64ce5u, 0x2dc14751u, 0x1c295dccu, 0xba5e5678u, 0x7ff968f6u, 0xd98e6342u, 0xe86679dfu, 0x4e11726bu,
0xb8590282u, 0x1e2e0936u, 0x2fc613abu, 0x89b1181fu, 0x4c162691u, 0xea612d25u, 0xdb8937b8u, 0x7dfe3c0cu,
0xec68d02bu, 0x4a1fdb9fu, 0x7bf7c102u, 0xdd80cab6u, 0x1827f438u, 0xbe50ff8cu, 0x8fb8e511u, 0x29cfeea5u,
0xdf879e4cu, 0x79f095f8u, 0x48188f65u, 0xee6f84d1u, 0x2bc8ba5fu, 0x8dbfb1ebu, 0xbc57ab76u, 0x1a20a0c2u,
0x8816eaf2u, 0x2e61e146u, 0x1f89fbdbu, 0xb9fef06fu, 0x7c59cee1u, 0xda2ec555u, 0xebc6dfc8u, 0x4db1d47cu,
0xbbf9a495u, 0x1d8eaf21u, 0x2c66b5bcu, 0x8a11be08u, 0x4fb68086u, 0xe9c18b32u, 0xd82991afu, 0x7e5e9a1bu,
0xefc8763cu, 0x49bf7d88u, 0x78576715u, 0xde206ca1u, 0x1b87522fu, 0xbdf0599bu, 0x8c184306u, 0x2a6f48b2u,
0xdc27385bu, 0x7a5033efu, 0x4bb82972u, 0xedcf22c6u, 0x28681c48u, 0x8e1f17fcu, 0xbff70d61u, 0x198006d5u,
0x47abd36eu, 0xe1dcd8dau, 0xd034c247u, 0x7643c9f3u, 0xb3e4f77du, 0x1593fcc9u, 0x247be654u, 0x820cede0u,
0x74449d09u, 0xd23396bdu, 0xe3db8c20u, 0x45ac8794u, 0x800bb91au, 0x267cb2aeu, 0x1794a833u, 0xb1e3a387u,
0x20754fa0u, 0x86024414u, 0xb7ea5e89u, 0x119d553du, 0xd43a6bb3u, 0x724d6007u, 0x43a57a9au, 0xe5d2712eu,
0x139a01c7u, 0xb5ed0a73u, 0x840510eeu, 0x22721b5au, 0xe7d525d4u, 0x41a22e60u, 0x704a34fdu, 0xd63d3f49u,
0xcc1d9f8bu, 0x6a6a943fu, 0x5b828ea2u, 0xfdf58516u, 0x3852bb98u, 0x9e25b02cu, 0xafcdaab1u, 0x09baa105u,
0xfff2d1ecu, 0x5985da58u, 0x686dc0c5u, 0xce1acb71u, 0x0bbdf5ffu, 0xadcafe4bu, 0x9c22e4d6u, 0x3a55ef62u,
0xabc30345u, 0x0db408f1u, 0x3c5c126cu, 0x9a2b19d8u, 0x5f8c2756u, 0xf9fb2ce2u, 0xc813367fu, 0x6e643dcbu,
0x982c4d22u, 0x3e5b4696u, 0x0fb35c0bu, 0xa9c457bfu, 0x6c636931u, 0xca146285u, 0xfbfc7818u, 0x5d8b73acu,
0x03a0a617u, 0xa5d7ada3u, 0x943fb73eu, 0x3248bc8au, 0xf7ef8204u, 0x519889b0u, 0x6070932du, 0xc6079899u,
0x304fe870u, 0x9638e3c4u, 0xa7d0f959u, 0x01a7f2edu, 0xc400cc63u, 0x6277c7d7u, 0x539fdd4au, 0xf5e8d6feu,
0x647e3ad9u, 0xc209316du, 0xf3e12bf0u, 0x55962044u, 0x90311ecau, 0x3646157eu, 0x07ae0fe3u, 0xa1d90457u,
0x579174beu, 0xf1e67f0au, 0xc00e6597u, 0x66796e23u, 0xa3de50adu, 0x05a95b19u, 0x34414184u, 0x92364a30u
};
static const unsigned lodepng_crc32_table7[256] = {
0x00000000u, 0xccaa009eu, 0x4225077du, 0x8e8f07e3u, 0x844a0efau, 0x48e00e64u, 0xc66f0987u, 0x0ac50919u,
0xd3e51bb5u, 0x1f4f1b2bu, 0x91c01cc8u, 0x5d6a1c56u, 0x57af154fu, 0x9b0515d1u, 0x158a1232u, 0xd92012acu,
0x7cbb312bu, 0xb01131b5u, 0x3e9e3656u, 0xf23436c8u, 0xf8f13fd1u, 0x345b3f4fu, 0xbad438acu, 0x767e3832u,
0xaf5e2a9eu, 0x63f42a00u, 0xed7b2de3u, 0x21d12d7du, 0x2b142464u, 0xe7be24fau, 0x69312319u, 0xa59b2387u,
0xf9766256u, 0x35dc62c8u, 0xbb53652bu, 0x77f965b5u, 0x7d3c6cacu, 0xb1966c32u, 0x3f196bd1u, 0xf3b36b4fu,
0x2a9379e3u, 0xe639797du, 0x68b67e9eu, 0xa41c7e00u, 0xaed97719u, 0x62737787u, 0xecfc7064u, 0x205670fau,
0x85cd537du, 0x496753e3u, 0xc7e85400u, 0x0b42549eu, 0x01875d87u, 0xcd2d5d19u, 0x43a25afau, 0x8f085a64u,
0x562848c8u, 0x9a824856u, 0x140d4fb5u, 0xd8a74f2bu, 0xd2624632u, 0x1ec846acu, 0x9047414fu, 0x5ced41d1u,
0x299dc2edu, 0xe537c273u, 0x6bb8c590u, 0xa712c50eu, 0xadd7cc17u, 0x617dcc89u, 0xeff2cb6au, 0x2358cbf4u,
0xfa78d958u, 0x36d2d9c6u, 0xb85dde25u, 0x74f7debbu, 0x7e32d7a2u, 0xb298d73cu, 0x3c17d0dfu, 0xf0bdd041u,
0x5526f3c6u, 0x998cf358u, 0x1703f4bbu, 0xdba9f425u, 0xd16cfd3cu, 0x1dc6fda2u, 0x9349fa41u, 0x5fe3fadfu,
0x86c3e873u, 0x4a69e8edu, 0xc4e6ef0eu, 0x084cef90u, 0x0289e689u, 0xce23e617u, 0x40ace1f4u, 0x8c06e16au,
0xd0eba0bbu, 0x1c41a025u, 0x92cea7c6u, 0x5e64a758u, 0x54a1ae41u, 0x980baedfu, 0x1684a93cu, 0xda2ea9a2u,
0x030ebb0eu, 0xcfa4bb90u, 0x412bbc73u, 0x8d81bcedu, 0x8744b5f4u, 0x4beeb56au, 0xc561b289u, 0x09cbb217u,
0xac509190u, 0x60fa910eu, 0xee7596edu, 0x22df9673u, 0x281a9f6au, 0xe4b09ff4u, 0x6a3f9817u, 0xa6959889u,
0x7fb58a25u, 0xb31f8abbu, 0x3d908d58u, 0xf13a8dc6u, 0xfbff84dfu, 0x37558441u, 0xb9da83a2u, 0x7570833cu,
0x533b85dau, 0x9f918544u, 0x111e82a7u, 0xddb48239u, 0xd7718b20u, 0x1bdb8bbeu, 0x95548c5du, 0x59fe8cc3u,
0x80de9e6fu, 0x4c749ef1u, 0xc2fb9912u, 0x0e51998cu, 0x04949095u, 0xc83e900bu, 0x46b197e8u, 0x8a1b9776u,
0x2f80b4f1u, 0xe32ab46fu, 0x6da5b38cu, 0xa10fb312u, 0xabcaba0bu, 0x6760ba95u, 0xe9efbd76u, 0x2545bde8u,
0xfc65af44u, 0x30cfafdau, 0xbe40a839u, 0x72eaa8a7u, 0x782fa1beu, 0xb485a120u, 0x3a0aa6c3u, 0xf6a0a65du,
0xaa4de78cu, 0x66e7e712u, 0xe868e0f1u, 0x24c2e06fu, 0x2e07e976u, 0xe2ade9e8u, 0x6c22ee0bu, 0xa088ee95u,
0x79a8fc39u, 0xb502fca7u, 0x3b8dfb44u, 0xf727fbdau, 0xfde2f2c3u, 0x3148f25du, 0xbfc7f5beu, 0x736df520u,
0xd6f6d6a7u, 0x1a5cd639u, 0x94d3d1dau, 0x5879d144u, 0x52bcd85du, 0x9e16d8c3u, 0x1099df20u, 0xdc33dfbeu,
0x0513cd12u, 0xc9b9cd8cu, 0x4736ca6fu, 0x8b9ccaf1u, 0x8159c3e8u, 0x4df3c376u, 0xc37cc495u, 0x0fd6c40bu,
0x7aa64737u, 0xb60c47a9u, 0x3883404au, 0xf42940d4u, 0xfeec49cdu, 0x32464953u, 0xbcc94eb0u, 0x70634e2eu,
0xa9435c82u, 0x65e95c1cu, 0xeb665bffu, 0x27cc5b61u, 0x2d095278u, 0xe1a352e6u, 0x6f2c5505u, 0xa386559bu,
0x061d761cu, 0xcab77682u, 0x44387161u, 0x889271ffu, 0x825778e6u, 0x4efd7878u, 0xc0727f9bu, 0x0cd87f05u,
0xd5f86da9u, 0x19526d37u, 0x97dd6ad4u, 0x5b776a4au, 0x51b26353u, 0x9d1863cdu, 0x1397642eu, 0xdf3d64b0u,
0x83d02561u, 0x4f7a25ffu, 0xc1f5221cu, 0x0d5f2282u, 0x079a2b9bu, 0xcb302b05u, 0x45bf2ce6u, 0x89152c78u,
0x50353ed4u, 0x9c9f3e4au, 0x121039a9u, 0xdeba3937u, 0xd47f302eu, 0x18d530b0u, 0x965a3753u, 0x5af037cdu,
0xff6b144au, 0x33c114d4u, 0xbd4e1337u, 0x71e413a9u, 0x7b211ab0u, 0xb78b1a2eu, 0x39041dcdu, 0xf5ae1d53u,
0x2c8e0fffu, 0xe0240f61u, 0x6eab0882u, 0xa201081cu, 0xa8c40105u, 0x646e019bu, 0xeae10678u, 0x264b06e6u
};
/* Computes the cyclic redundancy check as used by PNG chunks*/
unsigned lodepng_crc32(const unsigned char* data, size_t length) {
/*Using the Slicing by Eight algorithm*/
unsigned r = 0xffffffffu;
size_t i;
for(i = 0; i < length; ++i) {
r = lodepng_crc32_table[(r ^ data[i]) & 0xffu] ^ (r >> 8u);
while(length >= 8) {
r = lodepng_crc32_table7[(data[0] ^ (r & 0xffu))] ^
lodepng_crc32_table6[(data[1] ^ ((r >> 8) & 0xffu))] ^
lodepng_crc32_table5[(data[2] ^ ((r >> 16) & 0xffu))] ^
lodepng_crc32_table4[(data[3] ^ ((r >> 24) & 0xffu))] ^
lodepng_crc32_table3[data[4]] ^
lodepng_crc32_table2[data[5]] ^
lodepng_crc32_table1[data[6]] ^
lodepng_crc32_table0[data[7]];
data += 8;
length -= 8;
}
while(length--) {
r = lodepng_crc32_table0[(r ^ *data++) & 0xffu] ^ (r >> 8);
}
return r ^ 0xffffffffu;
}
#else /* LODEPNG_COMPILE_CRC */
/*in this case, the function is only declared here, and must be defined externally
so that it will be linked in*/
so that it will be linked in.
Example implementation that uses a much smaller lookup table for memory constrained cases:
unsigned lodepng_crc32(const unsigned char* data, size_t length) {
unsigned r = 0xffffffffu;
static const unsigned table[16] = {
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};
while(length--) {
r = table[(r ^ *data) & 0xf] ^ (r >> 4);
r = table[(r ^ (*data >> 4)) & 0xf] ^ (r >> 4);
data++;
}
return r ^ 0xffffffffu;
}
*/
unsigned lodepng_crc32(const unsigned char* data, size_t length);
#endif /* LODEPNG_COMPILE_CRC */
@ -3964,15 +4237,14 @@ static unsigned auto_choose_color(LodePNGColorMode* mode_out,
#endif /* #ifdef LODEPNG_COMPILE_ENCODER */
/*
Paeth predictor, used by PNG filter type 4
The parameters are of type short, but should come from unsigned chars, the shorts
are only needed to make the paeth calculation correct.
*/
static unsigned char paethPredictor(short a, short b, short c) {
short pa = LODEPNG_ABS(b - c);
short pb = LODEPNG_ABS(a - c);
short pc = LODEPNG_ABS(a + b - c - c);
/*Path predictor, used by PNG filter type 4*/
static unsigned char paethPredictor(unsigned char a, unsigned char b, unsigned char c) {
/* the subtractions of unsigned char cast it to a signed type.
With gcc, short is faster than int, with clang int is as fast (as of april 2023)*/
short pa = (b - c) < 0 ? -(b - c) : (b - c);
short pb = (a - c) < 0 ? -(a - c) : (a - c);
/* writing it out like this compiles to something faster than introducing a temp variable*/
short pc = (a + b - c - c) < 0 ? -(a + b - c - c) : (a + b - c - c);
/* return input value associated with smallest of pa, pb, pc (with certain priority if equal) */
if(pb < pa) { a = b; pa = pb; }
return (pc < pa) ? c : a;
@ -4168,47 +4440,108 @@ static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scan
break;
case 4:
if(precon) {
size_t j = 0;
for(i = 0; i != bytewidth; ++i) {
recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/
}
/* Unroll independent paths of the paeth predictor. A 6x and 8x version is also possible but that
adds too much code. Whether this speeds up anything depends on compiler and settings. */
if(bytewidth >= 4) {
for(; i + 3 < length; i += 4, j += 4) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2], s3 = scanline[i + 3];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2], r3 = recon[j + 3];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2], p3 = precon[i + 3];
unsigned char q0 = precon[j + 0], q1 = precon[j + 1], q2 = precon[j + 2], q3 = precon[j + 3];
recon[i + 0] = s0 + paethPredictor(r0, p0, q0);
recon[i + 1] = s1 + paethPredictor(r1, p1, q1);
recon[i + 2] = s2 + paethPredictor(r2, p2, q2);
recon[i + 3] = s3 + paethPredictor(r3, p3, q3);
/* Unroll independent paths of this predictor. Whether this speeds up
anything depends on compiler and settings. */
if(bytewidth == 8) {
unsigned char a0, b0 = 0, c0, d0 = 0, a1, b1 = 0, c1, d1 = 0;
unsigned char a2, b2 = 0, c2, d2 = 0, a3, b3 = 0, c3, d3 = 0;
unsigned char a4, b4 = 0, c4, d4 = 0, a5, b5 = 0, c5, d5 = 0;
unsigned char a6, b6 = 0, c6, d6 = 0, a7, b7 = 0, c7, d7 = 0;
for(i = 0; i + 7 < length; i += 8) {
c0 = b0; c1 = b1; c2 = b2; c3 = b3;
c4 = b4; c5 = b5; c6 = b6; c7 = b7;
b0 = precon[i + 0]; b1 = precon[i + 1]; b2 = precon[i + 2]; b3 = precon[i + 3];
b4 = precon[i + 4]; b5 = precon[i + 5]; b6 = precon[i + 6]; b7 = precon[i + 7];
a0 = d0; a1 = d1; a2 = d2; a3 = d3;
a4 = d4; a5 = d5; a6 = d6; a7 = d7;
d0 = scanline[i + 0] + paethPredictor(a0, b0, c0);
d1 = scanline[i + 1] + paethPredictor(a1, b1, c1);
d2 = scanline[i + 2] + paethPredictor(a2, b2, c2);
d3 = scanline[i + 3] + paethPredictor(a3, b3, c3);
d4 = scanline[i + 4] + paethPredictor(a4, b4, c4);
d5 = scanline[i + 5] + paethPredictor(a5, b5, c5);
d6 = scanline[i + 6] + paethPredictor(a6, b6, c6);
d7 = scanline[i + 7] + paethPredictor(a7, b7, c7);
recon[i + 0] = d0; recon[i + 1] = d1; recon[i + 2] = d2; recon[i + 3] = d3;
recon[i + 4] = d4; recon[i + 5] = d5; recon[i + 6] = d6; recon[i + 7] = d7;
}
} else if(bytewidth >= 3) {
for(; i + 2 < length; i += 3, j += 3) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1], s2 = scanline[i + 2];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1], r2 = recon[j + 2];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1], p2 = precon[i + 2];
unsigned char q0 = precon[j + 0], q1 = precon[j + 1], q2 = precon[j + 2];
recon[i + 0] = s0 + paethPredictor(r0, p0, q0);
recon[i + 1] = s1 + paethPredictor(r1, p1, q1);
recon[i + 2] = s2 + paethPredictor(r2, p2, q2);
} else if(bytewidth == 6) {
unsigned char a0, b0 = 0, c0, d0 = 0, a1, b1 = 0, c1, d1 = 0;
unsigned char a2, b2 = 0, c2, d2 = 0, a3, b3 = 0, c3, d3 = 0;
unsigned char a4, b4 = 0, c4, d4 = 0, a5, b5 = 0, c5, d5 = 0;
for(i = 0; i + 5 < length; i += 6) {
c0 = b0; c1 = b1; c2 = b2;
c3 = b3; c4 = b4; c5 = b5;
b0 = precon[i + 0]; b1 = precon[i + 1]; b2 = precon[i + 2];
b3 = precon[i + 3]; b4 = precon[i + 4]; b5 = precon[i + 5];
a0 = d0; a1 = d1; a2 = d2;
a3 = d3; a4 = d4; a5 = d5;
d0 = scanline[i + 0] + paethPredictor(a0, b0, c0);
d1 = scanline[i + 1] + paethPredictor(a1, b1, c1);
d2 = scanline[i + 2] + paethPredictor(a2, b2, c2);
d3 = scanline[i + 3] + paethPredictor(a3, b3, c3);
d4 = scanline[i + 4] + paethPredictor(a4, b4, c4);
d5 = scanline[i + 5] + paethPredictor(a5, b5, c5);
recon[i + 0] = d0; recon[i + 1] = d1; recon[i + 2] = d2;
recon[i + 3] = d3; recon[i + 4] = d4; recon[i + 5] = d5;
}
} else if(bytewidth >= 2) {
for(; i + 1 < length; i += 2, j += 2) {
unsigned char s0 = scanline[i + 0], s1 = scanline[i + 1];
unsigned char r0 = recon[j + 0], r1 = recon[j + 1];
unsigned char p0 = precon[i + 0], p1 = precon[i + 1];
unsigned char q0 = precon[j + 0], q1 = precon[j + 1];
recon[i + 0] = s0 + paethPredictor(r0, p0, q0);
recon[i + 1] = s1 + paethPredictor(r1, p1, q1);
} else if(bytewidth == 4) {
unsigned char a0, b0 = 0, c0, d0 = 0, a1, b1 = 0, c1, d1 = 0;
unsigned char a2, b2 = 0, c2, d2 = 0, a3, b3 = 0, c3, d3 = 0;
for(i = 0; i + 3 < length; i += 4) {
c0 = b0; c1 = b1; c2 = b2; c3 = b3;
b0 = precon[i + 0]; b1 = precon[i + 1]; b2 = precon[i + 2]; b3 = precon[i + 3];
a0 = d0; a1 = d1; a2 = d2; a3 = d3;
d0 = scanline[i + 0] + paethPredictor(a0, b0, c0);
d1 = scanline[i + 1] + paethPredictor(a1, b1, c1);
d2 = scanline[i + 2] + paethPredictor(a2, b2, c2);
d3 = scanline[i + 3] + paethPredictor(a3, b3, c3);
recon[i + 0] = d0; recon[i + 1] = d1; recon[i + 2] = d2; recon[i + 3] = d3;
}
} else if(bytewidth == 3) {
unsigned char a0, b0 = 0, c0, d0 = 0;
unsigned char a1, b1 = 0, c1, d1 = 0;
unsigned char a2, b2 = 0, c2, d2 = 0;
for(i = 0; i + 2 < length; i += 3) {
c0 = b0; c1 = b1; c2 = b2;
b0 = precon[i + 0]; b1 = precon[i + 1]; b2 = precon[i + 2];
a0 = d0; a1 = d1; a2 = d2;
d0 = scanline[i + 0] + paethPredictor(a0, b0, c0);
d1 = scanline[i + 1] + paethPredictor(a1, b1, c1);
d2 = scanline[i + 2] + paethPredictor(a2, b2, c2);
recon[i + 0] = d0; recon[i + 1] = d1; recon[i + 2] = d2;
}
} else if(bytewidth == 2) {
unsigned char a0, b0 = 0, c0, d0 = 0;
unsigned char a1, b1 = 0, c1, d1 = 0;
for(i = 0; i + 1 < length; i += 2) {
c0 = b0; c1 = b1;
b0 = precon[i + 0];
b1 = precon[i + 1];
a0 = d0; a1 = d1;
d0 = scanline[i + 0] + paethPredictor(a0, b0, c0);
d1 = scanline[i + 1] + paethPredictor(a1, b1, c1);
recon[i + 0] = d0;
recon[i + 1] = d1;
}
} else if(bytewidth == 1) {
unsigned char a, b = 0, c, d = 0;
for(i = 0; i != length; ++i) {
c = b;
b = precon[i];
a = d;
d = scanline[i] + paethPredictor(a, b, c);
recon[i] = d;
}
} else {
/* Normally not a possible case, but this would handle it correctly */
for(i = 0; i != bytewidth; ++i) {
recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/
}
}
for(; i != length; ++i, ++j) {
recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[j]));
/* finish any remaining bytes */
for(; i != length; ++i) {
recon[i] = (scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth]));
}
} else {
size_t j = 0;
@ -5521,7 +5854,7 @@ static void filterScanline(unsigned char* out, const unsigned char* scanline, co
for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - (scanline[i - bytewidth] >> 1);
}
break;
case 4: /*Paeth*/
case 4: /*Path*/
if(prevline) {
/*paethPredictor(0, prevline[i], 0) is always prevline[i]*/
for(i = 0; i != bytewidth; ++i) out[i] = (scanline[i] - prevline[i]);
@ -6057,7 +6390,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize,
if(state->encoder.force_palette) {
if(info.color.colortype != LCT_GREY && info.color.colortype != LCT_GREY_ALPHA &&
(auto_color.colortype == LCT_GREY || auto_color.colortype == LCT_GREY_ALPHA)) {
/*user speficially forced a PLTE palette, so cannot convert to grayscale types because
/*user specifically forced a PLTE palette, so cannot convert to grayscale types because
the PNG specification only allows writing a suggested palette in PLTE for truecolor types*/
allow_convert = 0;
}

View File

@ -1,42 +0,0 @@
#include "include/MLX42/MLX42.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <memory.h>
#define WIDTH 256
#define HEIGHT 256
mlx_image_t *g_img;
void hook(void *param)
{
mlx_t *mlx;
mlx = param;
if (mlx_is_key_down(mlx, MLX_KEY_ESCAPE))
mlx_close_window(mlx);
if (mlx_is_key_down(mlx, MLX_KEY_UP))
g_img->instances[0].y -= 5;
if (mlx_is_key_down(mlx, MLX_KEY_DOWN))
g_img->instances[0].y += 5;
if (mlx_is_key_down(mlx, MLX_KEY_LEFT))
g_img->instances[0].x -= 5;
if (mlx_is_key_down(mlx, MLX_KEY_RIGHT))
g_img->instances[0].x += 5;
}
int32_t main(void)
{
mlx_t *mlx;
mlx = mlx_init(WIDTH, HEIGHT, "MLX42", true);
if (!mlx)
exit(EXIT_FAILURE);
g_img = mlx_new_image(mlx, 128, 128);
memset(g_img->pixels, 255, g_img->width * g_img->height * sizeof(int));
mlx_image_to_window(mlx, g_img, 0, 0);
mlx_loop_hook(mlx, &hook, mlx);
mlx_loop(mlx);
mlx_terminate(mlx);
return (EXIT_SUCCESS);
}

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* font.h :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/02/22 12:42:53 by W2Wizard #+# #+# */
/* Updated: 2022/03/03 13:05:57 by lde-la-h ######## odam.nl */
@ -19,10 +19,10 @@
// GIMP RGBA C-Source image dump (font.c)
static struct s_font
{
uint32_t width;
uint32_t height;
uint32_t bpp;
uint8_t pixels[1140 * 20 * 4 + 1];
uint32_t width;
uint32_t height;
uint32_t bpp;
char* pixels;
} font_atlas = {
1140, 20, 4,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* mlx_font.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/02/22 12:01:37 by W2Wizard #+# #+# */
/* Updated: 2022/06/27 19:53:36 by lde-la-h ######## odam.nl */
@ -31,7 +31,7 @@ static void mlx_draw_char(mlx_image_t* image, int32_t texoffset, int32_t imgoffs
if (texoffset < 0)
return;
uint8_t* pixelx;
char* pixelx;
uint8_t* pixeli;
for (uint32_t y = 0; y < FONT_HEIGHT; y++)
{
@ -65,7 +65,7 @@ mlx_image_t* mlx_put_string(mlx_t* mlx, const char* str, int32_t x, int32_t y)
mlx_image_t* strimage;
const size_t len = strlen(str);
if (len > MLX_MAX_STRING)
return ((void*)mlx_error(MLX_STRTOBIG));
return ((void*)mlx_error(MLX_STRTOOBIG));
if (!(strimage = mlx_new_image(mlx, len * FONT_WIDTH, FONT_HEIGHT)))
return (NULL);

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_cursor.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/01/18 20:10:54 by W2Wizard #+# #+# */
/* Updated: 2022/11/22 08:58:23 by jvan-hal ######## odam.nl */
/* Updated: 2023/03/09 11:11:45 by W2Wizard ######## odam.nl */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
//= Public =//
void* mlx_create_std_cursor(cursor_t type)
mlx_win_cursor_t* mlx_create_std_cursor(cursor_t type)
{
MLX_ASSERT(type >= MLX_CURSOR_ARROW && type < MLX_CURSOR_VRESIZE, "Invalid standard cursor type");
@ -24,17 +24,30 @@ void* mlx_create_std_cursor(cursor_t type)
return ((void *)mlx_error(MLX_MEMFAIL));
}
void* mlx_create_cursor(mlx_texture_t* texture)
mlx_win_cursor_t* mlx_create_cursor(mlx_texture_t* texture)
{
MLX_NONNULL(texture);
GLFWcursor* cursor;
if ((cursor = glfwCreateCursor((GLFWimage*)texture, 0, 0)))
GLFWimage image = (GLFWimage) {
.width = texture->width,
.height = texture->height,
.pixels = texture->pixels
};
if ((cursor = glfwCreateCursor(&image, 0, 0)))
return (cursor);
return ((void *)mlx_error(MLX_MEMFAIL));
}
void mlx_set_cursor(mlx_t* mlx, void* cursor)
void mlx_destroy_cursor(mlx_win_cursor_t* cursor)
{
MLX_NONNULL(cursor);
glfwDestroyCursor(cursor);
}
void mlx_set_cursor(mlx_t* mlx, mlx_win_cursor_t* cursor)
{
MLX_NONNULL(mlx);
MLX_NONNULL(cursor);

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_exit.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/28 02:43:22 by W2Wizard #+# #+# */
/* Updated: 2022/11/26 14:23:55 by jvan-hal ######## odam.nl */
/* Updated: 2023/06/08 18:12:20 by XEDGit ######## odam.nl */
/* */
/* ************************************************************************** */
@ -31,7 +31,7 @@ void mlx_close_window(mlx_t* mlx)
/**
* All of glfw & glads resources are cleaned up by the terminate function.
* Now it's time to cleanup our own mess.
* Now it's time to clean up our own mess.
*/
void mlx_terminate(mlx_t* mlx)
{
@ -39,6 +39,9 @@ void mlx_terminate(mlx_t* mlx)
mlx_ctx_t *const mlxctx = mlx->context;
glUseProgram(0);
glLinkProgram(mlxctx->shaderprogram);
glDeleteProgram(mlxctx->shaderprogram);
glfwTerminate();
mlx_lstclear((mlx_list_t**)(&mlxctx->hooks), &free);
mlx_lstclear((mlx_list_t**)(&mlxctx->render_queue), &free);

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_images.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/01/21 15:34:45 by W2Wizard #+# #+# */
/* Updated: 2022/07/28 18:26:59 by sbos ######## odam.nl */
/* Created: 2021/12/28 02:29:06 by W2Wizard #+# #+# */
/* Updated: 2023/03/30 16:36:39 by ntamayo- ######## odam.nl */
/* */
/* ************************************************************************** */
@ -229,13 +229,23 @@ bool mlx_resize_image(mlx_image_t* img, uint32_t nwidth, uint32_t nheight)
return (mlx_error(MLX_INVDIM));
if (nwidth != img->width || nheight != img->height)
{
uint8_t* tempbuff = realloc(img->pixels, (nwidth * nheight) * BPP);
uint32_t* origin = (uint32_t*)img->pixels;
float wstep = (float)img->width / nwidth;
float hstep = (float)img->height / nheight;
uint8_t* tempbuff = calloc(nwidth * nheight, BPP);
if (!tempbuff)
return (mlx_error(MLX_MEMFAIL));
img->pixels = tempbuff;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nwidth, nheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->pixels);
uint32_t* destin = (uint32_t*)img->pixels;
for (uint32_t j = 0; j < nheight; j++)
for (uint32_t i = 0; i < nwidth; i++)
destin[j * nwidth + i] = origin[(uint32_t)(j * hstep) * img->width + (uint32_t)(i * wstep)];
(*(uint32_t*)&img->width) = nwidth;
(*(uint32_t*)&img->height) = nheight;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nwidth, nheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->pixels);
free(origin);
}
return (true);
}

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_init.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/28 00:24:30 by W2Wizard #+# #+# */
/* Updated: 2022/08/10 13:00:53 by lde-la-h ######## odam.nl */
/* Updated: 2023/06/08 18:16:19 by XEDGit ######## odam.nl */
/* */
/* ************************************************************************** */
@ -68,7 +68,7 @@ static bool mlx_create_buffers(mlx_t* mlx)
}
/**
* Compiles the given shader source code, of a given shader type.
* Compiles the given shader source code of a given shader type.
* Returns shader object via param.
*
* @param code The shader source code.
@ -92,6 +92,7 @@ static uint32_t mlx_compile_shader(const char* code, int32_t type)
{
glGetShaderInfoLog(shader, sizeof(infolog), NULL, infolog);
fprintf(stderr, "%s", infolog);
glDeleteShader(shader);
return (0);
}
return (shader);
@ -112,17 +113,26 @@ static bool mlx_init_render(mlx_t* mlx)
// Load all OpenGL function pointers
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
return (mlx_error(MLX_GLADFAIL));
if (!(vshader = mlx_compile_shader(vert_shader, GL_VERTEX_SHADER)))
return (mlx_error(MLX_VERTFAIL));
if (!(fshader = mlx_compile_shader(frag_shader, GL_FRAGMENT_SHADER)))
return (mlx_error(MLX_FRAGFAIL));
if (!(mlxctx->shaderprogram = glCreateProgram()))
{
glDeleteShader(fshader);
glDeleteShader(vshader);
return (mlx_error(MLX_SHDRFAIL));
}
glAttachShader(mlxctx->shaderprogram, vshader);
glAttachShader(mlxctx->shaderprogram, fshader);
glLinkProgram(mlxctx->shaderprogram);
glDeleteShader(vshader);
glDeleteShader(fshader);
glDetachShader(mlxctx->shaderprogram, vshader);
glDetachShader(mlxctx->shaderprogram, fshader);
int32_t success;
glGetProgramiv(mlxctx->shaderprogram, GL_LINK_STATUS, &success);
if (!success)
@ -131,8 +141,6 @@ static bool mlx_init_render(mlx_t* mlx)
fprintf(stderr, "%s", infolog);
return (mlx_error(MLX_SHDRFAIL));
}
glDeleteShader(vshader);
glDeleteShader(fshader);
glUseProgram(mlxctx->shaderprogram);
for (size_t i = 0; i < 16; i++)
@ -152,9 +160,9 @@ bool sort_queue = false;
mlx_t* mlx_init(int32_t width, int32_t height, const char* title, bool resize)
{
MLX_NONNULL(title);
MLX_ASSERT(width > 0, "Window width must be positive");
MLX_ASSERT(height > 0, "Window height must be positive");
MLX_ASSERT(title, "Window title can't be null");
bool init;
mlx_t* mlx;

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_keys.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/01/01 21:06:45 by W2Wizard #+# #+# */
/* Updated: 2022/06/27 14:28:01 by lde-la-h ######## odam.nl */
/* Updated: 2023/02/13 12:24:40 by W2Wizard ######## odam.nl */
/* */
/* ************************************************************************** */
@ -32,8 +32,8 @@ static void mlx_key_callback(GLFWwindow* window, int32_t key, int32_t scancode,
void mlx_key_hook(mlx_t* mlx, mlx_keyfunc func, void* param)
{
MLX_ASSERT(mlx, "Parameter can't be null");
MLX_ASSERT(func, "Parameter can't be null");
MLX_NONNULL(mlx);
MLX_NONNULL(func);
mlx_ctx_t* mlxctx = mlx->context;
mlxctx->key_hook.func = func;
@ -43,7 +43,7 @@ void mlx_key_hook(mlx_t* mlx, mlx_keyfunc func, void* param)
bool mlx_is_key_down(mlx_t* mlx, keys_t key)
{
MLX_ASSERT(mlx, "Parameter can't be null");
MLX_NONNULL(mlx);
return (glfwGetKey(mlx->window, key) == GLFW_PRESS);
}

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_loop.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/28 01:24:36 by W2Wizard #+# #+# */
/* Updated: 2022/06/27 18:07:04 by lde-la-h ######## odam.nl */
/* Updated: 2023/03/28 16:34:17 by W2Wizard ######## odam.nl */
/* */
/* ************************************************************************** */
@ -42,8 +42,11 @@ static void mlx_render_images(mlx_t* mlx)
while (imglst)
{
mlx_image_t* image;
if (!(image = imglst->content))
return ((void)mlx_error(MLX_INVIMG));
if (!(image = imglst->content)) {
mlx_error(MLX_INVIMG);
return;
}
glBindTexture(GL_TEXTURE_2D, ((mlx_image_ctx_t*)image->context)->texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
imglst = imglst->next;
@ -66,8 +69,8 @@ static void mlx_render_images(mlx_t* mlx)
bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param)
{
MLX_ASSERT(mlx, "Parameter can't be null");
MLX_ASSERT(f, "Parameter can't be null");
MLX_NONNULL(mlx);
MLX_NONNULL(f);
mlx_hook_t* hook;
if (!(hook = malloc(sizeof(mlx_hook_t))))
@ -89,7 +92,7 @@ bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param)
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
void mlx_loop(mlx_t* mlx)
{
MLX_ASSERT(mlx, "Parameter can't be null");
MLX_NONNULL(mlx);
double start, oldstart = 0;
while (!glfwWindowShouldClose(mlx->window))
@ -103,7 +106,7 @@ void mlx_loop(mlx_t* mlx)
glfwGetWindowSize(mlx->window, &(mlx->width), &(mlx->height));
if ((mlx->width > 1 || mlx->height > 1))
mlx_update_matrix(mlx, mlx->width, mlx->height);
mlx_update_matrix(mlx);
mlx_exec_loop_hooks(mlx);
mlx_render_images(mlx);

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* mlx_monitor.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/01/19 17:18:59 by W2Wizard #+# #+# */
/* Updated: 2022/06/27 20:02:38 by lde-la-h ######## odam.nl */

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* mlx_mouse.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/01/01 23:20:13 by W2Wizard #+# #+# */
/* Updated: 2022/06/29 15:34:25 by lde-la-h ######## odam.nl */

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* mlx_put_pixel.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/28 03:30:13 by W2Wizard #+# #+# */
/* Updated: 2022/06/29 16:00:30 by lde-la-h ######## odam.nl */
@ -12,7 +12,7 @@
#include "MLX42/MLX42_Int.h"
// BUG: Linux may experience a red hue instead due to endiannes
// BUG: Linux may experience a red hue instead due to endianness
void mlx_draw_pixel(uint8_t* pixel, uint32_t color)
{
*(pixel++) = (uint8_t)(color >> 24);

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* mlx_window.c :+: :+: */
/* +:+ */
/* By: W2wizard <w2wizzard@gmail.com> +#+ */
/* By: W2wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/02/08 01:14:59 by W2wizard #+# #+# */
/* Updated: 2022/11/22 09:06:54 by jvan-hal ######## odam.nl */
@ -18,7 +18,7 @@
* Recalculate the view projection matrix, used by images for screen pos
* Reference: https://bit.ly/3KuHOu1 (Matrix View Projection)
*/
void mlx_update_matrix(const mlx_t* mlx, int32_t width, int32_t height)
void mlx_update_matrix(const mlx_t* mlx)
{
const mlx_ctx_t* mlxctx = mlx->context;
const float depth = mlxctx->zdepth;
@ -27,8 +27,8 @@ void mlx_update_matrix(const mlx_t* mlx, int32_t width, int32_t height)
* In case the setting to stretch the image is set, we maintain the width and height but not
* the depth.
*/
width = mlx_settings[MLX_STRETCH_IMAGE] ? mlxctx->initialWidth : mlx->width;
height = mlx_settings[MLX_STRETCH_IMAGE] ? mlxctx->initialHeight : mlx->height;
const float width = mlx_settings[MLX_STRETCH_IMAGE] ? mlxctx->initialWidth : mlx->width;
const float height = mlx_settings[MLX_STRETCH_IMAGE] ? mlxctx->initialHeight : mlx->height;
const float matrix[16] = {
2.f / width, 0, 0, 0,
@ -87,7 +87,13 @@ void mlx_set_icon(mlx_t* mlx, mlx_texture_t* image)
MLX_NONNULL(mlx);
MLX_NONNULL(image);
glfwSetWindowIcon(mlx->window, 1, (const GLFWimage*)image);
const GLFWimage icon = {
.width = image->width,
.height = image->height,
.pixels = image->pixels
};
glfwSetWindowIcon(mlx->window, 1, &icon);
}
void mlx_set_window_pos(mlx_t* mlx, int32_t xpos, int32_t ypos)

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* mlx_png.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/02/16 23:11:29 by W2Wizard #+# #+# */
/* Updated: 2022/06/27 19:55:06 by lde-la-h ######## odam.nl */

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_texture.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/02/17 01:02:24 by W2Wizard #+# #+# */
/* Updated: 2022/06/29 15:34:25 by lde-la-h ######## odam.nl */
/* Updated: 2023/03/09 11:03:47 by W2Wizard ######## odam.nl */
/* */
/* ************************************************************************** */
@ -14,66 +14,24 @@
//= Public =//
mlx_image_t* mlx_texture_area_to_image(mlx_t* mlx, mlx_texture_t* texture, uint32_t xy[2], uint32_t wh[2])
{
MLX_NONNULL(mlx);
MLX_NONNULL(texture);
MLX_NONNULL(xy);
MLX_NONNULL(wh);
if (wh[0] > texture->width || wh[1] > texture->height)
return ((void*)mlx_error(MLX_INVDIM));
if (xy[0] > texture->width || xy[1] > texture->height)
return ((void*)mlx_error(MLX_INVPOS));
mlx_image_t* image;
if (!(image = mlx_new_image(mlx, wh[0], wh[1])))
return ((void*)mlx_error(MLX_MEMFAIL));
uint8_t* pixelx;
uint8_t* pixeli;
for (uint32_t y = 0; y < wh[1]; y++)
{
pixelx = &texture->pixels[((xy[1] + y) * texture->width + xy[0]) * BPP];
pixeli = &image->pixels[y * wh[0] * BPP];
memmove(pixeli, pixelx, wh[0] * BPP);
}
return (image);
}
mlx_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture)
{
MLX_NONNULL(mlx);
MLX_NONNULL(texture);
mlx_image_t* img;
const int32_t xy[] = {0, 0};
const uint32_t wh[] = {texture->width, texture->height};
if (!(img = mlx_texture_area_to_image(mlx, texture, (uint32_t*)xy, (uint32_t*)wh)))
mlx_image_t* image = mlx_new_image(mlx, texture->width, texture->height);
if (image == NULL)
return (NULL);
return (img);
}
bool mlx_draw_texture(mlx_image_t* image, mlx_texture_t* texture, uint32_t x, uint32_t y)
{
MLX_NONNULL(image);
MLX_NONNULL(texture);
if (texture->width > image->width || texture->height > image->height)
return (mlx_error(MLX_INVDIM));
if (x > image->width || y > image->height)
return (mlx_error(MLX_INVPOS));
uint8_t* pixelx;
uint8_t* pixeli;
for (uint32_t i = 0; i < texture->height; i++)
{
pixelx = &texture->pixels[(i * texture->width) * texture->bytes_per_pixel];
pixeli = &image->pixels[((i + y) * image->width + x) * texture->bytes_per_pixel];
pixeli = &image->pixels[(i * image->width) * texture->bytes_per_pixel];
memmove(pixeli, pixelx, texture->width * texture->bytes_per_pixel);
}
return (true);
return (image);
}
void mlx_delete_texture(mlx_texture_t* texture)

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* mlx_xpm42.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/28 03:42:29 by W2Wizard #+# #+# */
/* Updated: 2022/06/27 19:58:33 by lde-la-h ######## odam.nl */
@ -14,7 +14,7 @@
/**
* XPM is an obscure image format which can't seem to make up its mind
* wether it wants to be written in C code or not.
* whether it wants to be written in C code or not.
*
* https://en.wikipedia.org/wiki/X_PixMap
*
@ -30,11 +30,11 @@
* as to what does what.
*
* Additionally with the C style format, the idea is that you simply include
* it directly into the compilation of the program (since its just c).
* it directly into the compilation of the program (since it's just C).
*
* As convenient as this is, I just find it hideous especially the XPM3 variant.
* By sticking to the XPM style format, conversion should be very easy and
* straight forward to this format however.
* straightforward to this format however.
*/
//= Private =//
@ -59,13 +59,13 @@ static uint8_t mlx_parse_hex_channel(char* channel)
* @param line The line to parse.
* @param ctable The color hash table.
* @param s Size of the hash table
* @return True or false depending on if it sucessfully parsed the line.
* @return True or false depending on if it successfully parsed the line.
*/
static bool mlx_insert_xpm_entry(xpm_t* xpm, char* line, uint32_t* ctable, size_t s)
{
// NOTE: uintptr because windows likes to complain...
// Verify the length of the Pixel string by checking backwards for the first
// occurence of a space and then check the distance by comparing with cpp.
// occurrence of a space and then check the distance by comparing with cpp.
if (((uintptr_t)strrchr(line, ' ') - (uintptr_t)line) != (uint64_t)xpm->cpp)
return (false);
if (!isspace(line[xpm->cpp]) || line[xpm->cpp + 1] != '#' || !isalnum(line[xpm->cpp + 2]))
@ -91,7 +91,7 @@ static bool mlx_insert_xpm_entry(xpm_t* xpm, char* line, uint32_t* ctable, size_
* @param file The filepath to the XPM42 file.
* @param ctable The color hash table.
* @param s Size of the hash table.
* @return True or false depending on if it sucessfully parsed the line.
* @return True or false depending on if it successfully parsed the line.
*/
static bool mlx_read_data(xpm_t* xpm, FILE* file, uint32_t* ctable, size_t s)
{
@ -123,8 +123,8 @@ static bool mlx_read_data(xpm_t* xpm, FILE* file, uint32_t* ctable, size_t s)
* table with every ascii character in it. This should help avoid a O(n)
* case and give us a O(1) for very fast look ups.
*
* Downside is we still need to iterate of each pixel to solve its color.
* So I hope this makes it atleast a bit faster.
* Downside is we still need to iterate over each pixel to solve its color.
* So I hope this makes it at least a bit faster.
*
* TODO: This buffer might be way to big! Do actual collision checks,
* for now just straight up raw dog this.

View File

@ -1,27 +1,31 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* init_test.c :+: :+: */
/* mlx_comparison.c :+: :+: */
/* +:+ */
/* By: lde-la-h <lde-la-h@student.codam.nl> +#+ */
/* By: jvan-hal <jvan-hal@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/07/18 10:19:40 by lde-la-h #+# #+# */
/* Updated: 2022/08/03 10:28:20 by lde-la-h ######## odam.nl */
/* Created: 2023/01/31 17:20:19 by jvan-hal #+# #+# */
/* Updated: 2023/01/31 17:23:49 by jvan-hal ######## odam.nl */
/* */
/* ************************************************************************** */
#include "Tester.h"
#include "MLX42/MLX42.h"
#include "MLX42/MLX42_Int.h"
int32_t main(void)
//= Private =//
bool mlx_equal_image(void* lstcontent, void* value)
{
TEST_DECLARE("mlx_init");
TEST_EXPECT(PASS);
const mlx_image_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;
mlx_set_setting(MLX_HEADLESS, true);
mlx_t* mlx = mlx_init(32, 32, "TEST", false);
assert(mlx);
assert(mlx_errno == MLX_SUCCESS);
mlx_terminate(mlx);
TEST_EXIT(EXIT_SUCCESS);
return (lcontent == lvalue);
}
bool mlx_equal_inst(void* lstcontent, void* value)
{
const draw_queue_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;
return (lcontent->image == lvalue);
}

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* mlx_error.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/28 02:51:54 by W2Wizard #+# #+# */
/* Updated: 2022/11/22 08:50:15 by jvan-hal ######## odam.nl */
@ -44,11 +44,7 @@ bool mlx_error(mlx_errno_t val)
{
mlx_errno = val;
#ifndef NDEBUG
# ifdef _WIN32
fprintf(stderr, "MLX42: %s", mlx_strerror(mlx_errno));
# else
warnx("MLX42: %s", mlx_strerror(mlx_errno));
# endif
#endif
return (false);
}

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_list.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/28 01:53:51 by W2Wizard #+# #+# */
/* Updated: 2022/11/26 14:26:23 by jvan-hal ######## odam.nl */
/* Updated: 2023/02/27 11:31:01 by W2Wizard ######## odam.nl */
/* */
/* ************************************************************************** */
@ -16,13 +16,10 @@
int32_t mlx_lstsize(mlx_list_t* lst)
{
int32_t i = 0;
int32_t i;
while (lst)
{
i++;
for (i = 0; lst != NULL; i++)
lst = lst->next;
}
return (i);
}
@ -92,23 +89,6 @@ void mlx_lstadd_front(mlx_list_t** lst, mlx_list_t* new)
*lst = new;
}
// TODO: Move this somewhere else...
bool mlx_equal_image(void* lstcontent, void* value)
{
const mlx_image_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;
return (lcontent == lvalue);
}
bool mlx_equal_inst(void* lstcontent, void* value)
{
const draw_queue_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;
return (lcontent->image == lvalue);
}
/**
* Removes the specified content from the list, if found.
* Also fixes any relinking that might be needed.

View File

@ -3,7 +3,7 @@
/* :::::::: */
/* mlx_utils.c :+: :+: */
/* +:+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2022/01/03 20:13:17 by W2Wizard #+# #+# */
/* Updated: 2022/11/22 10:56:09 by jvan-hal ######## odam.nl */
@ -18,12 +18,12 @@
* Function to read a file stream line by line, reusing the same output pointer.
* Since the same output pointer is reused it should only be freed once, either on success or failure.
* This function is made to be somewhat similar to getline.
* Getline can't be used directly since its not standard and therefore not available on all platforms.
* Getline can't be used directly since it's not standard and therefore not available on all platforms.
*
* @param out Pointer to store output string.
* @param out_size Pointer to store output strings length.
* @param file File stream to read from.
* @return True if line was read, false if EOF was reached or an error ocurred.
* @return True if line was read, false if EOF was reached or an error occurred.
*/
bool mlx_getline(char** out, size_t* out_size, FILE* file)
{

View File

@ -1,62 +0,0 @@
# **************************************************************************** #
# #
# :::::::: #
# Makefile :+: :+: #
# +:+ #
# By: lde-la-h <lde-la-h@student.codam.nl> +#+ #
# +#+ #
# Created: 2022/07/19 08:43:31 by lde-la-h #+# #+# #
# Updated: 2022/07/21 10:34:17 by lde-la-h ######## odam.nl #
# #
# **************************************************************************** #
#//= Variables =//#
rwildcard = $(subst \,/,$(sort $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2) $(wildcard $1/$2))))
#//= Colors =//#
BOLD := \033[1m
BLACK := \033[30;1m
RED := \033[31;1m
GREEN := \033[32;1m
YELLOW := \033[33;1m
BLUE := \033[34;1m
MAGENTA := \033[35;1m
CYAN := \033[36;1m
WHITE := \033[37;1m
RESET := \033[0m
NAME := test
SRC_DIR := .
SRCS := $(call rwildcard,$(SRC_DIR),*.c)
OBJS := $(sort $(patsubst %.c,%.o,$(SRCS)))
CFLAGS := -Wextra -Wall -Wunreachable-code -Wno-char-subscripts -Wno-unused-variable
ifeq ($(OS), Windows_NT)
$(error Not supported)
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
MLX_FLAGS := -ldl -lglfw -pthread -lm
else ifeq ($(UNAME_S), Darwin)
MLX_FLAGS := -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit
endif
endif
#//= Recipes =//#
# TODO: Check if any failed and only at the end error!
all: # Redirect to run target
@$(MAKE) -si run
run: mlx $(OBJS)
mlx:
@echo "\033[30;1m[Running tests]\033[0m"
@$(MAKE) -s re DEBUG=1 -C ../
@echo "\n"
%.o: %.c
@gcc $^ -o $(NAME) ../libmlx42.a -I . -I ../include $(MLX_FLAGS) $(CFLAGS) && ./$(NAME)
@rm -rf $(NAME)

View File

@ -1,114 +0,0 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* Tester.h :+: :+: */
/* +:+ */
/* By: lde-la-h <lde-la-h@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/07/18 12:41:32 by lde-la-h #+# #+# */
/* Updated: 2022/07/21 10:41:26 by lde-la-h ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef TESTER_H
#define TESTER_H
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <fcntl.h>
# include <errno.h>
# include <assert.h>
# include <unistd.h>
# include <stdbool.h>
# include <signal.h>
# define READ 0
# define WRITE 1
# define PASS 0
# define FAIL 1
//////////////////////////////////////////////////////////////////////////////////
// TODO: Clean this up ...
static int32_t _fds[2];
static int32_t _expected;
static int32_t _result = -1;
static bool _normalExit;
static const char* _name;
static void printError(void)
{
printf("\r\033[35C\033[31;1m[ERROR] %s\033[0m\n", strerror(errno));
}
static int32_t resolveExitCode(void)
{
return (_result == _expected ? EXIT_SUCCESS : EXIT_FAILURE);
}
void handle(void)
{
static char buff[256] = {0};
// Check result
if (_result != _expected)
{
if (_normalExit)
_result = FAIL;
}
else
_result = PASS;
// If we failed and exit was abnormal
if (_result == FAIL && !_normalExit)
{
ssize_t bread;
if ((bread = read(_fds[READ], buff, sizeof(buff))) < 0)
{
printError();
return;
}
}
// Print result
printf("\r\033[35C%s\n", _result == PASS ? "\033[32;1m[OK]\033[0m" : "\033[31;1m[FAIL]\033[0m");
printf("\033[31;1m%s\033[0m", buff);
}
#define TEST_EXPECT(expect) \
{ _expected = expect; } \
#define TEST_EXIT(code) \
{ _result = code; _normalExit = true; exit(resolveExitCode()); } \
void sighandle(int32_t sig)
{
(void)sig;
_result = (_expected == PASS ? EXIT_FAILURE : EXIT_SUCCESS);
_normalExit = false;
exit(resolveExitCode());
}
// Initialize the function as a test.
#define TEST_DECLARE(Name) \
_name = Name; \
printf("Testing: %s", _name); \
if (pipe(_fds) < 0) { \
printError(); \
exit(EXIT_FAILURE); \
} \
dup2(_fds[WRITE], STDERR_FILENO); \
/* Now redirect the signals! */ \
atexit(handle); \
signal(SIGABRT, sighandle); \
signal(SIGSEGV, sighandle); \
signal(SIGILL, sighandle); \
signal(SIGTERM, sighandle); \
signal(SIGBUS, sighandle); \
#endif
//////////////////////////////////////////////////////////////////////////////////

View File

@ -1,42 +0,0 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* img_del_test.c :+: :+: */
/* +:+ */
/* By: lde-la-h <lde-la-h@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/08/03 09:30:25 by lde-la-h #+# #+# */
/* Updated: 2022/08/03 10:28:27 by lde-la-h ######## odam.nl */
/* */
/* ************************************************************************** */
#include "Tester.h"
#include "MLX42/MLX42.h"
int32_t main(void)
{
TEST_DECLARE("img_del");
TEST_EXPECT(PASS);
mlx_set_setting(MLX_HEADLESS, true);
mlx_t* mlx = mlx_init(32, 32, "TEST", false);
assert(mlx);
mlx_image_t* img = mlx_new_image(mlx, 32, 32);
assert(img);
mlx_image_t* img2 = mlx_new_image(mlx, 32, 32);
assert(img2);
// Display then delete
mlx_image_to_window(mlx, img, 0, 0);
mlx_delete_image(mlx, img);
// Delete
mlx_delete_image(mlx, img2);
// Check errno just to make absolutely sure
assert(mlx_errno == MLX_SUCCESS);
mlx_terminate(mlx);
TEST_EXIT(EXIT_SUCCESS);
}

View File

@ -1,80 +0,0 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* prim_str_draw.c :+: :+: */
/* +:+ */
/* By: lde-la-h <lde-la-h@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/08/03 09:43:26 by lde-la-h #+# #+# */
/* Updated: 2022/08/03 10:30:23 by lde-la-h ######## odam.nl */
/* */
/* ************************************************************************** */
#include "Tester.h"
#include "MLX42/MLX42.h"
bool once = false;
void function(mlx_t* mlx)
{
if (once == false)
{
mlx_image_t* img2 = mlx_new_image(mlx, 64, 24);
memset(img2->pixels, 255, img2->width * img2->height * sizeof(int32_t));
mlx_image_to_window(mlx, img2, 64, 32);
mlx_delete_image(mlx, img2);
}
once = true;
}
// Primitive method of updating a string
void ft_draw(void* param)
{
static char buf[256];
static int32_t count = 0;
static mlx_image_t* img = NULL;
mlx_t *const mlx = param;
//mlx_ctx_t *const mlxctx = mlx->context;
if (img)
mlx_delete_image(mlx, img);
// Cheap itoa
memset(buf, '\0', sizeof(buf));
sprintf(buf, "%d", count);
img = mlx_put_string(mlx, buf, 0, 0);
count++;
// Some function modifies the render queue and image list
function(mlx);
if (count >= 420)
mlx_close_window(mlx);
assert(mlx_errno == MLX_SUCCESS);
}
int32_t main(void)
{
TEST_DECLARE("prim_str_draw");
TEST_EXPECT(PASS);
mlx_set_setting(MLX_HEADLESS, true);
mlx_t* mlx = mlx_init(128, 64, "TEST", false);
assert(mlx);
// Just because we want to do something messed up
mlx_image_t* img2 = mlx_new_image(mlx , 24, 24);
memset(img2->pixels, 255, img2->width * img2->height * sizeof(int32_t));
mlx_image_to_window(mlx, img2, 32, 18);
mlx_image_t* img3 = mlx_new_image(mlx , 24, 24);
memset(img3->pixels, 255, img3->width * img3->height * sizeof(int32_t));
mlx_image_to_window(mlx, img3, 48, 32);
mlx_image_t* img4 = mlx_new_image(mlx , 24, 24);
memset(img4->pixels, 255, img4->width * img4->height * sizeof(int32_t));
mlx_image_to_window(mlx, img4, 32, 48);
mlx_delete_image(mlx, img3);
mlx_loop_hook(mlx, ft_draw, mlx);
mlx_loop(mlx);
assert(mlx_errno == MLX_SUCCESS);
TEST_EXIT(EXIT_SUCCESS);
}

View File

@ -1,37 +0,0 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* put_pixel_test.c :+: :+: */
/* +:+ */
/* By: lde-la-h <lde-la-h@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/07/18 10:19:40 by lde-la-h #+# #+# */
/* Updated: 2022/08/03 10:28:45 by lde-la-h ######## odam.nl */
/* */
/* ************************************************************************** */
#include "Tester.h"
#include "MLX42/MLX42.h"
int32_t main(void)
{
TEST_DECLARE("put_pixel");
mlx_set_setting(MLX_HEADLESS, true);
mlx_t* mlx = mlx_init(32, 32, "TEST", false);
mlx_image_t* img = mlx_new_image(mlx, 32, 32);
assert(mlx_errno == MLX_SUCCESS);
// Test within bounds.
TEST_EXPECT(PASS);
mlx_put_pixel(img, 0, 0, 0xFFFFFFFF);
// Test out of bounds.
TEST_EXPECT(FAIL);
mlx_put_pixel(img, 69, 69, 0xFFFFFFFF);
// Put pixel passed when it should have failed...
mlx_terminate(mlx);
TEST_EXIT(EXIT_FAILURE);
}

40
mlx/tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,40 @@
# -----------------------------------------------------------------------------
# Codam Coding College, Amsterdam @ 2022-2023 by Jelle van Kraaij.
# See README in the root project for more information.
# -----------------------------------------------------------------------------
set(TEST_EXECUTABLE_NAME unit_tests)
# Download GoogleTest
# -----------------------------------------------------------------------------
include(GoogleTest)
include(FetchContent)
FetchContent_Declare(
googletest
DOWNLOAD_EXTRACT_TIMESTAMP
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG v1.13.0
)
FetchContent_MakeAvailable(googletest)
# -----------------------------------------------------------------------------
add_executable(
${TEST_EXECUTABLE_NAME}
tests.cpp
)
target_link_libraries(
${TEST_EXECUTABLE_NAME}
GTest::gtest_main
mlx42
)
set_property(TARGET ${TEST_EXECUTABLE_NAME} PROPERTY CXX_STANDARD 14)
# Add tests to CTest
# Set working directory to the testing folder so that the test can find their test files
# -----------------------------------------------------------------------------
gtest_discover_tests(${TEST_EXECUTABLE_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} TEST_PREFIX "MLX42.")
enable_testing()

View File

@ -0,0 +1,37 @@
// -----------------------------------------------------------------------------
// Codam Coding College, Amsterdam @ 2022-2023 by Jelle van Kraaij.
// See README in the root project for more information.
// -----------------------------------------------------------------------------
# pragma once
# include <gtest/gtest.h>
# include <MLX42/MLX42.h>
class Window : public ::testing::Test
{
protected:
mlx_t* mlx = nullptr;
static constexpr const char* name = "MLX42";
static const int32_t height = 400;
static const int32_t width = 400;
inline void SetUp() override
{
// reset error code as it is shared between tests
mlx_errno = MLX_SUCCESS;
mlx_set_setting(MLX_HEADLESS, true);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
mlx = mlx_init(width, height, name, false);
ASSERT_NE(mlx, nullptr);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
}
inline void TearDown() override
{
ASSERT_NE(mlx, nullptr);
mlx_terminate(mlx);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
}
};

139
mlx/tests/tests.cpp Normal file
View File

@ -0,0 +1,139 @@
// -----------------------------------------------------------------------------
// Codam Coding College, Amsterdam @ 2022-2023 by Jelle van Kraaij.
// See README in the root project for more information.
// -----------------------------------------------------------------------------
// If your new to gtest follow the following documentation:
// http://google.github.io/googletest/primer.html
#include "WindowFixture.hpp"
// --------------------------------------------
// Fixture for window tests
// For every TEST_F(window, ...) the SetUp() and TearDown() functions are called
// MLX can be accessed via the mlx variable in each test
// For the implementation of the fixture see tests/windowFixture.hpp
// --------------------------------------------
TEST_F(Window, Basic)
{
// Basic window is already tested in the fixture
}
// NOTE: This test cannot be run with a fixture because the settings need to be set before the window is created
TEST(MWindow, Settings)
{
mlx_errno = MLX_SUCCESS;
mlx_set_setting(MLX_STRETCH_IMAGE, true);
mlx_set_setting(MLX_MAXIMIZED, true);
mlx_set_setting(MLX_DECORATED, true);
mlx_set_setting(MLX_FULLSCREEN, true);
mlx_set_setting(MLX_HEADLESS, true);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
mlx_t *mlx = mlx_init(400, 400, "MLX42", false);
ASSERT_NE(mlx, nullptr);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
mlx_terminate(mlx);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
// Set all settings to default
mlx_set_setting(MLX_STRETCH_IMAGE, false);
mlx_set_setting(MLX_FULLSCREEN, false);
mlx_set_setting(MLX_MAXIMIZED, false);
mlx_set_setting(MLX_DECORATED, true);
}
TEST_F(Window, SingleImage)
{
mlx_image_t* img = mlx_new_image(mlx, Window::width / 2, Window::height / 2);
ASSERT_NE(img, nullptr);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
int32_t val = mlx_image_to_window(mlx, img, Window::width / 4 , Window::height / 4);
EXPECT_GE(val, 0);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
mlx_delete_image(mlx, img);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
}
TEST_F(Window, MultipleImages)
{
mlx_image_t* img1 = mlx_new_image(mlx, Window::width / 2, Window::height / 2);
ASSERT_NE(img1, nullptr);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
mlx_image_t* img2 = mlx_new_image(mlx, Window::width, Window::height);
ASSERT_NE(img2, nullptr);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
int32_t val1 = mlx_image_to_window(mlx, img1, Window::width / 4, Window::height / 4);
EXPECT_GE(val1, 0);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
int32_t val2 = mlx_image_to_window(mlx, img2, 0, 0);
EXPECT_GE(val2, 0);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
mlx_delete_image(mlx, img1);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
mlx_delete_image(mlx, img2);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
}
static void ft_draw(void* param)
{
static char buf[256];
static int32_t count = 0;
static mlx_image_t* img = nullptr;
mlx_t* mlx = (mlx_t*)param;
if (img == nullptr)
{
mlx_delete_image(mlx, img);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
}
// Cheap itoa lol
memset(buf, '\0', sizeof(buf));
snprintf(buf, sizeof(buf), "%d", count);
img = mlx_put_string(mlx, buf, 0, 0);
ASSERT_NE(img, nullptr);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
if (count >= 420)
{
mlx_close_window(mlx);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
}
count++;
}
TEST_F(Window, stringTortureTest)
{
mlx_image_t *img = mlx_new_image(mlx, Window::width / 2, Window::height / 2);
ASSERT_NE(img, nullptr);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
memset(img->pixels, 255, sizeof(int32_t) * img->width * img->height);
int32_t val_window = mlx_image_to_window(mlx, img, Window::width / 4 , Window::height / 4);
EXPECT_GE(val_window, 0);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
bool val_hook = mlx_loop_hook(mlx, ft_draw, mlx);
EXPECT_EQ(val_hook, true);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
mlx_loop(mlx);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
mlx_delete_image(mlx, img);
ASSERT_EQ(mlx_errno, MLX_SUCCESS);
}

30
mlx/tools/compile_shader.bat Normal file → Executable file
View File

@ -1,14 +1,7 @@
:: ************************************************************************** ::
:: ::
:: :::::::: ::
:: compile_shader.bat :+: :+: ::
:: +:+ ::
:: By: fbes <fbes@student.codam.nl> +#+ ::
:: +#+ ::
:: Created: 2022/03/07 16:24:06 by fbes #+# #+# ::
:: Updated: 2022/03/07 18:12:51 by fbes ######## odam.nl ::
:: ::
:: ************************************************************************** ::
:: -----------------------------------------------------------------------------
:: Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
:: See README in the root project for more information.
:: -----------------------------------------------------------------------------
@echo off
SETLOCAL DisableDelayedExpansion
@ -22,17 +15,10 @@ IF NOT EXIST %1 GOTO fnotfound
SET SHADERTYPE=%~x1
SET SHADERTYPE=%SHADERTYPE:~1%
echo /* ************************************************************************** */
echo /* */
echo /* :::::::: */
echo /* lol.c :+: :+: */
echo /* +:+ */
echo /* By: W2wizard ^<lde-la-h@student.codam.nl^> +#+ */
echo /* +#+ */
echo /* Created: 2022/02/17 22:34:59 by W2wizard #+# #+# */
echo /* Updated: 2022/02/17 22:34:59 by W2wizard ######## odam.nl */
echo /* */
echo /* ************************************************************************** */
echo // -----------------------------------------------------------------------------
echo // Codam Coding College, Amsterdam @ <2022-2023> by W2Wizard.
echo // See README in the root project for more information.
echo // -----------------------------------------------------------------------------
echo.
echo // If you wish to modify this file edit the .vert or .frag file!
echo.

32
mlx/tools/compile_shader.sh Normal file → Executable file
View File

@ -1,15 +1,8 @@
#!/bin/bash
# **************************************************************************** #
# #
# :::::::: #
# compile_shader.sh :+: :+: #
# +:+ #
# By: fbes <fbes@student.codam.nl> +#+ #
# +#+ #
# Created: 2022/03/03 02:38:19 by fbes #+# #+# #
# Updated: 2022/03/15 20:34:51 by lde-la-h ######## odam.nl #
# #
# **************************************************************************** #
# -----------------------------------------------------------------------------
# Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
# See README in the root project for more information.
# -----------------------------------------------------------------------------
# If no arguments have been given, exit with error code 1
if [ "$#" -ne 1 ]; then
@ -25,23 +18,16 @@ fi
SHADERTYPE="${1##*.}"
echo "/* ************************************************************************** */"
echo "/* */"
echo "/* :::::::: */"
echo "/* lol.c :+: :+: */"
echo "/* +:+ */"
echo "/* By: W2wizard <lde-la-h@student.codam.nl> +#+ */"
echo "/* +#+ */"
echo "/* Created: 2022/02/17 22:34:59 by W2wizard #+# #+# */"
echo "/* Updated: 2022/02/17 22:34:59 by W2wizard ######## odam.nl */"
echo "/* */"
echo "/* ************************************************************************** */"
echo "// -----------------------------------------------------------------------------"
echo "// Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard. "
echo "// See README in the root project for more information. "
echo "// -----------------------------------------------------------------------------"
echo ""
echo "// If you wish to modify this file edit the .vert or .frag file!"
echo ""
echo "#include \"MLX42/MLX42_Int.h\""
echo ""
echo "const char* ${SHADERTYPE}_shader = \"$(sed -n '1{p;q;}' $1)\\n\""
echo "const char* ${SHADERTYPE}_shader = \"$(sed -n '1{p;q;}' "$1")\\n\""
{
# Skip over first line
read

3
mlx/tools/xpm3_conv.py Normal file → Executable file
View File

@ -12,7 +12,7 @@
import sys
# This script takes an XPM3 as argument and outputs it to XPM42.
# This script takes an XPM3 as argument and converts it to XPM42.
# This is a generated dictionary from the XFree86 distribution.
colours = {
@ -811,6 +811,5 @@ def main():
temp = l[1:-3] + "\n"
newxpm42.write(temp)
if __name__ == "__main__":
main()