Archived
1
0

git rm --cached

This commit is contained in:
Adam Joly
2024-01-06 17:17:52 +01:00
parent d4fd4c2949
commit 9e19633e10
570 changed files with 397857 additions and 1 deletions

365
MacroLibX/includes/mlx.h Normal file
View File

@ -0,0 +1,365 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mlx.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
/* Updated: 2023/12/27 17:19:50 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
// MacroLibX official repo https://github.com/seekrs/MacroLibX
#ifndef __MACRO_LIB_X_H__
#define __MACRO_LIB_X_H__
#include "mlx_profile.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
MLX_KEYDOWN = 0,
MLX_KEYUP = 1,
MLX_MOUSEDOWN = 2,
MLX_MOUSEUP = 3,
MLX_MOUSEWHEEL = 4,
MLX_WINDOW_EVENT = 5
} mlx_event_type;
/**
* @brief Initializes the MLX internal application
*
* @return (void*) An opaque pointer to the internal MLX application or NULL (0x0) in case of error
*/
MLX_API void* mlx_init();
/**
* @brief Creates a new window
*
* @param mlx Internal MLX application
* @param w Width of the window
* @param h Height of the window
* @param title Title of the window
*
* @return (void*) An opaque pointer to the internal MLX window or NULL (0x0) in case of error
*/
MLX_API void* mlx_new_window(void* mlx, int w, int h, const char* title);
/**
* @brief Gives a function to be executed at each loop turn
*
* @param mlx Internal MLX application
* @param f The function
* @param param Param to give to the function passed
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_loop_hook(void* mlx, int (*f)(void*), void* param);
/**
* @brief Starts the internal main loop
*
* @param mlx Internal MLX application
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_loop(void* mlx);
/**
* @brief Ends the internal main loop
*
* @param mlx Internal MLX application
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_loop_end(void* mlx);
/**
* @brief Shows mouse cursor
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_mouse_show();
/**
* @brief Hides mouse cursor
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_mouse_hide();
/**
* @brief Moves cursor to givent position
*
* @param mlx Internal MLX application
* @param win Internal window from which cursor moves
* @param x X coordinate
* @param y Y coordinate
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_mouse_move(void* mlx, void* win, int x, int y);
/**
* @brief Get cursor's position
*
* @param mlx Internal MLX application
* @param x Get x coordinate
* @param y Get y coordinate
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_mouse_get_pos(void* mlx, int* x, int* y);
/**
* @brief Gives a function to be executed on event type
*
* @param mlx Internal MLX application
* @param win Internal window
* @param event Event type (see union on top of this file)
* @param f Function to be executed
* @param param Parameter given to the function
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*f)(int, void*), void* param);
/**
* @brief Put a pixel in the window
*
* @param mlx Internal MLX application
* @param win Internal window
* @param x X coordinate
* @param y Y coordinate
* @param color Color of the pixel (coded on 3 bytes in an int, 0x00RRGGBB)
*
* Note : If your're reading pixel colors from an image, don't forget to shift them
* one byte to the right as image pixels are encoded as 0xRRGGBBAA and pixel put takes 0x00RRGGBB.
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_pixel_put(void* mlx, void* win, int x, int y, int color);
/**
* @brief Create a new empty image
*
* @param mlx Internal MLX application
* @param width Width of the image
* @param height Height of the image
*
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
*/
MLX_API void* mlx_new_image(void* mlx, int width, int height);
/**
* @brief Get image pixel data
*
* @param mlx Internal MLX application
* @param img Internal image
* @param x X coordinate in the image
* @param y Y coordinate in the image
*
* @return (int) Return the pixel data
*
* /!\ If you run into glitches when writing or reading pixels from images /!\
* You need to add IMAGES_OPTIMIZED=false to your make mlx command
* ```
* ~ git clone https://github.com/seekrs/MacroLibX.git
* ~ cd MacroLibX
* ~ make IMAGES_OPTIMIZED=false
* ```
*/
MLX_API int mlx_get_image_pixel(void* mlx, void* img, int x, int y);
/**
* @brief Set image pixel data
*
* @param mlx Internal MLX application
* @param img Internal image
* @param x X coordinate in the image
* @param y Y coordinate in the image
* @param color Color of the pixel to set
*
* @return (void)
*
* /!\ If you run into glitches when writing or reading pixels from images /!\
* You need to add IMAGES_OPTIMIZED=false to your make mlx command
* ```
* ~ git clone https://github.com/seekrs/MacroLibX.git
* ~ cd MacroLibX
* ~ make IMAGES_OPTIMIZED=false
* ```
*/
MLX_API void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color);
/**
* @brief Put image to the given window
*
* @param mlx Internal MLX application
* @param win Internal window
* @param img Internal image
* @param x X coordinate
* @param y Y coordinate
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y);
/**
* @brief Destroys internal image
*
* @param mlx Internal MLX application
* @param img Internal image
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_destroy_image(void* mlx, void* img);
/**
* @brief Create a new image from a png file
*
* @param mlx Internal MLX application
* @param filename Path to the png file
* @param width Get the width of the image
* @param heigth Get the height of the image
*
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
*/
MLX_API void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height);
/**
* @brief Create a new image from a jpg file
*
* @param mlx Internal MLX application
* @param filename Path to the jpg file
* @param width Get the width of the image
* @param heigth Get the height of the image
*
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
*/
MLX_API void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height);
/**
* @brief Create a new image from a bmp file
*
* @param mlx Internal MLX application
* @param filename Path to the bmp file
* @param width Get the width of the image
* @param heigth Get the height of the image
*
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
*/
MLX_API void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height);
/**
* @brief Put text in given window
*
* @param mlx Internal MLX application
* @param win Internal window
* @param x X coordinate
* @param y Y coordinate
* @param color Color of the pixel (coded on 3 bytes in an int, 0x00RRGGBB)
* @param str Text to put
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str);
/**
* @brief Loads a font to be used by `mlx_string_put`
*
* @param mlx Internal MLX application
* @param win Internal window
* @param filepath Filepath to the font or "default" to reset to the embedded font
*
* @return (void)
*/
MLX_API void mlx_set_font(void* mlx, void* win, char* filepath);
/**
* @brief Loads a font to be used by `mlx_string_put` and scales it
*
* @param mlx Internal MLX application
* @param win Internal window
* @param filepath Filepath to the font or "default" to reset to the embedded font
* @param scale Scale to apply to the font
*
* @return (void)
*/
MLX_API void mlx_set_font_scale(void* mlx, void* win, char* filepath, float scale);
/**
* @brief Clears the given window (resets all rendered data)
*
* @param mlx Internal MLX application
* @param win Internal window
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_clear_window(void* mlx, void* win);
/**
* @brief Destroys internal window
*
* @param mlx Internal MLX application
* @param win Internal window
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_destroy_window(void* mlx, void* win);
/**
* @brief Destroy internal MLX application
*
* @param mlx Internal MLX application
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_destroy_display(void* mlx);
/**
* @brief Get screen size
*
* @param mlx Internal MLX application
* @param x Get X size
* @param y Get Y size
*
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
*/
MLX_API int mlx_get_screens_size(void* mlx, int* w, int* h);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,215 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mlx_profile.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/10 08:49:17 by maldavid #+# #+# */
/* Updated: 2024/01/03 15:33:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_PROFILE__
#define __MLX_PROFILE__
// Try to identify the compiler
#if defined(__BORLANDC__)
#define MLX_COMPILER_BORDLAND
#elif defined(__clang__)
#define MLX_COMPILER_CLANG
#ifdef __MINGW32__
#define MLX_COMPILER_MINGW
#ifdef __MINGW64_VERSION_MAJOR
#define MLX_COMPILER_MINGW_W64
#endif
#endif
#elif defined(__GNUC__) || defined(__MINGW32__)
#define MLX_COMPILER_GCC
#ifdef __MINGW32__
#define MLX_COMPILER_MINGW
#ifdef __MINGW64_VERSION_MAJOR
#define MLX_COMPILER_MINGW_W64
#endif
#endif
#elif defined(__INTEL_COMPILER) || defined(__ICL)
#define MLX_COMPILER_INTEL
#elif defined(_MSC_VER)
#define MLX_COMPILER_MSVC
#else
#define MLX_COMPILER_UNKNOWN
#warning "This compiler is not fully supported"
#endif
#if defined(_WIN32) || defined(__CYGWIN__)
#define MLX_PLAT_WINDOWS
#elif defined(__linux__)
#define MLX_PLAT_LINUX
#elif defined(__APPLE__) && defined(__MACH__)
#define MLX_PLAT_MACOS
#elif defined(unix) || defined(__unix__) || defined(__unix)
#define MLX_PLAT_UNIX
#else
#error "Unknown environment (not Windows, not Linux, not MacOS, not Unix)"
#endif
#ifdef MLX_PLAT_WINDOWS
#ifdef MLX_COMPILER_MSVC
#ifdef MLX_BUILD
#define MLX_API __declspec(dllexport)
#else
#define MLX_API __declspec(dllimport)
#endif
#elif defined(MLX_COMPILER_GCC)
#ifdef MLX_BUILD
#define MLX_API __attribute__((dllexport))
#else
#define MLX_API __attribute__((dllimport))
#endif
#else
#define MLX_API
#endif
#elif defined(MLX_COMPILER_GCC)
#define MLX_API __attribute__((visibility("default")))
#else
#define MLX_API
#endif
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__)
#define MLX_FUNC_SIG __PRETTY_FUNCTION__
#elif defined(__DMC__) && (__DMC__ >= 0x810)
#define MLX_FUNC_SIG __PRETTY_FUNCTION__
#elif (defined(__FUNCSIG__) || (_MSC_VER))
#define MLX_FUNC_SIG __FUNCSIG__
#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
#define MLX_FUNC_SIG __FUNCTION__
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
#define MLX_FUNC_SIG __FUNC__
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
#define MLX_FUNC_SIG __func__
#elif defined(__cplusplus) && (__cplusplus >= 201103)
#define MLX_FUNC_SIG __func__
#else
#define MLX_FUNC_SIG "Unknown function"
#endif
#ifndef __cplusplus // if we compile in C
#ifdef __STDC__
#ifdef __STDC_VERSION__
#if __STDC_VERSION__ == 199409L
#define MLX_C_VERSION 1994
#elif __STDC_VERSION__ == 199901L
#define MLX_C_VERSION 1999
#elif __STDC_VERSION__ == 201112L
#define MLX_C_VERSION 2011
#elif __STDC_VERSION__ == 201710L
#define MLX_C_VERSION 2017
#elif __STDC_VERSION__ == 202311L
#define MLX_C_VERSION 2023
#else
#define MLX_C_VERSION 0
#endif
#else
#define MLX_C_VERSION 0
#endif
#else
#define MLX_C_VERSION 0
#endif
#else
#define MLX_C_VERSION 0
#endif
#if defined(MLX_PLAT_WINDOWS)
#define VK_USE_PLATFORM_WIN32_KHR
#ifdef __cplusplus
constexpr const char* VULKAN_LIB_NAME = "vulkan-1.dll";
#endif
#elif defined(MLX_PLAT_MACOS)
#define VK_USE_PLATFORM_MACOS_MVK
#define VK_USE_PLATFORM_METAL_EXT
#ifdef __cplusplus
constexpr const char* VULKAN_LIB_NAME = "libvulkan.dylib / libvulkan.1.dylib / libMoltenVK.dylib";
#endif
#else
#define VK_USE_PLATFORM_XLIB_KHR
#define VK_USE_PLATFORM_WAYLAND_KHR
#ifdef __cplusplus
constexpr const char* VULKAN_LIB_NAME = "libvulkan.so / libvulkan.so.1";
#endif
#endif
// Checking common assumptions
#ifdef __cplusplus
#include <climits>
#include <cstdint>
static_assert(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
#elif MLX_C_VERSION >= 2011
#if MLX_C_VERSION < 2023
#include <assert.h>
#endif
#include <limits.h>
#include <stdint.h>
static_assert(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
#elif defined(MLX_COMPILER_GCC)
#define STATIC_ASSERT(cnd, descr) \
({ \
extern int __attribute__((error("static assert failed: (" #cnd ") (" #descr ")"))) compile_time_check(void); \
((cnd) ? 0 : compile_time_check()), 0; \
})
#include <limits.h>
#include <stdint.h>
STATIC_ASSERT(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
STATIC_ASSERT(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
STATIC_ASSERT(sizeof(int16_t) == 2, "int16_t is not of the correct size");
STATIC_ASSERT(sizeof(int32_t) == 4, "int32_t is not of the correct size");
STATIC_ASSERT(sizeof(int64_t) == 8, "int64_t is not of the correct size");
STATIC_ASSERT(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
STATIC_ASSERT(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
STATIC_ASSERT(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
STATIC_ASSERT(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
#else
#define STATIC_ASSERT(COND, MSG) typedef char static_assertion___##MSG[(COND)?1:-1]
#include <limits.h>
#include <stdint.h>
STATIC_ASSERT(CHAR_BIT == 8, CHAR_BIT_is_expected_to_be_8);
STATIC_ASSERT(sizeof(int8_t) == 1, int8_t_is_not_of_the_correct_size);
STATIC_ASSERT(sizeof(int16_t) == 2, int16_t_is_not_of_the_correct_size);
STATIC_ASSERT(sizeof(int32_t) == 4, int32_t_is_not_of_the_correct_size);
STATIC_ASSERT(sizeof(int64_t) == 8, int64_t_is_not_of_the_correct_size);
STATIC_ASSERT(sizeof(uint8_t) == 1, uint8_t_is_not_of_the_correct_size);
STATIC_ASSERT(sizeof(uint16_t) == 2, uint16_t_is_not_of_the_correct_size);
STATIC_ASSERT(sizeof(uint32_t) == 4, uint32_t_is_not_of_the_correct_size);
STATIC_ASSERT(sizeof(uint64_t) == 8, uint64_t_is_not_of_the_correct_size);
#endif
#endif