{"id":19370325,"url":"https://github.com/codam-coding-college/mlx42","last_synced_at":"2025-10-24T10:55:28.549Z","repository":{"id":37091605,"uuid":"443534015","full_name":"codam-coding-college/MLX42","owner":"codam-coding-college","description":"Codam's own fixed, functioning and open source alternative of the miniLibX. MLX42 is a simple cross-platform graphics library running on GLFW and OpenGL.","archived":false,"fork":false,"pushed_at":"2025-08-20T09:56:13.000Z","size":5938,"stargazers_count":462,"open_issues_count":1,"forks_count":72,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-16T15:19:34.648Z","etag":null,"topics":["42","42born2code","42pleaseadoptmefinally","42school","c","cocoa","codam","cross-platform","glfw","graphics","graphics-library","linux","macos","minilibx","mlx","mlx42","opengl","winapi","windows","x11"],"latest_commit_sha":null,"homepage":"https://codam-coding-college.github.io/MLX42/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codam-coding-college.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-01-01T12:27:16.000Z","updated_at":"2025-10-11T16:45:54.000Z","dependencies_parsed_at":"2023-02-01T07:46:00.985Z","dependency_job_id":"e95de05e-049d-4924-b0df-77d6251e1f5f","html_url":"https://github.com/codam-coding-college/MLX42","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/codam-coding-college/MLX42","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codam-coding-college%2FMLX42","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codam-coding-college%2FMLX42/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codam-coding-college%2FMLX42/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codam-coding-college%2FMLX42/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codam-coding-college","download_url":"https://codeload.github.com/codam-coding-college/MLX42/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codam-coding-college%2FMLX42/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280783850,"owners_count":26390279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["42","42born2code","42pleaseadoptmefinally","42school","c","cocoa","codam","cross-platform","glfw","graphics","graphics-library","linux","macos","minilibx","mlx","mlx42","opengl","winapi","windows","x11"],"created_at":"2024-11-10T08:14:59.057Z","updated_at":"2025-10-24T10:55:28.532Z","avatar_url":"https://github.com/codam-coding-college.png","language":"C","readme":"\u003c/br\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/63303990/150698103-7e908ff3-abf8-4b0f-ad54-07a76b6c45e2.png\" alt=\"42MLX_Logo\"\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003csub\u003eWritten by \u003ca href=\"https://portfolio.w2wizard.dev/\"\u003eW2.Wizard\u003c/a\u003e for Codam\u003c/sub\u003e\n    \u003cdiv align=\"center\"\u003e\n\t\u003c/br\u003e\n\t\u003cimg src=\"https://img.shields.io/github/license/codam-coding-college/MLX42\" alt=\"License GPL2.0\"\u003e \n\t\u003cimg src=\"https://github.com/codam-coding-college/MLX42/actions/workflows/ci.yml/badge.svg\" alt=\"Build\"\u003e\n\t\u003cimg src=\"https://img.shields.io/github/forks/codam-coding-college/MLX42\" alt=\"Forks\"\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n\nMLX42 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.\n\nIt provides primitive tools to draw textures onto the window as well as modifying them at runtime as they get displayed on the window.\n\n\u003e [!IMPORTANT]\n\u003e 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.\n\n# Features ✨\n\nMLX42 comes with a plethora of features that make using it actually a joy instead of a chore.\n\n## Cross-Platform 🖥️\n\nRun it on your grandma's WindowsXP, on your uncle's debian or on a hipster's MacOS!\nNo matter what the platform, if MLX42 can build on it, it will run on its native windowing system. \n\nThis allows you to work on your project no matter which machine it is on.\n\n## Documented 📚\n\nMLX42 cares about good documentation, every function, usage and even some internal workings are documented!\nNo more guessing and searching how something functions or is supposed to work.\n\n## Performance 🚀\n\nIt is built on OpenGL and uses batched rendering to speed up the rendering process compared to other libraries.\n\n## Open source \u0026\u0026 Community driven 🌐\nThis 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.\n\n## Emscripten Compatibility 🚀\nMLX42 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.\n\n### Highlights\n- **Emscripten Support**: Compile MLX42 with Emscripten, enabling graphical applications to run in a web environment.\n- **WebAssembly Compatibility**: Ensures that MLX42 can be utilized in modern web browsers, expanding its usability beyond traditional desktop environments.\n- **Updated Documentation**: Provided guidance on how to build and run MLX42 projects using Emscripten.\n\n---\n\n## Installation 🏗️\n### General compilation\n\nOverall the building of this project is as follows for ALL systems. As long as CMake can make sense of it.\n\n1. [Download and build MLX42](#download-and-build---mlx42) \n\nIn case your system doesn't have [glfw](https://github.com/glfw/glfw) installed cmake will detect this and download it for you.\nYou 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.\nSame goes for CMake or any other dependencies you might need for your system.\n\nHowever 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.\n\n\u003e [!NOTE]\n\u003e For Codam, GLFW is already installed on the Macs.\n\n\u003e [!NOTE]\n\u003e During the linking stage, the flag to link GLFW can either be: -lglfw3 or -lglfw depending on your system.\n\n1. Compile your program with the library:\n\t- For: [MacOS](#for-macos)\n\t- For: [Linux](#for-linux)\n\t- For: [Windows](#for-windows)\n\n2. Profit!\n\n### Installing to the system\n\nTo fully build the library and install it to your system run the following command:\n```bash\ncmake -B build \u0026\u0026 cmake --build build --parallel --config (Debug|Release|RelWithDebInfo|MinSizeRel) --target install\n```\n\nBy 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.\n\n### Unit tests\nMLX42 comes with some unit tests to ensure the integrity of the library, to build them run the following command:\n```sh\ncmake -DBUILD_TESTS=ON -B build \u0026\u0026 cmake --build build --parallel\n```\n\nThen simply run them with:\n```sh\nctest --output-on-failure --test-dir build\n```\n\n----\n\n## Download and build - MLX42\n\n```bash \ngit clone https://github.com/codam-coding-college/MLX42.git\ncd MLX42\ncmake -B build # build here refers to the outputfolder.\ncmake --build build -j4 # or do make -C build -j4\n```\n\nThe output library file is called `libmlx42.a` and is located in the `build` folder that you specified.\n\n### Available Options\n\nYou 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.\n\nYou can find an example makefile in the documentation [here](https://github.com/codam-coding-college/MLX42/blob/master/docs/Basics.md).\n\n----\n\n## For MacOS:\n\n### Installing the dependencies\n\nIf your system has neither GLFW nor CMake its highly recommended you use brew to install those missing dependencies.\n\nFor 42 Campuses you can use: [42Homebrew](https://github.com/kube/42homebrew)\n\nOtherwise with homebrew:\n```bash\nbrew install glfw\nbrew install cmake\n```\nIf you are using Apple Silicon (M1 chip or later), note that the Homebrew install path is different.\nYou may want to update your shell configuration file. For Zsh users (default shell on newer macOS versions):\n```bash\nnano ~/.zshrc\nexport LIBRARY_PATH=/opt/homebrew/lib\n```\nRestart your shell session or restart your terminal for the changes to take effect.\n\nFor MacOS you need to use the following flags to compile your program with the library\nin order to link the program with the correct frameworks:\n```bash\n-framework Cocoa -framework OpenGL -framework IOKit\n```\n\nNormally if you simply installed / built `glfw` from source or already have it installed\nthe compilation should be:\n```bash\ngcc main.c ... libmlx42.a -Iinclude -lglfw\n```\n\n#### Via [Homebrew](https://brew.sh/) / [42Homebrew](https://github.com/kube/42homebrew)\n```bash\n# Homebrew\ngcc main.c ... libmlx42.a -Iinclude -lglfw -L\"/opt/homebrew/Cellar/glfw/3.3.8/lib/\"\n\n# 42Homebrew\ngcc main.c ... libmlx42.a -Iinclude -lglfw -L\"/Users/$(USER)/.brew/opt/glfw/lib/\"\n```\n\n#### MacOS Security:\n\nWhen running your program in MacOS it may complain, because with Macs you just gotta think differently.\nIn case of any security warnings or MacOS telling you it can't verify the author/developer, go to ```Settings \u003e Security \u0026 Privacy```.\n\nThere will be a pop-up at the bottom telling you that an application tried to run, click the option to let it run.\n\n----\n\n## For Linux:\n\n1. Install the necessary packages:\n\nFor Debian like (Ubuntu, Mint, Pop OS...):\n```bash \nsudo apt update\nsudo apt install build-essential libx11-dev libglfw3-dev libglfw3 xorg-dev\n```\n\nFor Arch-linux (Manjaro, Endeavor, Garuda):\n```bash\nsudo pacman -S glfw-x11\n```\nOR (if you use sway/wlroots compositor or other wayland compositor)\n\n```bash\nsudo pacman -S glfw-wayland\n```\n\n2. [Download and build MLX42](#download-and-build---mlx42) \n\n3. Compile your program with the library:\n\n```bash\ngcc main.c ... libmlx42.a -Iinclude -ldl -lglfw -pthread -lm\n```\n4. Profit!\n\n----\n\n## For Windows (with Windows Subsystem for Linux 2 (WSL2))\n\n\u003e [!IMPORTANT]\n\u003e Before starting with all these steps, [read this](https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps)\n\n1. Set these variables in your `.zshrc` or `.bashrc`:\n```bash\nexport DISPLAY=$(ip route list default | awk '{print $3}'):0\nexport LIBGL_ALWAYS_INDIRECT=0\n```\n(If the DISPLAY export command is failing, see this [StackOverflow](https://stackoverflow.com/a/61110604) post for alternatives)\n\n2. Download and install an XServer application with extended configuration (XMing does not qualify)\nVcXsrv works: https://sourceforge.net/projects/vcxsrv/\n\n3. Open Windows Defender Firewall, and follow these steps:\n- Go to 'Allow an app or feature through Windows Defender Firewall'\n- Change Settings\n- Find the installed XServer, for VcXsrv that's 'VcXsrv windows server'\n- Enable communication over Private **and** Public network\nOptionally you might be able to provide these settings on first launch of the XServer application,\nand they might not even show up in the list until the first time you start the app.\n\n4. Start the XLaunch application (for VcXsrv) and provide these configuration settings:\n- Leave Display number on auto\n- Start no client\n- **UNTICK** `Native opengl` option\n- **TICK** `Disable access control`\n- Finish starting the server\n\n5. Probably all the other steps for Linux apply, just clone, build and run.\n\n----\n\n## For Windows Native:\n\n\u003e [!IMPORTANT]\n\u003e Be aware that Visual Studio (2022) is required for this. Developing on Windows can be somewhat frustrating.\n\nWe highly recommend you simply use [WSL2](#for-windows-with-windows-subsystem-for-linux-2-wsl2) to make this as painless as possible.\nHowever if you insist on building for windows natively then all you need in terms of dependencies is:\n\n- [CMake](https://cmake.org/download/)\n- [GLFW](https://www.glfw.org/download.html)\n\nOnce you have all the dependencies correctly installed `CMake` will generate\nthe visual studio project files. Simply build it and once you have a `.lib` file\nmove them to your actual project and install them as you would with any other library.\n\nJust 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`.\n\nOf 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`.\n\n## Example\n\n![MLX42](docs/assets/demo.gif)\n\n```c\n// -----------------------------------------------------------------------------\n// Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.\n// See README in the root project for more information.\n// -----------------------------------------------------------------------------\n\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstdbool.h\u003e\n#include \u003cMLX42/MLX42.h\u003e\n\n#define WIDTH 512\n#define HEIGHT 512\n\nstatic mlx_image_t* image;\n\n// -----------------------------------------------------------------------------\n\nint32_t ft_pixel(int32_t r, int32_t g, int32_t b, int32_t a)\n{\n    return (r \u003c\u003c 24 | g \u003c\u003c 16 | b \u003c\u003c 8 | a);\n}\n\nvoid ft_randomize(void* param)\n{\n\t(void)param;\n\tfor (uint32_t i = 0; i \u003c image-\u003ewidth; ++i)\n\t{\n\t\tfor (uint32_t y = 0; y \u003c image-\u003eheight; ++y)\n\t\t{\n\t\t\tuint32_t color = ft_pixel(\n\t\t\t\trand() % 0xFF, // R\n\t\t\t\trand() % 0xFF, // G\n\t\t\t\trand() % 0xFF, // B\n\t\t\t\trand() % 0xFF  // A\n\t\t\t);\n\t\t\tmlx_put_pixel(image, i, y, color);\n\t\t}\n\t}\n}\n\nvoid ft_hook(void* param)\n{\n\tmlx_t* mlx = param;\n\n\tif (mlx_is_key_down(mlx, MLX_KEY_ESCAPE))\n\t\tmlx_close_window(mlx);\n\tif (mlx_is_key_down(mlx, MLX_KEY_UP))\n\t\timage-\u003einstances[0].y -= 5;\n\tif (mlx_is_key_down(mlx, MLX_KEY_DOWN))\n\t\timage-\u003einstances[0].y += 5;\n\tif (mlx_is_key_down(mlx, MLX_KEY_LEFT))\n\t\timage-\u003einstances[0].x -= 5;\n\tif (mlx_is_key_down(mlx, MLX_KEY_RIGHT))\n\t\timage-\u003einstances[0].x += 5;\n}\n\n// -----------------------------------------------------------------------------\n\nint32_t main(void)\n{\n\tmlx_t* mlx;\n\n\t// Gotta error check this stuff\n\tif (!(mlx = mlx_init(WIDTH, HEIGHT, \"MLX42\", true)))\n\t{\n\t\tputs(mlx_strerror(mlx_errno));\n\t\treturn(EXIT_FAILURE);\n\t}\n\tif (!(image = mlx_new_image(mlx, 128, 128)))\n\t{\n\t\tmlx_close_window(mlx);\n\t\tputs(mlx_strerror(mlx_errno));\n\t\treturn(EXIT_FAILURE);\n\t}\n\tif (mlx_image_to_window(mlx, image, 0, 0) == -1)\n\t{\n\t\tmlx_close_window(mlx);\n\t\tputs(mlx_strerror(mlx_errno));\n\t\treturn(EXIT_FAILURE);\n\t}\n\t\n\tmlx_loop_hook(mlx, ft_randomize, mlx);\n\tmlx_loop_hook(mlx, ft_hook, mlx);\n\n\tmlx_loop(mlx);\n\tmlx_terminate(mlx);\n\treturn (EXIT_SUCCESS);\n}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodam-coding-college%2Fmlx42","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodam-coding-college%2Fmlx42","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodam-coding-college%2Fmlx42/lists"}