MLX42 1.0
MLX42
|
#include "MLX42/MLX42.h"
#include "lodepng/lodepng.h"
#include "glad/glad.h"
#include "KHR/khrplatform.h"
#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <memory.h>
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
Go to the source code of this file.
Data Structures | |
struct | vertex |
struct | mlx_list |
struct | mlx_srcoll |
struct | mlx_mouse |
struct | mlx_cursor |
struct | mlx_close |
struct | mlx_resize |
struct | mlx_key |
struct | mlx_hook |
struct | mlx_ctx |
struct | draw_queue |
struct | mlx_image_ctx |
Macros | |
#define | LODEPNG_NO_COMPILE_ALLOCATORS |
#define | MLX_SWAP_INTERVAL 1 |
#define | MLX_BATCH_SIZE 12000 |
#define | BPP sizeof(int32_t) /* Only support RGBA */ |
#define | GETLINE_BUFF 1280 |
#define | MLX_MAX_STRING 512 /* Arbitrary string limit */ |
#define | MLX_ASSERT(cond, msg) assert(cond && msg); |
#define | MLX_NONNULL(var) MLX_ASSERT(var, "Value can't be null"); /* Assert instead of attribute */ |
Variables | |
const char * | vert_shader |
const char * | frag_shader |
bool | sort_queue |
int32_t | mlx_settings [MLX_SETTINGS_MAX] |
#define GETLINE_BUFF 1280 |
Definition at line 43 of file MLX42_Int.h.
#define LODEPNG_NO_COMPILE_ALLOCATORS |
Definition at line 15 of file MLX42_Int.h.
#define MLX_BATCH_SIZE 12000 |
Definition at line 40 of file MLX42_Int.h.
#define MLX_NONNULL | ( | var | ) | MLX_ASSERT(var, "Value can't be null"); /* Assert instead of attribute */ |
Definition at line 46 of file MLX42_Int.h.
#define MLX_SWAP_INTERVAL 1 |
Definition at line 37 of file MLX42_Int.h.
For rendering we need to store most of OpenGL's stuff such as the vertex array object, vertex buffer object & the shader program as well as hooks and the zdepth level.
Additionally we represent draw calls with a linked list queue that points to the image and the index of its instance. Again, instances only carry XYZ data, so coupled with the image it lets us know where to draw a copy of the image.
Texture contexts are kept in a struct alongside the capacity of the array of instances, since the array is realloced like a vector.
There are 2 types of hooks, special and generics.
Specials: Specials are specific callback functions to a specific action such as window resizing or key presses. These are attached to the callbacks of glfw. In case MLX itself needs the callback we call the specials in that callback since there can only ever be a single callback.
Generics: Generics are MLX42 specific hooks and can have multiple hooks at the same time, these are executed every frame and can be used as an alternative for keypresses or animations for instance.
NOTE: Hooks could be achieved with va_args to have any amount of args sized functor but we can't/don't want to let the user deal with va_args and having to look up what args are what, etc...
We want to keep it straightforward with functors already describing what params they have.
void mlx_draw_instance | ( | mlx_ctx_t * | mlx, |
mlx_image_t * | img, | ||
mlx_instance_t * | instance | ||
) |
Internal function to draw a single instance of an image to the screen.
Definition at line 63 of file mlx_images.c.
Definition at line 17 of file mlx_compare.c.
Definition at line 25 of file mlx_compare.c.
bool mlx_error | ( | mlx_errno_t | val | ) |
Functions to set the error number, simply for convenience.
val | The error value. |
Definition at line 43 of file mlx_error.c.
Definition at line 17 of file mlx_images.c.
String hashing algorithm using FNV-1a. Source: https://bit.ly/3JcRGHa
str | The string to hash |
len | The length of the string. |
Definition at line 68 of file mlx_utils.c.
Utility function that lets you free x amount of pointers.
count | The amount of args provided. |
... | Any form of pointer. |
Definition at line 89 of file mlx_utils.c.
Function to read a file stream line by line, reusing the same output pointer. Since the same output pointer is reused it should only be freed once, either on success or failure. This function is made to be somewhat similar to getline. Getline can't be used directly since it's not standard and therefore not available on all platforms.
out | Pointer to store output string. |
out_size | Pointer to store output strings length. |
file | File stream to read from. |
Definition at line 28 of file mlx_utils.c.
void mlx_lstadd_back | ( | mlx_list_t ** | lst, |
mlx_list_t * | new | ||
) |
Definition at line 67 of file mlx_list.c.
void mlx_lstadd_front | ( | mlx_list_t ** | lst, |
mlx_list_t * | new | ||
) |
void mlx_lstclear | ( | mlx_list_t ** | lst, |
void(*)(void *) | del | ||
) |
Definition at line 33 of file mlx_list.c.
mlx_list_t * mlx_lstlast | ( | mlx_list_t * | lst | ) |
mlx_list_t * mlx_lstnew | ( | void * | content | ) |
All sorts of internal functions shared in the library that should not be accessible to the user! No touch!
Definition at line 45 of file mlx_list.c.
mlx_list_t * mlx_lstremove | ( | mlx_list_t ** | lst, |
void * | value, | ||
bool(*)(void *, void *) | comp | ||
) |
Removes the specified content from the list, if found. Also fixes any relinking that might be needed.
[in] | lst | The list |
[in] | comp | Function to check if the content and value are the same. |
Definition at line 100 of file mlx_list.c.
int32_t mlx_lstsize | ( | mlx_list_t * | lst | ) |
Converts an RGBA value to a monochrome/grayscale value. It does so using specific weights for each channel.
color | The input RGBA value. |
Definition at line 109 of file mlx_utils.c.
void mlx_sort_renderqueue | ( | mlx_list_t ** | lst | ) |
Okay-ish sorting algorithm to sort the render queue / doubly linked list. We need to do this to fix transparency.
lst | The render queue. |
Definition at line 161 of file mlx_list.c.
Recalculate the view projection matrix, used by images for screen pos Reference: https://bit.ly/3KuHOu1 (Matrix View Projection)
In case the setting to stretch the image is set, we maintain the width and height but not the depth.
Definition at line 21 of file mlx_window.c.
|
extern |
Definition at line 160 of file mlx_init.c.
|
extern |
Definition at line 162 of file mlx_init.c.
The shader code is extracted from the shader files and converted to a .c file as a single string at compile time. This keeps shader files external but still integrated into the program letting you use the executable anywhere without having to take the shaders with you.
Most modern frameworks like .NET do this by having resource files instead.