Upgrades
@@ -1,7 +1,7 @@
|
||||
NO assets/textures/wallTlou.png
|
||||
SO assets/textures/wallTlou.png
|
||||
WE assets/textures/wallTlou.png
|
||||
EA assets/textures/wallTlou.png
|
||||
NO assets/textures/norte.png
|
||||
SO assets/textures/sur.png
|
||||
WE assets/textures/este.png
|
||||
EA assets/textures/oeste.png
|
||||
|
||||
C 164,157,79
|
||||
F 30,55,55
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
EA assets/textures/wallTlou.png
|
||||
F 30,55,55
|
||||
C 255,255,255
|
||||
|
||||
EA assets/textures/wallTlou.png
|
||||
NO assets/textures/wallTlou.png
|
||||
SO assets/textures/wallTlou.png
|
||||
WE assets/textures/wallTlou.png
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
EA assets/textures/wallTlou.png
|
||||
F 30,55,55
|
||||
C 255,255,255
|
||||
|
||||
NO assets/textures/wallTlou.png
|
||||
SO assets/textures/wallTlou.png
|
||||
WE assets/textures/wallTlou.png
|
||||
|
||||
1111111111111111111111111111
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000E00000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1111111111111111111111111111
|
||||
BIN
assets/textures/este.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
assets/textures/forest.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
assets/textures/norte.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
assets/textures/oeste.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
assets/textures/sur.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
@@ -1,16 +0,0 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{js,jsx,ts,tsx,css,scss,html,svelte,postcss,glsl,c,h}]
|
||||
indent_size = 2
|
||||
indent_style = tab
|
||||
trim_trailing_whitespace = true
|
||||
0
lib/mlx/.gitattributes
vendored
Executable file → Normal file
0
lib/mlx/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Executable file → Normal file
0
lib/mlx/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Executable file → Normal file
0
lib/mlx/.github/workflows/ci.yml
vendored
Executable file → Normal file
38
lib/mlx/.github/workflows/wasm.yml
vendored
@@ -1,38 +0,0 @@
|
||||
# Simple workflow for deploying static content to GitHub Pages
|
||||
name: Deploy static content to Pages
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
||||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: false
|
||||
|
||||
# Single deploy job since we're just deploying
|
||||
jobs:
|
||||
deploy:
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
runs-on: ubuntu-latest
|
||||
#TODO: add a build step to get the wasm file instead of commiting it.
|
||||
#Doesn't really matter atm since the git history is polluted anyway
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v5
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: './web'
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
0
lib/mlx/.gitignore
vendored
Executable file → Normal file
113
lib/mlx/CMakeLists.txt
Executable file → Normal file
@@ -5,8 +5,8 @@
|
||||
|
||||
# CMake specifications
|
||||
# -----------------------------------------------------------------------------
|
||||
cmake_minimum_required (VERSION 3.16.0)
|
||||
project(mlx42 VERSION 2.4.2)
|
||||
cmake_minimum_required (VERSION 3.18.0)
|
||||
project(mlx42 VERSION 2.3.3)
|
||||
message(STATUS "MLX42 @ ${CMAKE_PROJECT_VERSION}")
|
||||
|
||||
# Variables
|
||||
@@ -23,11 +23,9 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
||||
|
||||
# Options
|
||||
# -----------------------------------------------------------------------------
|
||||
option(BUILD_SHARED_LIBS "Build mlx42 as a shared library." OFF)
|
||||
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")
|
||||
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
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -36,13 +34,14 @@ set(BUILD_TESTS OFF CACHE BOOL "Build the tests to verify the integrity of the l
|
||||
add_definitions(-D LODEPNG_NO_COMPILE_ENCODER)
|
||||
add_definitions(-D LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS)
|
||||
|
||||
if(UNIX AND NOT EMSCRIPTEN)
|
||||
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
|
||||
@@ -55,55 +54,40 @@ if(UNIX AND NOT EMSCRIPTEN)
|
||||
else()
|
||||
message(STATUS "Building in RELEASE mode")
|
||||
add_definitions(-D NDEBUG)
|
||||
add_compile_options(-O3)
|
||||
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
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if (UNIX)
|
||||
set(CCSHADER ${TOOLS_DIR}/compile_shader.sh)
|
||||
else()
|
||||
set(CCSHADER ${TOOLS_DIR}/compile_shader.bat)
|
||||
endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
set(EMSCRIPTEN_VALUE 1)
|
||||
else()
|
||||
set(EMSCRIPTEN_VALUE 0)
|
||||
endif()
|
||||
|
||||
# Add custom command for fragment shader
|
||||
add_custom_command(
|
||||
COMMENT "Building fragment shader"
|
||||
DEPENDS ${PROJECT_SOURCE_DIR}/shaders/default.frag
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mlx_frag_shader.c
|
||||
COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR}/shaders/default.frag ${EMSCRIPTEN_VALUE} > ${CMAKE_CURRENT_BINARY_DIR}/mlx_frag_shader.c
|
||||
VERBATIM
|
||||
PRE_BUILD
|
||||
USES_TERMINAL
|
||||
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 for vertex shader
|
||||
add_custom_command(
|
||||
COMMENT "Building vertex shader"
|
||||
DEPENDS ${PROJECT_SOURCE_DIR}/shaders/default.vert
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mlx_vert_shader.c
|
||||
COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR}/shaders/default.vert ${EMSCRIPTEN_VALUE} > ${CMAKE_CURRENT_BINARY_DIR}/mlx_vert_shader.c
|
||||
VERBATIM
|
||||
PRE_BUILD
|
||||
USES_TERMINAL
|
||||
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
|
||||
# -----------------------------------------------------------------------------
|
||||
# The library type is now determined by the BUILD_SHARED_LIBS option.
|
||||
# By default, it builds a STATIC library.
|
||||
add_library(mlx42 # Changed from "add_library(mlx42 STATIC"
|
||||
add_library(mlx42 STATIC
|
||||
|
||||
# Root
|
||||
${SOURCE_DIR}/mlx_cursor.c
|
||||
@@ -138,45 +122,32 @@ add_library(mlx42 # Changed from "add_library(mlx42 STATIC"
|
||||
)
|
||||
target_include_directories(mlx42 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
# Add this block to control symbol visibility for shared library builds
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set_target_properties(mlx42 PROPERTIES
|
||||
C_VISIBILITY_PRESET hidden
|
||||
CXX_VISIBILITY_PRESET hidden
|
||||
)
|
||||
target_compile_definitions(mlx42 PRIVATE MLX42_BUILD_SHARED)
|
||||
endif()
|
||||
|
||||
|
||||
# Dependencies
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
find_package(glfw3)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
target_link_libraries(mlx42 "-s USE_GLFW=3" "-s FULL_ES3=1")
|
||||
else()
|
||||
target_link_libraries(mlx42 OpenGL::GL)
|
||||
find_package(glfw3)
|
||||
if (glfw3_FOUND)
|
||||
target_link_libraries(mlx42 ${GLFW3_LIBRARY})
|
||||
endif()
|
||||
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(APPLE)
|
||||
target_link_libraries(mlx42 "-framework Cocoa" "-framework IOKit")
|
||||
endif()
|
||||
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
|
||||
# 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
|
||||
|
||||
|
||||
0
lib/mlx/CODE_OF_CONDUCT.md
Executable file → Normal file
0
lib/mlx/CONTRIBUTING.md
Executable file → Normal file
0
lib/mlx/LICENSE
Executable file → Normal file
19
lib/mlx/README.md
Executable file → Normal file
@@ -16,9 +16,6 @@ MLX42 is a performant, easy to use, cross-platform, minimal windowing graphics l
|
||||
|
||||
It provides primitive tools to draw textures onto the window as well as modifying them at runtime as they get displayed on the window.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> At times it may seem like no updates have taken place for a long time. This is expected, the project / lib is considered completed and requires minimal updates. Bug fixes are still guaranteed and the project is still being actively maintained.
|
||||
|
||||
# Features ✨
|
||||
|
||||
MLX42 comes with a plethora of features that make using it actually a joy instead of a chore.
|
||||
@@ -42,14 +39,6 @@ It is built on OpenGL and uses batched rendering to speed up the rendering proce
|
||||
## 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.
|
||||
|
||||
## Emscripten Compatibility 🚀
|
||||
MLX42 introduces compatibility with [Emscripten](https://emscripten.org/), allowing MLX42 to run in web browsers through WebAssembly. This modification were made possible thanks to [@PepeLevi](https://github.com/PepeLevi/MLX42_emcc), credits to him for his fork and contributions.
|
||||
|
||||
### Highlights
|
||||
- **Emscripten Support**: Compile MLX42 with Emscripten, enabling graphical applications to run in a web environment.
|
||||
- **WebAssembly Compatibility**: Ensures that MLX42 can be utilized in modern web browsers, expanding its usability beyond traditional desktop environments.
|
||||
- **Updated Documentation**: Provided guidance on how to build and run MLX42 projects using Emscripten.
|
||||
|
||||
---
|
||||
|
||||
## Installation 🏗️
|
||||
@@ -117,14 +106,6 @@ You can pass build [options](./docs/index.md#available-options) to cmake, e.g: `
|
||||
|
||||
You can find an example makefile in the documentation [here](https://github.com/codam-coding-college/MLX42/blob/master/docs/Basics.md).
|
||||
|
||||
#### Bindings (Python, etc)
|
||||
MLX42 currently has a [Python FFI binding](./ffi/python/README.md) available.
|
||||
In order to get it working you need to build the library first as shown above.
|
||||
The only change is that you need to enable the option `BUILD_SHARED_LIBS` when building with cmake:
|
||||
```bash
|
||||
cmake -B build -DBUILD_SHARED_LIBS=ON && cmake --build build --parallel
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
## For MacOS:
|
||||
|
||||
0
lib/mlx/SECURITY.md
Executable file → Normal file
0
lib/mlx/cmake/Findglfw3.cmake
Executable file → Normal file
0
lib/mlx/cmake/LinkGLFW.cmake
Executable file → Normal file
2
lib/mlx/docs/42.md
Executable file → Normal file
@@ -47,7 +47,7 @@ It addresses one of the main problems at 42, which is that although it is a tech
|
||||
| Le Havre | ✅ | |
|
||||
| Vienna | ❓ | |
|
||||
| Seoul | ❌ | I didn't really understand why but basically as long as Paris says no they will too |
|
||||
| Madrid | ✅ | Authorized since the Linux migration |
|
||||
| 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|
|
||||
|
||||
0
lib/mlx/docs/Basics.md
Executable file → Normal file
0
lib/mlx/docs/Colors.md
Executable file → Normal file
0
lib/mlx/docs/Functions.md
Executable file → Normal file
0
lib/mlx/docs/Hooks.md
Executable file → Normal file
0
lib/mlx/docs/Images.md
Executable file → Normal file
0
lib/mlx/docs/Input.md
Executable file → Normal file
0
lib/mlx/docs/Shaders.md
Executable file → Normal file
0
lib/mlx/docs/Textures.md
Executable file → Normal file
0
lib/mlx/docs/XPM42.md
Executable file → Normal file
0
lib/mlx/docs/assets/demo.gif
Executable file → Normal file
|
Before Width: | Height: | Size: 4.7 MiB After Width: | Height: | Size: 4.7 MiB |
0
lib/mlx/docs/assets/logo.png
Executable file → Normal file
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 75 KiB |
0
lib/mlx/docs/index.md
Executable file → Normal file
216
lib/mlx/ffi/python/.gitignore
vendored
@@ -1,216 +0,0 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[codz]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
# Pipfile.lock
|
||||
|
||||
# UV
|
||||
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# uv.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
# poetry.lock
|
||||
# poetry.toml
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
||||
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
||||
# pdm.lock
|
||||
# pdm.toml
|
||||
.pdm-python
|
||||
.pdm-build/
|
||||
|
||||
# pixi
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
||||
# pixi.lock
|
||||
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
||||
# in the .venv directory. It is recommended not to include this directory in version control.
|
||||
.pixi
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# Redis
|
||||
*.rdb
|
||||
*.aof
|
||||
*.pid
|
||||
|
||||
# RabbitMQ
|
||||
mnesia/
|
||||
rabbitmq/
|
||||
rabbitmq-data/
|
||||
|
||||
# ActiveMQ
|
||||
activemq-data/
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.envrc
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
# .idea/
|
||||
|
||||
# Abstra
|
||||
# Abstra is an AI-powered process automation framework.
|
||||
# Ignore directories containing user credentials, local state, and settings.
|
||||
# Learn more at https://abstra.io/docs
|
||||
.abstra/
|
||||
|
||||
# Visual Studio Code
|
||||
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
||||
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
||||
# you could uncomment the following to ignore the entire vscode folder
|
||||
# .vscode/
|
||||
|
||||
# Ruff stuff:
|
||||
.ruff_cache/
|
||||
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
# Marimo
|
||||
marimo/_static/
|
||||
marimo/_lsp/
|
||||
__marimo__/
|
||||
|
||||
# Streamlit
|
||||
.streamlit/secrets.toml
|
||||
@@ -1,30 +0,0 @@
|
||||
# Python Bindings for MLX42
|
||||
|
||||
This directory contains Python bindings for the MLX42 graphics library, allowing you to use MLX42 functionalities in Python applications (using ^=3.13).
|
||||
|
||||
## Building
|
||||
|
||||
```bash
|
||||
git clone https://github.com/codam-coding-college/MLX42.git
|
||||
cd MLX42
|
||||
cmake -B build -DBUILD_SHARED_LIBS=ON && cmake --build build --parallel
|
||||
```
|
||||
|
||||
Within MLX42's root directory, there is an example script located at `ffi/python/example.py`.
|
||||
You can run this script to see how to use the Python bindings:
|
||||
|
||||
In case you have a static library (`libmlx42.a`), you can create a shared library from it using `clang` or `gcc`:
|
||||
```bash
|
||||
clang -shared -o libmlx42.so libmlx42.a
|
||||
```
|
||||
|
||||
Afterwards, place the shared library in the `ffi/python/` directory:
|
||||
```bash
|
||||
# You can also move the shared library onto a system path
|
||||
mv build/libmlx42.so ffi/python/libmlx42.so
|
||||
cd ffi/python
|
||||
python3 example.py
|
||||
```
|
||||
|
||||
# Example Output
|
||||

|
||||
@@ -1,89 +0,0 @@
|
||||
# ============================================================================
|
||||
# Codam Coding College, Amsterdam 2018-2025, All Rights Reserved.
|
||||
# See README in the root project for more information.
|
||||
# ============================================================================
|
||||
|
||||
import signal
|
||||
import logging
|
||||
import random
|
||||
from libmlx import *
|
||||
|
||||
# ============================================================================
|
||||
|
||||
WIDTH = 512
|
||||
HEIGHT = 512
|
||||
|
||||
# ============================================================================
|
||||
|
||||
def ft_pixel(r, g, b, a):
|
||||
""" Packs RGBA values into a single 32-bit integer. """
|
||||
return (r << 24) | (g << 16) | (b << 8) | a
|
||||
|
||||
@mlx_loop_hook_func
|
||||
def ft_randomize(param):
|
||||
for i in range(image.contents.width):
|
||||
for y in range(image.contents.height):
|
||||
color = ft_pixel(
|
||||
random.randint(0, 255), # R
|
||||
random.randint(0, 255), # G
|
||||
random.randint(0, 255), # B
|
||||
random.randint(0, 255) # A
|
||||
)
|
||||
mlx.mlx_put_pixel(image, i, y, color)
|
||||
|
||||
@mlx_loop_hook_func
|
||||
def ft_hook(param):
|
||||
mlx_ptr = ctypes.cast(param, ctypes.POINTER(mlx_t))
|
||||
if mlx.mlx_is_key_down(mlx_ptr, MLX_KEY_ESCAPE):
|
||||
mlx.mlx_close_window(mlx_ptr)
|
||||
if mlx.mlx_is_key_down(mlx_ptr, MLX_KEY_UP):
|
||||
image.contents.instances[0].y -= 5
|
||||
if mlx.mlx_is_key_down(mlx_ptr, MLX_KEY_DOWN):
|
||||
image.contents.instances[0].y += 5
|
||||
if mlx.mlx_is_key_down(mlx_ptr, MLX_KEY_LEFT):
|
||||
image.contents.instances[0].x -= 5
|
||||
if mlx.mlx_is_key_down(mlx_ptr, MLX_KEY_RIGHT):
|
||||
image.contents.instances[0].x += 5
|
||||
|
||||
def main():
|
||||
# Better to encapsulate in a class, but keeping it simple for the example
|
||||
global image
|
||||
global mlx_ptr
|
||||
|
||||
# Initialize MLX
|
||||
mlx_ptr = mlx.mlx_init(500, 800, b"MLX42 Python Example", True)
|
||||
if not mlx_ptr:
|
||||
logging.critical(f"Error: {mlx.mlx_strerror(mlx.mlx_get_errno()).decode()}")
|
||||
exit(1)
|
||||
|
||||
# Create a new image
|
||||
image = mlx.mlx_new_image(mlx_ptr, 128, 128)
|
||||
if not image:
|
||||
mlx.mlx_close_window(mlx_ptr)
|
||||
logging.critical(f"Error: {mlx.mlx_strerror(mlx.mlx_get_errno()).decode()}")
|
||||
exit(1)
|
||||
|
||||
# Display the image in the window
|
||||
if mlx.mlx_image_to_window(mlx_ptr, image, 0, 0) == -1:
|
||||
mlx.mlx_delete_image(mlx_ptr, image)
|
||||
mlx.mlx_close_window(mlx_ptr)
|
||||
logging.critical(f"Error: {mlx.mlx_strerror(mlx.mlx_get_errno()).decode()}")
|
||||
exit(1)
|
||||
|
||||
mlx.mlx_loop_hook(mlx_ptr, ft_randomize, ctypes.cast(mlx_ptr, c_void_p))
|
||||
mlx.mlx_loop_hook(mlx_ptr, ft_hook, ctypes.cast(mlx_ptr, c_void_p))
|
||||
|
||||
mlx.mlx_loop(mlx_ptr)
|
||||
mlx.mlx_terminate(mlx_ptr)
|
||||
|
||||
# When receiving SIGINT (Ctrl+C), terminate MLX properly
|
||||
# Otherwise we get issues related to callbacks as MLX is trying
|
||||
# invoke it during termination.
|
||||
def signal_handler(sig, frame):
|
||||
mlx.mlx_terminate(mlx_ptr)
|
||||
|
||||
# ============================================================================
|
||||
|
||||
if __name__ == "__main__":
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
main()
|
||||
@@ -1,334 +0,0 @@
|
||||
# ============================================================================
|
||||
# Codam Coding College, Amsterdam 2018-2025, All Rights Reserved.
|
||||
# See README in the root project for more information.
|
||||
# ============================================================================
|
||||
# Python FFI bindings for MLX42
|
||||
# ============================================================================
|
||||
# This module provides Python bindings to the MLX42 graphics library using
|
||||
# the ctypes library. It handles loading the appropriate shared library based
|
||||
# on the operating system and defines necessary types, constants, and function
|
||||
# prototypes for interacting with MLX42.
|
||||
# ============================================================================
|
||||
|
||||
import ctypes
|
||||
from os import path
|
||||
from logging import critical
|
||||
from platform import system
|
||||
|
||||
# ============================================================================
|
||||
|
||||
try: # Load FFI Library
|
||||
lib = 'libmlx42'
|
||||
system = system()
|
||||
if system == "Linux":
|
||||
lib_name = f"{lib}.so"
|
||||
elif system == "Darwin":
|
||||
lib_name = f"{lib}.dylib"
|
||||
elif system == "Windows":
|
||||
lib_name = f"{lib}.dll"
|
||||
else:
|
||||
raise RuntimeError("Unsupported operating system")
|
||||
# Check if in the current working directory first
|
||||
if path.exists(f"./{lib_name}"):
|
||||
mlx = ctypes.CDLL(f"./{lib_name}")
|
||||
else:
|
||||
mlx = ctypes.CDLL(lib_name)
|
||||
except OSError as e:
|
||||
critical(f"Could not load the MLX42 library '{lib_name}'.")
|
||||
critical(e)
|
||||
exit(1)
|
||||
|
||||
# Type Definitions, Constants, and Enums
|
||||
# ============================================================================
|
||||
|
||||
c_int32 = ctypes.c_int32
|
||||
c_uint32 = ctypes.c_uint32
|
||||
c_uint8 = ctypes.c_uint8
|
||||
c_size_t = ctypes.c_size_t
|
||||
c_bool = ctypes.c_bool
|
||||
c_double = ctypes.c_double
|
||||
c_char_p = ctypes.c_char_p
|
||||
c_void_p = ctypes.c_void_p
|
||||
|
||||
# keys_t
|
||||
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
|
||||
|
||||
# cursor_t
|
||||
MLX_CURSOR_ARROW = 0x00036001
|
||||
MLX_CURSOR_IBEAM = 0x00036002
|
||||
MLX_CURSOR_CROSSHAIR = 0x00036003
|
||||
MLX_CURSOR_HAND = 0x00036004
|
||||
MLX_CURSOR_HRESIZE = 0x00036005
|
||||
MLX_CURSOR_VRESIZE = 0x00036006
|
||||
|
||||
# mouse_mode_t
|
||||
MLX_MOUSE_NORMAL = 0x00034001
|
||||
MLX_MOUSE_HIDDEN = 0x00034002
|
||||
MLX_MOUSE_DISABLED = 0x00034003
|
||||
|
||||
# mouse_key_t
|
||||
MLX_MOUSE_BUTTON_LEFT = 0
|
||||
MLX_MOUSE_BUTTON_RIGHT = 1
|
||||
MLX_MOUSE_BUTTON_MIDDLE = 2
|
||||
|
||||
# modifier_key_t
|
||||
MLX_SHIFT = 0x0001
|
||||
MLX_CONTROL = 0x0002
|
||||
MLX_ALT = 0x0004
|
||||
MLX_SUPERKEY = 0x0008
|
||||
MLX_CAPSLOCK = 0x0010
|
||||
MLX_NUMLOCK = 0x0020
|
||||
|
||||
MLX_RELEASE = 0
|
||||
MLX_PRESS = 1
|
||||
MLX_REPEAT = 2
|
||||
|
||||
MLX_STRETCH_IMAGE = 0, # Should images resize with the window as it's being resized or not. Default: false
|
||||
MLX_FULLSCREEN = 1, # Should the window be in Fullscreen, note it will fullscreen at the given resolution. Default: false
|
||||
MLX_MAXIMIZED = 2, # Start the window in a maximized state, overwrites the fullscreen state if this is true. Default: false
|
||||
MLX_DECORATED = 3, # Have the window be decorated with a window bar. Default: true
|
||||
MLX_HEADLESS = 4, # Run in headless mode, no window is created. (NOTE: Still requires some form of window manager such as xvfb)
|
||||
MLX_SETTINGS_MAX = 5, # Setting count.
|
||||
|
||||
# Structures
|
||||
# ============================================================================
|
||||
|
||||
class mlx_texture_t(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("width", c_uint32),
|
||||
("height", c_uint32),
|
||||
("bytes_per_pixel", c_uint8),
|
||||
("pixels", ctypes.POINTER(c_uint8))
|
||||
]
|
||||
|
||||
class mlx_instance_t(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("x", c_int32),
|
||||
("y", c_int32),
|
||||
("z", c_int32),
|
||||
("enabled", c_bool)
|
||||
]
|
||||
|
||||
class xpm_t(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("texture", mlx_texture_t),
|
||||
("color_count", c_int32),
|
||||
("cpp", c_int32),
|
||||
("mode", ctypes.c_char)
|
||||
]
|
||||
|
||||
class mlx_key_data_t(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("key", c_int32), # ENUM
|
||||
("action", c_int32), # ENUM
|
||||
("os_key", c_int32),
|
||||
("modifier", c_int32) # ENUM
|
||||
]
|
||||
|
||||
class mlx_image_t(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("width", c_uint32),
|
||||
("height", c_uint32),
|
||||
("pixels", ctypes.POINTER(c_uint8)),
|
||||
("instances", ctypes.POINTER(mlx_instance_t)),
|
||||
("count", c_size_t),
|
||||
("enabled", c_bool),
|
||||
("context", c_void_p)
|
||||
]
|
||||
|
||||
class mlx_instance_t(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("x", c_int32),
|
||||
("y", c_int32),
|
||||
("z", c_int32),
|
||||
("enabled", c_bool)
|
||||
]
|
||||
|
||||
class mlx_t(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("window", c_void_p),
|
||||
("context", c_void_p),
|
||||
("width", c_int32),
|
||||
("height", c_int32),
|
||||
("delta_time", c_double)
|
||||
]
|
||||
|
||||
# Function Callbacks
|
||||
# ============================================================================
|
||||
|
||||
mlx_scrollfunc = ctypes.CFUNCTYPE(None, c_double, c_double, c_void_p)
|
||||
mlx_mousefunc = ctypes.CFUNCTYPE(None, c_int32, c_int32, c_int32, c_void_p)
|
||||
mlx_cursorfunc = ctypes.CFUNCTYPE(None, c_double, c_double, c_void_p)
|
||||
mlx_keyfunc = ctypes.CFUNCTYPE(None, mlx_key_data_t, c_void_p)
|
||||
mlx_resizefunc = ctypes.CFUNCTYPE(None, c_int32, c_int32, c_void_p)
|
||||
mlx_closefunc = ctypes.CFUNCTYPE(None, c_void_p)
|
||||
mlx_loop_hook_func = ctypes.CFUNCTYPE(None, c_void_p)
|
||||
|
||||
# Function Signatures
|
||||
# ============================================================================
|
||||
|
||||
# Error
|
||||
mlx.mlx_strerror.argtypes = [c_int32] # errno_t enum
|
||||
mlx.mlx_strerror.restype = c_char_p
|
||||
|
||||
mlx.mlx_get_errno.argtypes = []
|
||||
mlx.mlx_get_errno.restype = c_int32 # errno_t enum
|
||||
|
||||
|
||||
# Generic MLX Functions
|
||||
mlx.mlx_init.argtypes = [c_int32, c_int32, c_char_p, c_bool]
|
||||
mlx.mlx_init.restype = ctypes.POINTER(mlx_t)
|
||||
|
||||
mlx.mlx_set_setting.argtypes = [ctypes.c_int, c_int32] # mlx_settings_t
|
||||
mlx.mlx_set_setting.restype = None
|
||||
|
||||
mlx.mlx_close_window.argtypes = [ctypes.POINTER(mlx_t)]
|
||||
mlx.mlx_close_window.restype = None
|
||||
|
||||
mlx.mlx_loop.argtypes = [ctypes.POINTER(mlx_t)]
|
||||
mlx.mlx_loop.restype = None
|
||||
|
||||
mlx.mlx_terminate.argtypes = [ctypes.POINTER(mlx_t)]
|
||||
mlx.mlx_terminate.restype = None
|
||||
|
||||
mlx.mlx_get_time.argtypes = []
|
||||
mlx.mlx_get_time.restype = c_double
|
||||
|
||||
|
||||
# Image Functions
|
||||
mlx.mlx_put_pixel.argtypes = [ctypes.POINTER(mlx_image_t), c_uint32, c_uint32, c_uint32]
|
||||
mlx.mlx_put_pixel.restype = None
|
||||
|
||||
mlx.mlx_new_image.argtypes = [ctypes.POINTER(mlx_t), c_uint32, c_uint32]
|
||||
mlx.mlx_new_image.restype = ctypes.POINTER(mlx_image_t)
|
||||
|
||||
mlx.mlx_image_to_window.argtypes = [ctypes.POINTER(mlx_t), ctypes.POINTER(mlx_image_t), c_int32, c_int32]
|
||||
mlx.mlx_image_to_window.restype = c_int32
|
||||
|
||||
mlx.mlx_delete_image.argtypes = [ctypes.POINTER(mlx_t), ctypes.POINTER(mlx_image_t)]
|
||||
mlx.mlx_delete_image.restype = None
|
||||
|
||||
# Input
|
||||
mlx.mlx_is_key_down.argtypes = [ctypes.POINTER(mlx_t), ctypes.c_int] # keys_t
|
||||
mlx.mlx_is_key_down.restype = c_bool
|
||||
|
||||
# Hooks
|
||||
mlx.mlx_loop_hook.argtypes = [ctypes.POINTER(mlx_t), mlx_loop_hook_func, c_void_p]
|
||||
mlx.mlx_loop_hook.restype = c_bool
|
||||
0
lib/mlx/include/KHR/khrplatform.h
Executable file → Normal file
110
lib/mlx/include/MLX42/MLX42.h
Executable file → Normal file
@@ -6,7 +6,7 @@
|
||||
/* By: W2Wizard <main@w2wizard.dev> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2021/12/28 02:29:06 by W2Wizard #+# #+# */
|
||||
/* Updated: 2025/11/16 13:00:19 by w2wizard ######## odam.nl */
|
||||
/* Updated: 2023/03/30 16:23:19 by ntamayo- ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -32,17 +32,6 @@
|
||||
# include <stddef.h>
|
||||
# include <stdint.h>
|
||||
# include <stdbool.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# if defined(MLX42_BUILD_SHARED)
|
||||
# define MLX_API __declspec(dllexport)
|
||||
# else
|
||||
# define MLX_API __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
#define MLX_API __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
@@ -489,14 +478,7 @@ typedef void mlx_win_cursor_t;
|
||||
* @param[in] val The error code.
|
||||
* @return The error string that describes the error code.
|
||||
*/
|
||||
MLX_API const char* mlx_strerror(mlx_errno_t val);
|
||||
|
||||
/**
|
||||
* Gets the current global error code of MLX. Useful for FFI bindings.
|
||||
* @example printf("Error: %s\n", mlx_strerror(get_mlx_errno()));
|
||||
* @return The current global error code.
|
||||
*/
|
||||
MLX_API mlx_errno_t mlx_get_errno(void);
|
||||
const char* mlx_strerror(mlx_errno_t val);
|
||||
|
||||
//= Generic Functions =//
|
||||
|
||||
@@ -509,7 +491,7 @@ MLX_API mlx_errno_t mlx_get_errno(void);
|
||||
* @param[in] resize Enable window resizing.
|
||||
* @returns Ptr to the MLX handle or null on failure.
|
||||
*/
|
||||
MLX_API mlx_t* mlx_init(int32_t width, int32_t height, const char* title, bool resize);
|
||||
mlx_t* mlx_init(int32_t width, int32_t height, const char* title, bool resize);
|
||||
|
||||
/**
|
||||
* Set a setting for MLX42.
|
||||
@@ -518,7 +500,7 @@ MLX_API mlx_t* mlx_init(int32_t width, int32_t height, const char* title, bool r
|
||||
* @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 an enum / macro.
|
||||
*/
|
||||
MLX_API void mlx_set_setting(mlx_settings_t setting, int32_t value);
|
||||
void mlx_set_setting(mlx_settings_t setting, int32_t value);
|
||||
|
||||
/**
|
||||
* Notifies MLX that it should stop rendering and exit the main loop.
|
||||
@@ -526,7 +508,7 @@ MLX_API void mlx_set_setting(mlx_settings_t setting, int32_t value);
|
||||
*
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
*/
|
||||
MLX_API void mlx_close_window(mlx_t* mlx);
|
||||
void mlx_close_window(mlx_t* mlx);
|
||||
|
||||
/**
|
||||
* Initializes the rendering of MLX, this function won't return until
|
||||
@@ -535,7 +517,7 @@ MLX_API void mlx_close_window(mlx_t* mlx);
|
||||
*
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
*/
|
||||
MLX_API void mlx_loop(mlx_t* mlx);
|
||||
void mlx_loop(mlx_t* mlx);
|
||||
|
||||
/**
|
||||
* Lets you set a custom image as the program icon.
|
||||
@@ -547,7 +529,7 @@ MLX_API void mlx_loop(mlx_t* mlx);
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
* @param[in] image The image to use as icon.
|
||||
*/
|
||||
MLX_API void mlx_set_icon(mlx_t* mlx, mlx_texture_t* image);
|
||||
void mlx_set_icon(mlx_t* mlx, mlx_texture_t* image);
|
||||
|
||||
/**
|
||||
* Terminates MLX and cleans up any of its used resources.
|
||||
@@ -556,14 +538,14 @@ MLX_API void mlx_set_icon(mlx_t* mlx, mlx_texture_t* image);
|
||||
*
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
*/
|
||||
MLX_API void mlx_terminate(mlx_t* mlx);
|
||||
void mlx_terminate(mlx_t* mlx);
|
||||
|
||||
/**
|
||||
* Gets the elapsed time since MLX was initialized.
|
||||
*
|
||||
* @return The amount of time elapsed in seconds.
|
||||
*/
|
||||
MLX_API double mlx_get_time(void);
|
||||
double mlx_get_time(void);
|
||||
|
||||
//= Window/Monitor Functions =//
|
||||
|
||||
@@ -576,7 +558,7 @@ MLX_API double mlx_get_time(void);
|
||||
*
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
*/
|
||||
MLX_API void mlx_focus(mlx_t* mlx);
|
||||
void mlx_focus(mlx_t* mlx);
|
||||
|
||||
/**
|
||||
* Gets the size of the specified monitor.
|
||||
@@ -585,7 +567,7 @@ MLX_API void mlx_focus(mlx_t* mlx);
|
||||
* @param[in] width The width of the window.
|
||||
* @param[in] height The height of the window.
|
||||
*/
|
||||
MLX_API void mlx_get_monitor_size(int32_t index, int32_t* width, int32_t* height);
|
||||
void mlx_get_monitor_size(int32_t index, int32_t* width, int32_t* height);
|
||||
|
||||
/**
|
||||
* Sets the window's position.
|
||||
@@ -597,7 +579,7 @@ MLX_API void mlx_get_monitor_size(int32_t index, int32_t* width, int32_t* height
|
||||
* @param[in] xpos The x position.
|
||||
* @param[in] ypos The y position.
|
||||
*/
|
||||
MLX_API void mlx_set_window_pos(mlx_t* mlx, int32_t xpos, int32_t ypos);
|
||||
void mlx_set_window_pos(mlx_t* mlx, int32_t xpos, int32_t ypos);
|
||||
|
||||
/**
|
||||
* Gets the window's position.
|
||||
@@ -606,7 +588,7 @@ MLX_API void mlx_set_window_pos(mlx_t* mlx, int32_t xpos, int32_t ypos);
|
||||
* @param[out] xpos The x position.
|
||||
* @param[out] ypos The y position.
|
||||
*/
|
||||
MLX_API void mlx_get_window_pos(mlx_t* mlx, int32_t* xpos, int32_t* ypos);
|
||||
void mlx_get_window_pos(mlx_t* mlx, int32_t* xpos, int32_t* ypos);
|
||||
|
||||
/**
|
||||
* Changes the window size to the newly specified values.
|
||||
@@ -616,7 +598,7 @@ MLX_API void mlx_get_window_pos(mlx_t* mlx, int32_t* xpos, int32_t* ypos);
|
||||
* @param[in] new_width The new desired width.
|
||||
* @param[in] new_height The new desired height.
|
||||
*/
|
||||
MLX_API void mlx_set_window_size(mlx_t* mlx, int32_t new_width, int32_t new_height);
|
||||
void mlx_set_window_size(mlx_t* mlx, int32_t new_width, int32_t new_height);
|
||||
|
||||
/**
|
||||
* Sets the size limits of the specified window.
|
||||
@@ -631,7 +613,7 @@ MLX_API void mlx_set_window_size(mlx_t* mlx, int32_t new_width, int32_t new_heig
|
||||
* @param[in] min_h The min height of the window.
|
||||
* @param[in] max_h The max height of the window.
|
||||
*/
|
||||
MLX_API void mlx_set_window_limit(mlx_t* mlx, int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h);
|
||||
void mlx_set_window_limit(mlx_t* mlx, int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h);
|
||||
|
||||
/**
|
||||
* Sets the title of the window.
|
||||
@@ -639,7 +621,7 @@ MLX_API void mlx_set_window_limit(mlx_t* mlx, int32_t min_w, int32_t min_h, int3
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
* @param[in] title The window title.
|
||||
*/
|
||||
MLX_API void mlx_set_window_title(mlx_t* mlx, const char* title);
|
||||
void mlx_set_window_title(mlx_t* mlx, const char* title);
|
||||
|
||||
//= Input Functions =//
|
||||
|
||||
@@ -650,7 +632,7 @@ MLX_API void mlx_set_window_title(mlx_t* mlx, const char* title);
|
||||
* @param[in] key The keycode to check, use MLX_KEY_... to specify!
|
||||
* @returns True or false if the key is down or not.
|
||||
*/
|
||||
MLX_API bool mlx_is_key_down(mlx_t* mlx, keys_t key);
|
||||
bool mlx_is_key_down(mlx_t* mlx, keys_t key);
|
||||
|
||||
/**
|
||||
* Checks whether a mouse button is pressed or not.
|
||||
@@ -659,7 +641,7 @@ MLX_API bool mlx_is_key_down(mlx_t* mlx, keys_t key);
|
||||
* @param[in] key A specific mouse key. e.g MLX_MOUSE_BUTTON_0
|
||||
* @returns True or false if the mouse key is down or not.
|
||||
*/
|
||||
MLX_API bool mlx_is_mouse_down(mlx_t* mlx, mouse_key_t key);
|
||||
bool mlx_is_mouse_down(mlx_t* mlx, mouse_key_t key);
|
||||
|
||||
/**
|
||||
* Returns the current, relative, mouse cursor position on the window, starting
|
||||
@@ -672,7 +654,7 @@ MLX_API bool mlx_is_mouse_down(mlx_t* mlx, mouse_key_t key);
|
||||
* @param[out] x The position.
|
||||
* @param[out] y The position.
|
||||
*/
|
||||
MLX_API void mlx_get_mouse_pos(mlx_t* mlx, int32_t* x, int32_t* y);
|
||||
void mlx_get_mouse_pos(mlx_t* mlx, int32_t* x, int32_t* y);
|
||||
|
||||
/**
|
||||
* Sets the mouse position.
|
||||
@@ -680,7 +662,7 @@ MLX_API void mlx_get_mouse_pos(mlx_t* mlx, int32_t* x, int32_t* y);
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
* @param[in] pos The position.
|
||||
*/
|
||||
MLX_API void mlx_set_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.
|
||||
@@ -688,7 +670,7 @@ MLX_API void mlx_set_mouse_pos(mlx_t* mlx, int32_t x, int32_t y);
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
* @param[in] mode A specified mouse mode.
|
||||
*/
|
||||
MLX_API void mlx_set_cursor_mode(mlx_t* mlx, mouse_mode_t mode);
|
||||
void mlx_set_cursor_mode(mlx_t* mlx, mouse_mode_t mode);
|
||||
|
||||
/**
|
||||
* Retrieves the system standard cursor.
|
||||
@@ -696,7 +678,7 @@ MLX_API void mlx_set_cursor_mode(mlx_t* mlx, mouse_mode_t mode);
|
||||
* @param[in] type The standard cursor type to create.
|
||||
* @return The cursor object or null on failure.
|
||||
*/
|
||||
MLX_API mlx_win_cursor_t* 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.
|
||||
@@ -707,14 +689,14 @@ MLX_API mlx_win_cursor_t* mlx_create_std_cursor(cursor_t type);
|
||||
* @param[in] texture The texture to use as cursor.
|
||||
* @returns The cursor object or null on failure.
|
||||
*/
|
||||
MLX_API mlx_win_cursor_t* 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.
|
||||
*/
|
||||
MLX_API void mlx_destroy_cursor(mlx_win_cursor_t* cursor);
|
||||
void mlx_destroy_cursor(mlx_win_cursor_t* cursor);
|
||||
|
||||
/**
|
||||
* Sets the current cursor to the given custom cursor.
|
||||
@@ -722,7 +704,7 @@ MLX_API void mlx_destroy_cursor(mlx_win_cursor_t* cursor);
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
* @param[in] cursor The cursor object to display, if null default cursor is selected.
|
||||
*/
|
||||
MLX_API void mlx_set_cursor(mlx_t* mlx, mlx_win_cursor_t* cursor);
|
||||
void mlx_set_cursor(mlx_t* mlx, mlx_win_cursor_t* cursor);
|
||||
|
||||
//= Hooks =//
|
||||
|
||||
@@ -734,7 +716,7 @@ MLX_API void mlx_set_cursor(mlx_t* mlx, mlx_win_cursor_t* cursor);
|
||||
* @param[in] func The scroll wheel callback function.
|
||||
* @param[in] param An additional optional parameter.
|
||||
*/
|
||||
MLX_API void mlx_scroll_hook(mlx_t* mlx, mlx_scrollfunc func, void* param);
|
||||
void mlx_scroll_hook(mlx_t* mlx, mlx_scrollfunc func, void* param);
|
||||
|
||||
/**
|
||||
* This function sets the mouse callback, which is called when a mouse
|
||||
@@ -744,7 +726,7 @@ MLX_API void mlx_scroll_hook(mlx_t* mlx, mlx_scrollfunc func, void* param);
|
||||
* @param[in] func The mouse callback function.
|
||||
* @param[in] param An additional optional parameter.
|
||||
*/
|
||||
MLX_API void mlx_mouse_hook(mlx_t* mlx, mlx_mousefunc 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 the
|
||||
@@ -754,7 +736,7 @@ MLX_API void mlx_mouse_hook(mlx_t* mlx, mlx_mousefunc func, void* param);
|
||||
* @param[in] func The cursor callback function.
|
||||
* @param[in] param An additional optional parameter.
|
||||
*/
|
||||
MLX_API void mlx_cursor_hook(mlx_t* mlx, mlx_cursorfunc func, void* param);
|
||||
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
|
||||
@@ -764,7 +746,7 @@ MLX_API void mlx_cursor_hook(mlx_t* mlx, mlx_cursorfunc func, void* param);
|
||||
* @param[in] func The keypress callback function.
|
||||
* @param[in] param An additional optional parameter.
|
||||
*/
|
||||
MLX_API void mlx_key_hook(mlx_t* mlx, mlx_keyfunc func, void* param);
|
||||
void mlx_key_hook(mlx_t* mlx, mlx_keyfunc func, void* param);
|
||||
|
||||
/**
|
||||
* This function sets the close callback, which is called in attempt to close
|
||||
@@ -774,7 +756,7 @@ MLX_API void mlx_key_hook(mlx_t* mlx, mlx_keyfunc func, void* param);
|
||||
* @param[in] func The close callback function.
|
||||
* @param[in] param An additional optional parameter.
|
||||
*/
|
||||
MLX_API void mlx_close_hook(mlx_t* mlx, mlx_closefunc func, void* param);
|
||||
void mlx_close_hook(mlx_t* mlx, mlx_closefunc func, void* param);
|
||||
|
||||
/**
|
||||
* This function sets the resize callback, which is called when the window is
|
||||
@@ -784,7 +766,7 @@ MLX_API void mlx_close_hook(mlx_t* mlx, mlx_closefunc func, void* param);
|
||||
* @param[in] func The resize callback function.
|
||||
* @param[in] param An additional optional parameter.
|
||||
*/
|
||||
MLX_API void mlx_resize_hook(mlx_t* mlx, mlx_resizefunc func, void* param);
|
||||
void mlx_resize_hook(mlx_t* mlx, mlx_resizefunc func, void* param);
|
||||
|
||||
/**
|
||||
* Generic loop hook for any custom hooks to add to the main loop.
|
||||
@@ -795,7 +777,7 @@ MLX_API void mlx_resize_hook(mlx_t* mlx, mlx_resizefunc func, void* param);
|
||||
* @param[in] param The parameter to pass on to the function.
|
||||
* @returns Whether or not the hook was added successfully.
|
||||
*/
|
||||
MLX_API bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param);
|
||||
bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param);
|
||||
|
||||
//= Texture Functions =//
|
||||
|
||||
@@ -805,7 +787,7 @@ MLX_API bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param);
|
||||
* @param[in] path Path to the PNG file.
|
||||
* @return If successful the texture data is returned, else NULL.
|
||||
*/
|
||||
MLX_API mlx_texture_t* mlx_load_png(const char* path);
|
||||
mlx_texture_t* mlx_load_png(const char* path);
|
||||
|
||||
/**
|
||||
* Loads an XPM42 texture from the given file path.
|
||||
@@ -813,14 +795,14 @@ MLX_API mlx_texture_t* mlx_load_png(const char* path);
|
||||
* @param[in] path The file path to the XPM texture.
|
||||
* @returns The XPM texture struct containing its information.
|
||||
*/
|
||||
MLX_API xpm_t* mlx_load_xpm42(const char* path);
|
||||
xpm_t* mlx_load_xpm42(const char* path);
|
||||
|
||||
/**
|
||||
* Deletes a texture by freeing its allocated data.
|
||||
*
|
||||
* @param[in] texture The texture to free.
|
||||
*/
|
||||
MLX_API void mlx_delete_texture(mlx_texture_t* texture);
|
||||
void mlx_delete_texture(mlx_texture_t* texture);
|
||||
|
||||
/**
|
||||
* Deletes an XPM42 texture by freeing its allocated data.
|
||||
@@ -830,7 +812,7 @@ MLX_API void mlx_delete_texture(mlx_texture_t* texture);
|
||||
*
|
||||
* @param[in] xpm The xpm texture to delete.
|
||||
*/
|
||||
MLX_API void mlx_delete_xpm42(xpm_t* xpm);
|
||||
void mlx_delete_xpm42(xpm_t* xpm);
|
||||
|
||||
/**
|
||||
* Converts a given texture to an image.
|
||||
@@ -839,7 +821,7 @@ MLX_API void mlx_delete_xpm42(xpm_t* xpm);
|
||||
* @param[in] texture The texture to use to create the image from.
|
||||
* @return mlx_image_t* The image created from the texture.
|
||||
*/
|
||||
MLX_API mlx_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture);
|
||||
mlx_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture);
|
||||
|
||||
//= Image Functions =//
|
||||
|
||||
@@ -854,7 +836,7 @@ MLX_API mlx_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture);
|
||||
* @param[in] y The Y coordinate position.
|
||||
* @param[in] color The color value to put.
|
||||
*/
|
||||
MLX_API void mlx_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t color);
|
||||
void mlx_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t color);
|
||||
|
||||
/**
|
||||
* Creates and allocates a new image buffer.
|
||||
@@ -864,7 +846,7 @@ MLX_API void mlx_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t
|
||||
* @param[in] height The desired height of the image.
|
||||
* @return Pointer to the image buffer, if it failed to allocate then NULL.
|
||||
*/
|
||||
MLX_API mlx_image_t* mlx_new_image(mlx_t* mlx, uint32_t width, uint32_t height);
|
||||
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
|
||||
@@ -883,7 +865,7 @@ MLX_API mlx_image_t* mlx_new_image(mlx_t* mlx, uint32_t width, uint32_t height);
|
||||
* @param[in] y The Y position.
|
||||
* @return Index to the instance, or -1 on failure.
|
||||
*/
|
||||
MLX_API int32_t mlx_image_to_window(mlx_t* mlx, mlx_image_t* img, int32_t x, int32_t y);
|
||||
int32_t mlx_image_to_window(mlx_t* mlx, mlx_image_t* img, int32_t x, int32_t y);
|
||||
|
||||
/**
|
||||
* Deleting an image will remove it from the render queue as well as any and all
|
||||
@@ -896,7 +878,7 @@ MLX_API int32_t mlx_image_to_window(mlx_t* mlx, mlx_image_t* img, int32_t x, int
|
||||
* @param[in] mlx The MLX instance handle.
|
||||
* @param[in] image The image to delete.
|
||||
*/
|
||||
MLX_API void mlx_delete_image(mlx_t* mlx, mlx_image_t* image);
|
||||
void mlx_delete_image(mlx_t* mlx, mlx_image_t* image);
|
||||
|
||||
/**
|
||||
* Allows you to resize an image, a new pixel buffer is allocated
|
||||
@@ -907,7 +889,7 @@ MLX_API void mlx_delete_image(mlx_t* mlx, mlx_image_t* image);
|
||||
* @param[in] nheight The new height.
|
||||
* @return True if image was resized or false on error.
|
||||
*/
|
||||
MLX_API bool mlx_resize_image(mlx_image_t* img, uint32_t nwidth, uint32_t nheight);
|
||||
bool mlx_resize_image(mlx_image_t* img, uint32_t nwidth, uint32_t nheight);
|
||||
|
||||
/**
|
||||
* Sets the depth / Z axis value of an instance.
|
||||
@@ -919,7 +901,7 @@ MLX_API bool mlx_resize_image(mlx_image_t* img, uint32_t nwidth, uint32_t nheigh
|
||||
* @param[in] instance The instance on which to change the depth.
|
||||
* @param[in] zdepth The new depth value.
|
||||
*/
|
||||
MLX_API void mlx_set_instance_depth(mlx_instance_t* instance, int32_t zdepth);
|
||||
void mlx_set_instance_depth(mlx_instance_t* instance, int32_t zdepth);
|
||||
|
||||
//= String Functions =//
|
||||
|
||||
@@ -932,14 +914,14 @@ MLX_API void mlx_set_instance_depth(mlx_instance_t* instance, int32_t zdepth);
|
||||
* @param[in] y The Y location.
|
||||
* @return Image ptr to the string.
|
||||
*/
|
||||
MLX_API mlx_image_t* mlx_put_string(mlx_t* mlx, const char* str, int32_t x, int32_t y);
|
||||
mlx_image_t* mlx_put_string(mlx_t* mlx, const char* str, int32_t x, int32_t y);
|
||||
|
||||
/**
|
||||
* Retrieve the texture data for the built-in font.
|
||||
*
|
||||
* @return Pointer to the built-in font texture.
|
||||
*/
|
||||
MLX_API const mlx_texture_t* mlx_get_font(void);
|
||||
const mlx_texture_t* mlx_get_font(void);
|
||||
|
||||
/**
|
||||
* This function lets you retrieve the X offset
|
||||
@@ -950,7 +932,7 @@ MLX_API const mlx_texture_t* mlx_get_font(void);
|
||||
* @param[in] c The character to get the offset from.
|
||||
* @return Non-negative if found or -1 if not found.
|
||||
*/
|
||||
MLX_API int32_t mlx_get_texoffset(char c);
|
||||
int32_t mlx_get_texoffset(char c);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
|
||||
0
lib/mlx/include/MLX42/MLX42_Int.h
Executable file → Normal file
0
lib/mlx/include/glad/glad.h
Executable file → Normal file
0
lib/mlx/include/lodepng/lodepng.h
Executable file → Normal file
0
lib/mlx/lib/glad/glad.c
Executable file → Normal file
0
lib/mlx/lib/png/lodepng.c
Executable file → Normal file
0
lib/mlx/shaders/default.frag
Executable file → Normal file
0
lib/mlx/shaders/default.vert
Executable file → Normal file
0
lib/mlx/src/font/font.h
Executable file → Normal file
0
lib/mlx/src/font/mlx_font.c
Executable file → Normal file
0
lib/mlx/src/mlx_cursor.c
Executable file → Normal file
0
lib/mlx/src/mlx_exit.c
Executable file → Normal file
0
lib/mlx/src/mlx_images.c
Executable file → Normal file
108
lib/mlx/src/mlx_init.c
Executable file → Normal file
@@ -70,7 +70,7 @@ static bool mlx_create_buffers(mlx_t* mlx)
|
||||
/**
|
||||
* Compiles the given shader source code of a given shader type.
|
||||
* Returns shader object via param.
|
||||
*
|
||||
*
|
||||
* @param code The shader source code.
|
||||
* @param Type GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, GL_GEOMETRY_SHADER, ...
|
||||
* @return Non-zero on success, else 0.
|
||||
@@ -81,7 +81,7 @@ static uint32_t mlx_compile_shader(const char* code, int32_t type)
|
||||
int32_t success;
|
||||
char infolog[512] = {0};
|
||||
|
||||
if (!code || (shader = glCreateShader(type)) == 0)
|
||||
if (!code || (shader = glCreateShader(type)) == 0)
|
||||
return (0);
|
||||
|
||||
GLint len = strlen(code);
|
||||
@@ -100,56 +100,53 @@ static uint32_t mlx_compile_shader(const char* code, int32_t type)
|
||||
|
||||
static bool mlx_init_render(mlx_t* mlx)
|
||||
{
|
||||
uint32_t vshader = 0;
|
||||
uint32_t fshader = 0;
|
||||
char infolog[512] = {0};
|
||||
mlx_ctx_t* mlxctx = mlx->context;
|
||||
uint32_t vshader = 0;
|
||||
uint32_t fshader = 0;
|
||||
char infolog[512] = {0};
|
||||
mlx_ctx_t* mlxctx = mlx->context;
|
||||
|
||||
glfwMakeContextCurrent(mlx->window);
|
||||
glfwSetFramebufferSizeCallback(mlx->window, framebuffer_callback);
|
||||
glfwSetWindowUserPointer(mlx->window, mlx);
|
||||
glfwSwapInterval(MLX_SWAP_INTERVAL);
|
||||
glfwMakeContextCurrent(mlx->window);
|
||||
glfwSetFramebufferSizeCallback(mlx->window, framebuffer_callback);
|
||||
glfwSetWindowUserPointer(mlx->window, mlx);
|
||||
glfwSwapInterval(MLX_SWAP_INTERVAL);
|
||||
|
||||
// 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);
|
||||
// Load all OpenGL function pointers
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
return (mlx_error(MLX_GLADFAIL));
|
||||
|
||||
int32_t success;
|
||||
glGetProgramiv(mlxctx->shaderprogram, GL_LINK_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetProgramInfoLog(mlxctx->shaderprogram, sizeof(infolog), NULL, infolog);
|
||||
fprintf(stderr, "%s", infolog);
|
||||
glDeleteProgram(mlxctx->shaderprogram);
|
||||
glDeleteShader(vshader);
|
||||
glDeleteShader(fshader);
|
||||
return (mlx_error(MLX_SHDRFAIL));
|
||||
}
|
||||
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);
|
||||
|
||||
// Detach shaders after linking but before deleting them
|
||||
glDetachShader(mlxctx->shaderprogram, vshader);
|
||||
glDetachShader(mlxctx->shaderprogram, fshader);
|
||||
glDeleteShader(vshader);
|
||||
glDeleteShader(fshader);
|
||||
glDetachShader(mlxctx->shaderprogram, vshader);
|
||||
glDetachShader(mlxctx->shaderprogram, fshader);
|
||||
|
||||
// Delete shaders
|
||||
glDeleteShader(vshader);
|
||||
glDeleteShader(fshader);
|
||||
glUseProgram(mlxctx->shaderprogram);
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
mlxctx->bound_textures[i] = 0;
|
||||
return (true);
|
||||
int32_t success;
|
||||
glGetProgramiv(mlxctx->shaderprogram, GL_LINK_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetProgramInfoLog(mlxctx->shaderprogram, sizeof(infolog), NULL, infolog);
|
||||
fprintf(stderr, "%s", infolog);
|
||||
return (mlx_error(MLX_SHDRFAIL));
|
||||
}
|
||||
glUseProgram(mlxctx->shaderprogram);
|
||||
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
mlxctx->bound_textures[i] = 0;
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
//= Public =//
|
||||
@@ -177,36 +174,25 @@ mlx_t* mlx_init(int32_t width, int32_t height, const char* title, bool resize)
|
||||
return (free(mlx), (void*)mlx_error(MLX_MEMFAIL));
|
||||
|
||||
mlx_ctx_t* const mlxctx = mlx->context;
|
||||
mlx->window = NULL;
|
||||
mlx->width = width;
|
||||
mlx->height = height;
|
||||
mlxctx->initialWidth = width;
|
||||
mlxctx->initialHeight = height;
|
||||
|
||||
// NOTE(W2): For emscripten, this value will be ignored anyway.
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
#ifdef EMSCRIPTEN
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
#else
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_MAXIMIZED, mlx_settings[MLX_MAXIMIZED]);
|
||||
glfwWindowHint(GLFW_DECORATED, mlx_settings[MLX_DECORATED]);
|
||||
glfwWindowHint(GLFW_VISIBLE, !mlx_settings[MLX_HEADLESS]);
|
||||
#endif
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
#endif
|
||||
glfwWindowHint(GLFW_RESIZABLE, resize ? GLFW_TRUE : GLFW_FALSE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, resize);
|
||||
if (!(mlx->window = glfwCreateWindow(width, height, title, mlx_settings[MLX_FULLSCREEN] ? glfwGetPrimaryMonitor() : NULL, NULL)))
|
||||
return (glfwTerminate(), (void*)mlx_error(MLX_WINFAIL));
|
||||
return (mlx_terminate(mlx), (void*)mlx_error(MLX_WINFAIL));
|
||||
if (!mlx_init_render(mlx) || !mlx_create_buffers(mlx))
|
||||
return (mlx_terminate(mlx), NULL);
|
||||
glfwMakeContextCurrent(mlx->window);
|
||||
return (mlx);
|
||||
}
|
||||
|
||||
|
||||
0
lib/mlx/src/mlx_keys.c
Executable file → Normal file
14
lib/mlx/src/mlx_loop.c
Executable file → Normal file
@@ -90,25 +90,17 @@ bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param)
|
||||
}
|
||||
|
||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
/**
|
||||
* In Emscripten the lood is defined differently, there the this function
|
||||
* is passed to the while loop instead
|
||||
*/
|
||||
void mlx_loop(mlx_t* mlx)
|
||||
{
|
||||
MLX_NONNULL(mlx);
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
static double start, oldstart = 0;
|
||||
#else
|
||||
double start, oldstart = 0;
|
||||
while (!glfwWindowShouldClose(mlx->window))
|
||||
while (!glfwWindowShouldClose(mlx->window))
|
||||
{
|
||||
#endif
|
||||
start = glfwGetTime();
|
||||
mlx->delta_time = start - oldstart;
|
||||
oldstart = start;
|
||||
|
||||
|
||||
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glfwGetWindowSize(mlx->window, &(mlx->width), &(mlx->height));
|
||||
@@ -122,7 +114,5 @@ void mlx_loop(mlx_t* mlx)
|
||||
|
||||
glfwSwapBuffers(mlx->window);
|
||||
glfwPollEvents();
|
||||
#ifndef EMSCRIPTEN
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
0
lib/mlx/src/mlx_monitor.c
Executable file → Normal file
0
lib/mlx/src/mlx_mouse.c
Executable file → Normal file
0
lib/mlx/src/mlx_put_pixel.c
Executable file → Normal file
0
lib/mlx/src/mlx_window.c
Executable file → Normal file
0
lib/mlx/src/textures/mlx_png.c
Executable file → Normal file
0
lib/mlx/src/textures/mlx_texture.c
Executable file → Normal file
0
lib/mlx/src/textures/mlx_xpm42.c
Executable file → Normal file
0
lib/mlx/src/utils/mlx_compare.c
Executable file → Normal file
11
lib/mlx/src/utils/mlx_error.c
Executable file → Normal file
@@ -6,7 +6,7 @@
|
||||
/* By: W2Wizard <main@w2wizard.dev> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2021/12/28 02:51:54 by W2Wizard #+# #+# */
|
||||
/* Updated: 2025/11/16 13:00:50 by w2wizard ######## odam.nl */
|
||||
/* Updated: 2022/11/22 08:50:15 by jvan-hal ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -36,9 +36,9 @@ static const char* mlx_errors[MLX_ERRMAX] = {
|
||||
|
||||
/**
|
||||
* Functions to set the error number, simply for convenience.
|
||||
*
|
||||
*
|
||||
* @param val The error value.
|
||||
* @return Always false
|
||||
* @return Always false
|
||||
*/
|
||||
bool mlx_error(mlx_errno_t val)
|
||||
{
|
||||
@@ -58,8 +58,3 @@ const char* mlx_strerror(mlx_errno_t val)
|
||||
|
||||
return (mlx_errors[val]);
|
||||
}
|
||||
|
||||
mlx_errno_t mlx_get_errno(void)
|
||||
{
|
||||
return (mlx_errno);
|
||||
}
|
||||
0
lib/mlx/src/utils/mlx_list.c
Executable file → Normal file
0
lib/mlx/src/utils/mlx_utils.c
Executable file → Normal file
0
lib/mlx/tests/CMakeLists.txt
Executable file → Normal file
0
lib/mlx/tests/WindowFixture.hpp
Executable file → Normal file
0
lib/mlx/tests/tests.cpp
Executable file → Normal file
@@ -4,28 +4,19 @@
|
||||
:: -----------------------------------------------------------------------------
|
||||
|
||||
@echo off
|
||||
SETLOCAL EnableDelayedExpansion
|
||||
SETLOCAL DisableDelayedExpansion
|
||||
|
||||
:: If no arguments have been given to the script
|
||||
IF "%~1"=="" (
|
||||
echo ERROR: missing arguments, use as follows: %~nx0 ^<ShaderFile^> ^<Mode^> 1>&2
|
||||
ENDLOCAL
|
||||
EXIT /B 1
|
||||
)
|
||||
:: go to usage function if no arguments have been given to the script
|
||||
IF [%1]==[] GOTO usage
|
||||
|
||||
:: Check if file exists
|
||||
IF NOT EXIST "%~1" (
|
||||
echo ERROR: shader file not found: %~1 1>&2
|
||||
ENDLOCAL
|
||||
EXIT /B 2
|
||||
)
|
||||
:: check if input file exists before continuing
|
||||
IF NOT EXIST %1 GOTO fnotfound
|
||||
|
||||
:: Extract the shader type (file extension without the dot)
|
||||
SET "SHADERTYPE=%~x1"
|
||||
SET "SHADERTYPE=%SHADERTYPE:~1%"
|
||||
SET SHADERTYPE=%~x1
|
||||
SET SHADERTYPE=%SHADERTYPE:~1%
|
||||
|
||||
echo // -----------------------------------------------------------------------------
|
||||
echo // Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
|
||||
echo // Codam Coding College, Amsterdam @ <2022-2023> by W2Wizard.
|
||||
echo // See README in the root project for more information.
|
||||
echo // -----------------------------------------------------------------------------
|
||||
echo.
|
||||
@@ -34,28 +25,23 @@ echo.
|
||||
echo #include "MLX42/MLX42_Int.h"
|
||||
echo.
|
||||
|
||||
:: Check the Mode argument (WASM specific output if Mode == 1)
|
||||
IF "%~2"=="1" (
|
||||
echo const char* %SHADERTYPE%_shader = "#version 300 es\n"
|
||||
echo "precision mediump float;\n"
|
||||
) ELSE (
|
||||
FOR /F "delims=" %%A IN ('more +0 "%~1"') DO (
|
||||
echo const char* %SHADERTYPE%_shader = "%%A\n"
|
||||
GOTO next
|
||||
)
|
||||
)
|
||||
|
||||
:next
|
||||
:: Read and process the rest of the shader file
|
||||
FOR /F "usebackq delims=" %%A IN ("%~1") DO (
|
||||
IF NOT "%%A"=="" (
|
||||
IF "%%A"=="}" (
|
||||
echo "%%A";
|
||||
) ELSE (
|
||||
echo "%%A"
|
||||
)
|
||||
)
|
||||
FOR /F "delims=" %%A IN (%1) DO IF NOT DEFINED VERSIONLINE set "VERSIONLINE=%%A"
|
||||
echo const char* %SHADERTYPE%_shader = "%VERSIONLINE%\n"
|
||||
FOR /F "skip=1 delims=" %%A IN (%1) DO (
|
||||
IF "%%A" == "}" (echo "%%A";) ELSE (echo "%%A")
|
||||
)
|
||||
|
||||
ENDLOCAL
|
||||
EXIT /B 0
|
||||
|
||||
:: usage function exits the script with exit code 3 (path not found)
|
||||
:usage
|
||||
echo ERROR: missing arguments, use as follows: %0 ^<ShaderFile^> 1>&2
|
||||
ENDLOCAL
|
||||
EXIT /B 3
|
||||
|
||||
:: fnotfound function exits the script with exit code 2 (file not found)
|
||||
:fnotfound
|
||||
echo ERROR: shader file not found: %1 1>&2
|
||||
ENDLOCAL
|
||||
EXIT /B 2
|
||||
|
||||
@@ -4,41 +4,32 @@
|
||||
# See README in the root project for more information.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# If no arguments have been given
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "ERROR: missing arguments, use as follows: $0 <ShaderFile> <Mode>" 1>&2
|
||||
exit 1
|
||||
# If no arguments have been given, exit with error code 1
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "ERROR: missing arguments, use as follows: $0 <ShaderFile>" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If file cannot be found
|
||||
# If file cannot be found, exit with error code 2
|
||||
if [ ! -f "$1" ]; then
|
||||
echo "ERROR: shader file not found: $1" 1>&2
|
||||
exit 2
|
||||
echo "ERROR: shader file not found: $1" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
SHADERTYPE="${1##*.}"
|
||||
|
||||
echo "// -----------------------------------------------------------------------------"
|
||||
echo "// Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard. "
|
||||
echo "// See README in the root project for more information. "
|
||||
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 ""
|
||||
|
||||
# Include the MLX42 header
|
||||
echo "#include \"MLX42/MLX42_Int.h\""
|
||||
echo ""
|
||||
|
||||
echo "const char* ${SHADERTYPE}_shader = \"$(sed -n '1{p;q;}' "$1")\\n\""
|
||||
{
|
||||
if [ "$2" -eq 1 ]; then # Output WASM specific lines
|
||||
echo "const char* ${SHADERTYPE}_shader = \"#version 300 es\\n\""
|
||||
echo " \"precision mediump float;\""
|
||||
else # Non-Wasm, output the original shader version
|
||||
echo "const char* ${SHADERTYPE}_shader = \"$(sed -n '1{p;q;}' "$1")\\n\""
|
||||
fi
|
||||
|
||||
# Read the rest of the shader file
|
||||
# Skip over first line
|
||||
read
|
||||
while IFS= read -r LINE; do
|
||||
if [ ! "${LINE}" = "" ]; then
|
||||
@@ -50,5 +41,4 @@ echo ""
|
||||
fi
|
||||
done
|
||||
} < "$1"
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
# Web
|
||||
|
||||
MLX42 supports compilation towards [WASM](https://webassembly.org/). What this means is you can run any application written in C directly in the browser!
|
||||
This overcomes a lot of issues with for instance showing projects towards others or have an environment where building natively just won't work.
|
||||
|
||||
In this README you will learn how to compile your project towards Webassembly and later deploy it on github!
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
- [Emscripten](https://emscripten.org/), you can install this via brew or read the instructions they provide for [Windows or Linux](https://emscripten.org/docs/getting_started/downloads.html)
|
||||
|
||||
## Building
|
||||
|
||||
Once you made sure you have emscripten installed (check if `emcc` and `emcmake` work).
|
||||
|
||||
Run:
|
||||
```bash
|
||||
emcmake cmake -B build && cmake --build build --parallel
|
||||
```
|
||||
|
||||
## Modifications
|
||||
|
||||
You're only required to do a few modifications to your `main.c`.
|
||||
For this we will use the demo main provided in the root [readme](../README.md).
|
||||
|
||||
Add the following headers at the top:
|
||||
```c
|
||||
#include <emscripten/html5.h>
|
||||
#include <emscripten/emscripten.h>
|
||||
```
|
||||
|
||||
Modify your main:
|
||||
```c
|
||||
// Invoked instead of mlx_loop directly.
|
||||
void emscripten_main_loop() {
|
||||
mlx_loop(mlx);
|
||||
}
|
||||
|
||||
int32_t main(int argc, char **argv)
|
||||
{
|
||||
// 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);
|
||||
|
||||
// This function will set up the main loop
|
||||
emscripten_set_main_loop(emscripten_main_loop, 0, true);
|
||||
mlx_terminate(mlx);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
```
|
||||
|
||||
Thats actually it! It may or may not be necessary to modify your own source code depending on what you do but that's most often not the case.
|
||||
It is that easy to just re-deploy your own app into webassembly.
|
||||
|
||||
## Building
|
||||
|
||||
```bash
|
||||
# Compile C into JS/WASM
|
||||
emcc -O3 -I include -I mlx -pthread main.c \
|
||||
-o ./web/demo.js \
|
||||
./build/libmlx42.a \
|
||||
-s USE_GLFW=3 -s USE_WEBGL2=1 -s FULL_ES3=1 -s WASM=1 \
|
||||
-s NO_EXIT_RUNTIME=1 -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \
|
||||
-s ALLOW_MEMORY_GROWTH
|
||||
|
||||
# Navigate into the web folder (if you're running this directly from this repo)
|
||||
cd web
|
||||
|
||||
# Launch local webserver, this is required to make the service worker function.
|
||||
python3 -m http.server 8000
|
||||
```
|
||||
|
||||
Once the server is up and running all you need to do now is go to [localhost](http://localhost:8000/index.html).
|
||||
There you can locally develop your application without having to do any git commits or actions shenanigans.
|
||||
|
||||
# Deploying to Github Pages
|
||||
|
||||
For a free, quick and easy hosting solution you can realistically deploy this anywhere.
|
||||
However for now we will only focus on putting this up via github pages.
|
||||
|
||||
What you need in your repository is a `.github/workflows/static.yml` file.
|
||||
It can be named anything `static`, `ci`, whatever. Later on if you learn more about CI Pipelines you can use this to do a lot of useful things.
|
||||
|
||||
## Enabling github pages
|
||||
Follow this step: https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow
|
||||
|
||||
Once selected, you need to commit an actions file.
|
||||
For now you can copy paste MLX42's `wasm.yml` file which functionally does the exact same.
|
||||
```yml
|
||||
# Simple workflow for deploying static content to GitHub Pages
|
||||
name: Deploy static content to Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["master"] # Change to main or whatever fancy name
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
||||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: false
|
||||
|
||||
# Single deploy job since we're just deploying
|
||||
jobs:
|
||||
deploy:
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
runs-on: ubuntu-latest
|
||||
#TODO: add a build step to get the wasm file instead of commiting it.
|
||||
#Doesn't really matter atm since the git history is polluted anyway
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v5
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: './web' # <= Set this variable to the directory relative to the root of the repo.
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
```
|
||||
|
||||
Once you commit this file github will do it's magic and create a deployment.
|
||||
You should then get a link to where you can access you program. Now you can access your app anywhere!
|
||||
@@ -1,146 +0,0 @@
|
||||
/*! coi-serviceworker v0.1.7 - Guido Zuidhof and contributors, licensed under MIT */
|
||||
let coepCredentialless = false;
|
||||
if (typeof window === 'undefined') {
|
||||
self.addEventListener("install", () => self.skipWaiting());
|
||||
self.addEventListener("activate", (event) => event.waitUntil(self.clients.claim()));
|
||||
|
||||
self.addEventListener("message", (ev) => {
|
||||
if (!ev.data) {
|
||||
return;
|
||||
} else if (ev.data.type === "deregister") {
|
||||
self.registration
|
||||
.unregister()
|
||||
.then(() => {
|
||||
return self.clients.matchAll();
|
||||
})
|
||||
.then(clients => {
|
||||
clients.forEach((client) => client.navigate(client.url));
|
||||
});
|
||||
} else if (ev.data.type === "coepCredentialless") {
|
||||
coepCredentialless = ev.data.value;
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", function (event) {
|
||||
const r = event.request;
|
||||
if (r.cache === "only-if-cached" && r.mode !== "same-origin") {
|
||||
return;
|
||||
}
|
||||
|
||||
const request = (coepCredentialless && r.mode === "no-cors")
|
||||
? new Request(r, {
|
||||
credentials: "omit",
|
||||
})
|
||||
: r;
|
||||
event.respondWith(
|
||||
fetch(request)
|
||||
.then((response) => {
|
||||
if (response.status === 0) {
|
||||
return response;
|
||||
}
|
||||
|
||||
const newHeaders = new Headers(response.headers);
|
||||
newHeaders.set("Cross-Origin-Embedder-Policy",
|
||||
coepCredentialless ? "credentialless" : "require-corp"
|
||||
);
|
||||
if (!coepCredentialless) {
|
||||
newHeaders.set("Cross-Origin-Resource-Policy", "cross-origin");
|
||||
}
|
||||
newHeaders.set("Cross-Origin-Opener-Policy", "same-origin");
|
||||
|
||||
return new Response(response.body, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: newHeaders,
|
||||
});
|
||||
})
|
||||
.catch((e) => console.error(e))
|
||||
);
|
||||
});
|
||||
|
||||
} else {
|
||||
(() => {
|
||||
const reloadedBySelf = window.sessionStorage.getItem("coiReloadedBySelf");
|
||||
window.sessionStorage.removeItem("coiReloadedBySelf");
|
||||
const coepDegrading = (reloadedBySelf == "coepdegrade");
|
||||
|
||||
// You can customize the behavior of this script through a global `coi` variable.
|
||||
const coi = {
|
||||
shouldRegister: () => !reloadedBySelf,
|
||||
shouldDeregister: () => false,
|
||||
coepCredentialless: () => true,
|
||||
coepDegrade: () => true,
|
||||
doReload: () => window.location.reload(),
|
||||
quiet: false,
|
||||
...window.coi
|
||||
};
|
||||
|
||||
const n = navigator;
|
||||
const controlling = n.serviceWorker && n.serviceWorker.controller;
|
||||
|
||||
// Record the failure if the page is served by serviceWorker.
|
||||
if (controlling && !window.crossOriginIsolated) {
|
||||
window.sessionStorage.setItem("coiCoepHasFailed", "true");
|
||||
}
|
||||
const coepHasFailed = window.sessionStorage.getItem("coiCoepHasFailed");
|
||||
|
||||
if (controlling) {
|
||||
// Reload only on the first failure.
|
||||
const reloadToDegrade = coi.coepDegrade() && !(
|
||||
coepDegrading || window.crossOriginIsolated
|
||||
);
|
||||
n.serviceWorker.controller.postMessage({
|
||||
type: "coepCredentialless",
|
||||
value: (reloadToDegrade || coepHasFailed && coi.coepDegrade())
|
||||
? false
|
||||
: coi.coepCredentialless(),
|
||||
});
|
||||
if (reloadToDegrade) {
|
||||
!coi.quiet && console.log("Reloading page to degrade COEP.");
|
||||
window.sessionStorage.setItem("coiReloadedBySelf", "coepdegrade");
|
||||
coi.doReload("coepdegrade");
|
||||
}
|
||||
|
||||
if (coi.shouldDeregister()) {
|
||||
n.serviceWorker.controller.postMessage({ type: "deregister" });
|
||||
}
|
||||
}
|
||||
|
||||
// If we're already coi: do nothing. Perhaps it's due to this script doing its job, or COOP/COEP are
|
||||
// already set from the origin server. Also if the browser has no notion of crossOriginIsolated, just give up here.
|
||||
if (window.crossOriginIsolated !== false || !coi.shouldRegister()) return;
|
||||
|
||||
if (!window.isSecureContext) {
|
||||
!coi.quiet && console.log("COOP/COEP Service Worker not registered, a secure context is required.");
|
||||
return;
|
||||
}
|
||||
|
||||
// In some environments (e.g. Firefox private mode) this won't be available
|
||||
if (!n.serviceWorker) {
|
||||
!coi.quiet && console.error("COOP/COEP Service Worker not registered, perhaps due to private mode.");
|
||||
return;
|
||||
}
|
||||
|
||||
n.serviceWorker.register(window.document.currentScript.src).then(
|
||||
(registration) => {
|
||||
!coi.quiet && console.log("COOP/COEP Service Worker registered", registration.scope);
|
||||
|
||||
registration.addEventListener("updatefound", () => {
|
||||
!coi.quiet && console.log("Reloading page to make use of updated COOP/COEP Service Worker.");
|
||||
window.sessionStorage.setItem("coiReloadedBySelf", "updatefound");
|
||||
coi.doReload();
|
||||
});
|
||||
|
||||
// If the registration is active, but it's not controlling the page
|
||||
if (registration.active && !n.serviceWorker.controller) {
|
||||
!coi.quiet && console.log("Reloading page to make use of COOP/COEP Service Worker.");
|
||||
window.sessionStorage.setItem("coiReloadedBySelf", "notcontrolling");
|
||||
coi.doReload();
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
!coi.quiet && console.error("COOP/COEP Service Worker failed to register:", err);
|
||||
}
|
||||
);
|
||||
})();
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WebAssembly Test</title>
|
||||
<style>
|
||||
body {
|
||||
margin: auto;
|
||||
padding-top: 1rem;
|
||||
width: 100%;
|
||||
min-height: 100dvh;
|
||||
background-color: #121212;
|
||||
color: #ffffff;
|
||||
font-family: 'Arial', sans-serif;
|
||||
max-width: 65rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: center;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 2.5em;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
a {
|
||||
color: #1e90ff;
|
||||
text-decoration: none;
|
||||
font-size: 1.1em;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #00bfff;
|
||||
}
|
||||
|
||||
.canvas-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
canvas {
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
|
||||
border: 2px solid #1e90ff;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 1.5em;
|
||||
color: #1e90ff;
|
||||
font-weight: bold;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.description {
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
.description p {
|
||||
line-height: 1.6;
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
.instructions {
|
||||
text-align: center;
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
.instructions p {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
kbd {
|
||||
background-color: #333;
|
||||
border-radius: 3px;
|
||||
border: 1px solid #666;
|
||||
box-shadow: 0 1px 0 #666, 0 1px 0 1px rgba(255, 255, 255, 0.1);
|
||||
color: #fff;
|
||||
display: inline-block;
|
||||
font-size: 1em;
|
||||
line-height: 1.4;
|
||||
padding: 2px 6px;
|
||||
margin: 0 2px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<h1>WebAssembly Test</h1>
|
||||
<a href="https://github.com/codam-coding-college/MLX42" target="_blank">Visit MLX42 GitHub Repo</a>
|
||||
</header>
|
||||
<section class="description">
|
||||
<p>
|
||||
This little demo demonstrates how you compile MLX42 using emscripten to leverage the power of WebAssembly
|
||||
and run any graphical project directly in the web!
|
||||
</p>
|
||||
</section>
|
||||
<div class="canvas-container">
|
||||
<span class="loading">Loading...</span>
|
||||
<canvas width="1024" height="1024" id="canvas"></canvas>
|
||||
</div>
|
||||
<div class="instructions">
|
||||
<p>Use <kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> <kbd>→</kbd> to move the element in the canvas.</p>
|
||||
</div>
|
||||
<script src="coi-serviceworker.js"></script>
|
||||
<script>
|
||||
var Module = {
|
||||
// This is called when the Emscripten module is ready
|
||||
onRuntimeInitialized: () => {
|
||||
console.log("Emscripten module initialized");
|
||||
var loadingText = document.querySelector('.loading');
|
||||
loadingText.style.display = 'none';
|
||||
},
|
||||
canvas: (() => {
|
||||
var canvas = document.getElementById('canvas');
|
||||
canvas.addEventListener("webglcontextlost", function (e) {
|
||||
alert('WebGL context lost. Reload the page.');
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
return canvas;
|
||||
})()
|
||||
};
|
||||
</script>
|
||||
<script src="demo.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -35,16 +35,16 @@ mlx_texture_t *get_texture(t_mlx *mlx, int flag)
|
||||
if (flag == 0)
|
||||
{
|
||||
if (mlx->ray->ray_ngl > M_PI / 2 && mlx->ray->ray_ngl < 3 * (M_PI / 2))
|
||||
return (mlx->tex->ea);
|
||||
else
|
||||
return (mlx->tex->we);
|
||||
else
|
||||
return (mlx->tex->ea);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mlx->ray->ray_ngl > 0 && mlx->ray->ray_ngl < M_PI)
|
||||
return (mlx->tex->so);
|
||||
else
|
||||
return (mlx->tex->no);
|
||||
else
|
||||
return (mlx->tex->so);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||