MLX42 1.0
MLX42
Loading...
Searching...
No Matches
MLX42.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
Include dependency graph for MLX42.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mlx_texture
 
struct  xpm
 
struct  mlx_instance
 
struct  mlx_key_data
 
struct  mlx_image
 
struct  mlx
 

Typedefs

typedef enum action action_t
 
typedef enum modifier_key modifier_key_t
 
typedef enum mouse_key mouse_key_t
 
typedef enum mouse_mode mouse_mode_t
 
typedef enum cursor cursor_t
 
typedef enum keys keys_t
 
typedef struct mlx_texture mlx_texture_t
 
typedef struct xpm xpm_t
 
typedef struct mlx_instance mlx_instance_t
 
typedef struct mlx_key_data mlx_key_data_t
 
typedef struct mlx_image mlx_image_t
 
typedef struct mlx mlx_t
 
typedef enum mlx_errno mlx_errno_t
 
typedef enum mlx_settings mlx_settings_t
 
typedef void(* mlx_scrollfunc) (double xdelta, double ydelta, void *param)
 
typedef void(* mlx_mousefunc) (mouse_key_t button, action_t action, modifier_key_t mods, void *param)
 
typedef void(* mlx_cursorfunc) (double xpos, double ypos, void *param)
 
typedef void(* mlx_keyfunc) (mlx_key_data_t keydata, void *param)
 
typedef void(* mlx_resizefunc) (int32_t width, int32_t height, void *param)
 
typedef void(* mlx_closefunc) (void *param)
 
typedef void mlx_win_cursor_t
 

Enumerations

enum  action { MLX_RELEASE = 0 , MLX_PRESS = 1 , MLX_REPEAT = 2 }
 
enum  modifier_key {
  MLX_SHIFT = 0x0001 , MLX_CONTROL = 0x0002 , MLX_ALT = 0x0004 , MLX_SUPERKEY = 0x0008 ,
  MLX_CAPSLOCK = 0x0010 , MLX_NUMLOCK = 0x0020
}
 
enum  mouse_key { MLX_MOUSE_BUTTON_LEFT = 0 , MLX_MOUSE_BUTTON_RIGHT = 1 , MLX_MOUSE_BUTTON_MIDDLE = 2 }
 
enum  mouse_mode { MLX_MOUSE_NORMAL = 0x00034001 , MLX_MOUSE_HIDDEN = 0x00034002 , MLX_MOUSE_DISABLED = 0x00034003 }
 
enum  cursor {
  MLX_CURSOR_ARROW = 0x00036001 , MLX_CURSOR_IBEAM = 0x00036002 , MLX_CURSOR_CROSSHAIR = 0x00036003 , MLX_CURSOR_HAND = 0x00036004 ,
  MLX_CURSOR_HRESIZE = 0x00036005 , MLX_CURSOR_VRESIZE = 0x00036006
}
 
enum  keys {
  MLX_KEY_SPACE = 32 , MLX_KEY_APOSTROPHE = 39 , MLX_KEY_COMMA = 44 , MLX_KEY_MINUS = 45 ,
  MLX_KEY_PERIOD = 46 , MLX_KEY_SLASH = 47 , MLX_KEY_0 = 48 , MLX_KEY_1 = 49 ,
  MLX_KEY_2 = 50 , MLX_KEY_3 = 51 , MLX_KEY_4 = 52 , MLX_KEY_5 = 53 ,
  MLX_KEY_6 = 54 , MLX_KEY_7 = 55 , MLX_KEY_8 = 56 , MLX_KEY_9 = 57 ,
  MLX_KEY_SEMICOLON = 59 , MLX_KEY_EQUAL = 61 , MLX_KEY_A = 65 , MLX_KEY_B = 66 ,
  MLX_KEY_C = 67 , MLX_KEY_D = 68 , MLX_KEY_E = 69 , MLX_KEY_F = 70 ,
  MLX_KEY_G = 71 , MLX_KEY_H = 72 , MLX_KEY_I = 73 , MLX_KEY_J = 74 ,
  MLX_KEY_K = 75 , MLX_KEY_L = 76 , MLX_KEY_M = 77 , MLX_KEY_N = 78 ,
  MLX_KEY_O = 79 , MLX_KEY_P = 80 , MLX_KEY_Q = 81 , MLX_KEY_R = 82 ,
  MLX_KEY_S = 83 , MLX_KEY_T = 84 , MLX_KEY_U = 85 , MLX_KEY_V = 86 ,
  MLX_KEY_W = 87 , MLX_KEY_X = 88 , MLX_KEY_Y = 89 , MLX_KEY_Z = 90 ,
  MLX_KEY_LEFT_BRACKET = 91 , MLX_KEY_BACKSLASH = 92 , MLX_KEY_RIGHT_BRACKET = 93 , MLX_KEY_GRAVE_ACCENT = 96 ,
  MLX_KEY_ESCAPE = 256 , MLX_KEY_ENTER = 257 , MLX_KEY_TAB = 258 , MLX_KEY_BACKSPACE = 259 ,
  MLX_KEY_INSERT = 260 , MLX_KEY_DELETE = 261 , MLX_KEY_RIGHT = 262 , MLX_KEY_LEFT = 263 ,
  MLX_KEY_DOWN = 264 , MLX_KEY_UP = 265 , MLX_KEY_PAGE_UP = 266 , MLX_KEY_PAGE_DOWN = 267 ,
  MLX_KEY_HOME = 268 , MLX_KEY_END = 269 , MLX_KEY_CAPS_LOCK = 280 , MLX_KEY_SCROLL_LOCK = 281 ,
  MLX_KEY_NUM_LOCK = 282 , MLX_KEY_PRINT_SCREEN = 283 , MLX_KEY_PAUSE = 284 , MLX_KEY_F1 = 290 ,
  MLX_KEY_F2 = 291 , MLX_KEY_F3 = 292 , MLX_KEY_F4 = 293 , MLX_KEY_F5 = 294 ,
  MLX_KEY_F6 = 295 , MLX_KEY_F7 = 296 , MLX_KEY_F8 = 297 , MLX_KEY_F9 = 298 ,
  MLX_KEY_F10 = 299 , MLX_KEY_F11 = 300 , MLX_KEY_F12 = 301 , MLX_KEY_F13 = 302 ,
  MLX_KEY_F14 = 303 , MLX_KEY_F15 = 304 , MLX_KEY_F16 = 305 , MLX_KEY_F17 = 306 ,
  MLX_KEY_F18 = 307 , MLX_KEY_F19 = 308 , MLX_KEY_F20 = 309 , MLX_KEY_F21 = 310 ,
  MLX_KEY_F22 = 311 , MLX_KEY_F23 = 312 , MLX_KEY_F24 = 313 , MLX_KEY_F25 = 314 ,
  MLX_KEY_KP_0 = 320 , MLX_KEY_KP_1 = 321 , MLX_KEY_KP_2 = 322 , MLX_KEY_KP_3 = 323 ,
  MLX_KEY_KP_4 = 324 , MLX_KEY_KP_5 = 325 , MLX_KEY_KP_6 = 326 , MLX_KEY_KP_7 = 327 ,
  MLX_KEY_KP_8 = 328 , MLX_KEY_KP_9 = 329 , MLX_KEY_KP_DECIMAL = 330 , MLX_KEY_KP_DIVIDE = 331 ,
  MLX_KEY_KP_MULTIPLY = 332 , MLX_KEY_KP_SUBTRACT = 333 , MLX_KEY_KP_ADD = 334 , MLX_KEY_KP_ENTER = 335 ,
  MLX_KEY_KP_EQUAL = 336 , MLX_KEY_LEFT_SHIFT = 340 , MLX_KEY_LEFT_CONTROL = 341 , MLX_KEY_LEFT_ALT = 342 ,
  MLX_KEY_LEFT_SUPER = 343 , MLX_KEY_RIGHT_SHIFT = 344 , MLX_KEY_RIGHT_CONTROL = 345 , MLX_KEY_RIGHT_ALT = 346 ,
  MLX_KEY_RIGHT_SUPER = 347 , MLX_KEY_MENU = 348
}
 
enum  mlx_errno {
  MLX_SUCCESS = 0 , MLX_INVEXT , MLX_INVFILE , MLX_INVPNG ,
  MLX_INVXPM , MLX_INVPOS , MLX_INVDIM , MLX_INVIMG ,
  MLX_VERTFAIL , MLX_FRAGFAIL , MLX_SHDRFAIL , MLX_MEMFAIL ,
  MLX_GLADFAIL , MLX_GLFWFAIL , MLX_WINFAIL , MLX_STRTOOBIG ,
  MLX_ERRMAX
}
 
enum  mlx_settings {
  MLX_STRETCH_IMAGE = 0 , MLX_FULLSCREEN , MLX_MAXIMIZED , MLX_DECORATED ,
  MLX_HEADLESS , MLX_SETTINGS_MAX
}
 

Functions

const charmlx_strerror (mlx_errno_t val)
 
mlx_tmlx_init (int32_t width, int32_t height, const char *title, bool resize)
 
void mlx_set_setting (mlx_settings_t setting, int32_t value)
 
void mlx_close_window (mlx_t *mlx)
 
void mlx_loop (mlx_t *mlx)
 
void mlx_set_icon (mlx_t *mlx, mlx_texture_t *image)
 
void mlx_terminate (mlx_t *mlx)
 
double mlx_get_time (void)
 
void mlx_focus (mlx_t *mlx)
 
void mlx_get_monitor_size (int32_t index, int32_t *width, int32_t *height)
 
void mlx_set_window_pos (mlx_t *mlx, int32_t xpos, int32_t ypos)
 
void mlx_get_window_pos (mlx_t *mlx, int32_t *xpos, int32_t *ypos)
 
void mlx_set_window_size (mlx_t *mlx, int32_t new_width, int32_t new_height)
 
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_title (mlx_t *mlx, const char *title)
 
bool mlx_is_key_down (mlx_t *mlx, keys_t key)
 
bool mlx_is_mouse_down (mlx_t *mlx, mouse_key_t key)
 
void mlx_get_mouse_pos (mlx_t *mlx, int32_t *x, int32_t *y)
 
void mlx_set_mouse_pos (mlx_t *mlx, int32_t x, int32_t y)
 
void mlx_set_cursor_mode (mlx_t *mlx, mouse_mode_t mode)
 
mlx_win_cursor_tmlx_create_std_cursor (cursor_t type)
 
mlx_win_cursor_tmlx_create_cursor (mlx_texture_t *texture)
 
void mlx_destroy_cursor (mlx_win_cursor_t *cursor)
 
void mlx_set_cursor (mlx_t *mlx, mlx_win_cursor_t *cursor)
 
void mlx_scroll_hook (mlx_t *mlx, mlx_scrollfunc func, void *param)
 
void mlx_mouse_hook (mlx_t *mlx, mlx_mousefunc func, void *param)
 
void mlx_cursor_hook (mlx_t *mlx, mlx_cursorfunc func, void *param)
 
void mlx_key_hook (mlx_t *mlx, mlx_keyfunc func, void *param)
 
void mlx_close_hook (mlx_t *mlx, mlx_closefunc func, void *param)
 
void mlx_resize_hook (mlx_t *mlx, mlx_resizefunc func, void *param)
 
bool mlx_loop_hook (mlx_t *mlx, void(*f)(void *), void *param)
 
mlx_texture_tmlx_load_png (const char *path)
 
xpm_tmlx_load_xpm42 (const char *path)
 
void mlx_delete_texture (mlx_texture_t *texture)
 
void mlx_delete_xpm42 (xpm_t *xpm)
 
mlx_image_tmlx_texture_to_image (mlx_t *mlx, mlx_texture_t *texture)
 
void mlx_put_pixel (mlx_image_t *image, uint32_t x, uint32_t y, uint32_t color)
 
mlx_image_tmlx_new_image (mlx_t *mlx, uint32_t width, uint32_t height)
 
int32_t mlx_image_to_window (mlx_t *mlx, mlx_image_t *img, int32_t x, int32_t y)
 
void mlx_delete_image (mlx_t *mlx, mlx_image_t *image)
 
bool mlx_resize_image (mlx_image_t *img, uint32_t nwidth, uint32_t nheight)
 
void mlx_set_instance_depth (mlx_instance_t *instance, int32_t zdepth)
 
mlx_image_tmlx_put_string (mlx_t *mlx, const char *str, int32_t x, int32_t y)
 
const mlx_texture_tmlx_get_font (void)
 
int32_t mlx_get_texoffset (char c)
 

Variables

mlx_errno_t mlx_errno
 

Typedef Documentation

◆ action_t

MLX42 is a cross-platform low level and simple graphics library written in C and uses OpenGL and GLFW for it's underlying windowing and rendering system.

It's a much more up-to-date alternative to the miniLibX which has been extensively proven to be fragile, unmaintained, deprecated and just plain painfully bad to work with. Also its code quality is dubious.

Some structs contain potential void* which are to be ignored as they simply represent points of abstraction to the hidden internal header. This abstraction is crucial as the whole point of this lib so to hide all the bells and whistles in the "engine". Most user's have no need for the inner workings eitherway (shaders, vertex buffer, ...).
The input key codes are copied straight from GLFW. Any new entries should have the exact same values as defined in the glfw3.h. A key action such as pressing or releasing a key.

Parameters
RELEASEExecute when the key is being released.
PRESSExecute when the key is being pressed.
REPEATExecute when the key is being held down.

◆ cursor_t

Various cursors that are standard.

Parameters
ARROWThe regular arrow cursor.
IBEAMThe text input I-beam cursor shape.
CROSSHAIRThe crosshair shape cursor.
HANDThe hand shape cursor.
HRESIZEThe horizontal resize arrow shape.
VRESIZEThe vertical resize arrow shape.

◆ keys_t

All sorts of keyboard keycodes.

KP = Keypad.

◆ mlx_closefunc

typedef void(* mlx_closefunc) (void *param)

Callback function used to handle window closing which is called when the user attempts to close the window, for example by clicking the close widget in the title bar.

Parameters
[in]paramAdditional parameter to pass on to the function.

Definition at line 462 of file MLX42.h.

◆ mlx_cursorfunc

typedef void(* mlx_cursorfunc) (double xpos, double ypos, void *param)

Callback function used to handle raw mouse movement.

Parameters
[in]xposThe mouse x position.
[in]yposThe mouse y position.
[in]paramAdditional parameter to pass on to the function.

Definition at line 433 of file MLX42.h.

◆ mlx_errno_t

◆ mlx_image_t

An image with an individual buffer that can be rendered. Any value can be modified except the width/height and context.

Parameters
widthThe width of the image.
heightThe height of the image.
pixelsThe literal pixel data.
instancesAn instance carrying the X, Y and Z location data.
countThe element count of the instances array.
enabledIf true the image is drawn onto the screen, else it's not.
contextAbstracted OpenGL data.

◆ mlx_instance_t

An image instance can be summarized as just a simple x, y & z coordinate.

Coordinates start from the top left of the screen at 0,0 and increase towards the bottom right.

NOTE: To change the z value, use mlx_set_instance_depth!

Parameters
xThe x location.
yThe y location.
zThe z depth, controls if the image is on the fore or background.
enabledIf true, the instance is drawn, else it's not.

◆ mlx_key_data_t

Key function callback data. Data related to the mlx_key_hook function

Parameters
keyThe key that was pressed.
actionThe action that was done with the key.
os_keyThe os_key is unique for every key, and will have a different value/keycode depending on the platform. They may be consistent on different platforms.
modifierThe modifier key that was pressed, 0 if no key was pressed.

◆ mlx_keyfunc

Callback function used to handle key presses.

Parameters
[in]keydataThe callback data, contains info on key, action, ...
[in]paramAdditional parameter to pass on to the function.

Definition at line 441 of file MLX42.h.

◆ mlx_mousefunc

Callback function used to handle mouse actions.

Parameters
[in]buttonThe mouse button/key pressed.
[in]actionThe mouse action that took place.
[in]modsThe modifier keys pressed together with the mouse key.
[in]paramAdditional parameter to pass on to the function.

Definition at line 424 of file MLX42.h.

◆ mlx_resizefunc

typedef void(* mlx_resizefunc) (int32_t width, int32_t height, void *param)

Callback function used to handle window resizing.

WARNING: The function is called every frame during which the window is being resized, be aware!

Parameters
[in]widthThe new width of the window.
[in]heightThe new height of the window.
[in]paramAdditional parameter to pass on to the function.

Definition at line 453 of file MLX42.h.

◆ mlx_scrollfunc

typedef void(* mlx_scrollfunc) (double xdelta, double ydelta, void *param)

Callback function used to handle scrolling.

Parameters
[in]xdeltaThe mouse x delta.
[in]ydeltaThe mouse y delta.
[in]paramAdditional parameter to pass on to the function.

Definition at line 414 of file MLX42.h.

◆ mlx_settings_t

◆ mlx_t

Main MLX handle, carries important data in regards to the program.

Parameters
windowThe window itself.
contextAbstracted opengl data.
widthThe width of the window.
heightThe height of the window.
delta_timeThe time difference between the previous frame and the current frame.

◆ mlx_texture_t

Base object for disk loaded textures. It contains rudementary information about the texture.

Parameters
widthThe width of the texture.
heightThe height of the texture.
pixelsThe literal pixel data.
bytes_per_pixelThe amount of bytes in a pixel, always 4.

◆ mlx_win_cursor_t

Typedef for a window cursor object, these eventually expand to the native cursor object, but are hidden from the user.

Under GLFW they are named GLFWcursor and have a wrapper for each implementation. You can find the ACTUAL cursor in the following files at GLFW named under *_platform.h

Definition at line 471 of file MLX42.h.

◆ modifier_key_t

Key modifiers, such as shift, control or alt. These keys are flags meaning you can combine them to detect key combinations such as CTRL + ALT so CTRL | ALT.

Parameters
SHIFTThe shift key.
CONTROLThe control key.
ALTThe alt key.
SUPERKEYThe Superkey such as the Windows Key or Command.
CAPSLOCKThe capslock key.
NUMLOCKThe numlock key.

◆ mouse_key_t

The mouse button keycodes.

Parameters
LEFTThe left mouse button.
RIGHTThe right mouse button.
MIDDLEThe middle mouse button, aka the Scrollwheel.

◆ mouse_mode_t

Various mouse/cursor states.

Parameters
NORMALSimple visible default cursor.
HIDDENThe cursor is not rendered but still functions.
DISABLEDThe cursor is not rendered, nor is it functional.

◆ xpm_t

Struct containing data regarding an XPM image.

Parameters
textureThe texture data of the XPM.
color_countThe amount of colors available.
cppThe amount of characters per pixel.
modeThe color mode, either (c)olor or (m)onochrome.

Enumeration Type Documentation

◆ action

MLX42 is a cross-platform low level and simple graphics library written in C and uses OpenGL and GLFW for it's underlying windowing and rendering system.

It's a much more up-to-date alternative to the miniLibX which has been extensively proven to be fragile, unmaintained, deprecated and just plain painfully bad to work with. Also its code quality is dubious.

Some structs contain potential void* which are to be ignored as they simply represent points of abstraction to the hidden internal header. This abstraction is crucial as the whole point of this lib so to hide all the bells and whistles in the "engine". Most user's have no need for the inner workings eitherway (shaders, vertex buffer, ...).
The input key codes are copied straight from GLFW. Any new entries should have the exact same values as defined in the glfw3.h. A key action such as pressing or releasing a key.

Parameters
RELEASEExecute when the key is being released.
PRESSExecute when the key is being pressed.
REPEATExecute when the key is being held down.
Enumerator
MLX_RELEASE 
MLX_PRESS 
MLX_REPEAT 

Definition at line 53 of file MLX42.h.

54{
55 MLX_RELEASE = 0,
56 MLX_PRESS = 1,
57 MLX_REPEAT = 2,
58} action_t;
@ MLX_REPEAT
Definition MLX42.h:57
@ MLX_RELEASE
Definition MLX42.h:55
@ MLX_PRESS
Definition MLX42.h:56
enum action action_t

◆ cursor

Various cursors that are standard.

Parameters
ARROWThe regular arrow cursor.
IBEAMThe text input I-beam cursor shape.
CROSSHAIRThe crosshair shape cursor.
HANDThe hand shape cursor.
HRESIZEThe horizontal resize arrow shape.
VRESIZEThe vertical resize arrow shape.
Enumerator
MLX_CURSOR_ARROW 
MLX_CURSOR_IBEAM 
MLX_CURSOR_CROSSHAIR 
MLX_CURSOR_HAND 
MLX_CURSOR_HRESIZE 
MLX_CURSOR_VRESIZE 

Definition at line 117 of file MLX42.h.

118{
119 MLX_CURSOR_ARROW = 0x00036001,
120 MLX_CURSOR_IBEAM = 0x00036002,
121 MLX_CURSOR_CROSSHAIR = 0x00036003,
122 MLX_CURSOR_HAND = 0x00036004,
123 MLX_CURSOR_HRESIZE = 0x00036005,
124 MLX_CURSOR_VRESIZE = 0x00036006,
125} cursor_t;
enum cursor cursor_t
@ MLX_CURSOR_ARROW
Definition MLX42.h:119
@ MLX_CURSOR_HAND
Definition MLX42.h:122
@ MLX_CURSOR_CROSSHAIR
Definition MLX42.h:121
@ MLX_CURSOR_VRESIZE
Definition MLX42.h:124
@ MLX_CURSOR_HRESIZE
Definition MLX42.h:123
@ MLX_CURSOR_IBEAM
Definition MLX42.h:120

◆ keys

All sorts of keyboard keycodes.

KP = Keypad.

Enumerator
MLX_KEY_SPACE 
MLX_KEY_APOSTROPHE 
MLX_KEY_COMMA 
MLX_KEY_MINUS 
MLX_KEY_PERIOD 
MLX_KEY_SLASH 
MLX_KEY_0 
MLX_KEY_1 
MLX_KEY_2 
MLX_KEY_3 
MLX_KEY_4 
MLX_KEY_5 
MLX_KEY_6 
MLX_KEY_7 
MLX_KEY_8 
MLX_KEY_9 
MLX_KEY_SEMICOLON 
MLX_KEY_EQUAL 
MLX_KEY_A 
MLX_KEY_B 
MLX_KEY_C 
MLX_KEY_D 
MLX_KEY_E 
MLX_KEY_F 
MLX_KEY_G 
MLX_KEY_H 
MLX_KEY_I 
MLX_KEY_J 
MLX_KEY_K 
MLX_KEY_L 
MLX_KEY_M 
MLX_KEY_N 
MLX_KEY_O 
MLX_KEY_P 
MLX_KEY_Q 
MLX_KEY_R 
MLX_KEY_S 
MLX_KEY_T 
MLX_KEY_U 
MLX_KEY_V 
MLX_KEY_W 
MLX_KEY_X 
MLX_KEY_Y 
MLX_KEY_Z 
MLX_KEY_LEFT_BRACKET 
MLX_KEY_BACKSLASH 
MLX_KEY_RIGHT_BRACKET 
MLX_KEY_GRAVE_ACCENT 
MLX_KEY_ESCAPE 
MLX_KEY_ENTER 
MLX_KEY_TAB 
MLX_KEY_BACKSPACE 
MLX_KEY_INSERT 
MLX_KEY_DELETE 
MLX_KEY_RIGHT 
MLX_KEY_LEFT 
MLX_KEY_DOWN 
MLX_KEY_UP 
MLX_KEY_PAGE_UP 
MLX_KEY_PAGE_DOWN 
MLX_KEY_HOME 
MLX_KEY_END 
MLX_KEY_CAPS_LOCK 
MLX_KEY_SCROLL_LOCK 
MLX_KEY_NUM_LOCK 
MLX_KEY_PRINT_SCREEN 
MLX_KEY_PAUSE 
MLX_KEY_F1 
MLX_KEY_F2 
MLX_KEY_F3 
MLX_KEY_F4 
MLX_KEY_F5 
MLX_KEY_F6 
MLX_KEY_F7 
MLX_KEY_F8 
MLX_KEY_F9 
MLX_KEY_F10 
MLX_KEY_F11 
MLX_KEY_F12 
MLX_KEY_F13 
MLX_KEY_F14 
MLX_KEY_F15 
MLX_KEY_F16 
MLX_KEY_F17 
MLX_KEY_F18 
MLX_KEY_F19 
MLX_KEY_F20 
MLX_KEY_F21 
MLX_KEY_F22 
MLX_KEY_F23 
MLX_KEY_F24 
MLX_KEY_F25 
MLX_KEY_KP_0 
MLX_KEY_KP_1 
MLX_KEY_KP_2 
MLX_KEY_KP_3 
MLX_KEY_KP_4 
MLX_KEY_KP_5 
MLX_KEY_KP_6 
MLX_KEY_KP_7 
MLX_KEY_KP_8 
MLX_KEY_KP_9 
MLX_KEY_KP_DECIMAL 
MLX_KEY_KP_DIVIDE 
MLX_KEY_KP_MULTIPLY 
MLX_KEY_KP_SUBTRACT 
MLX_KEY_KP_ADD 
MLX_KEY_KP_ENTER 
MLX_KEY_KP_EQUAL 
MLX_KEY_LEFT_SHIFT 
MLX_KEY_LEFT_CONTROL 
MLX_KEY_LEFT_ALT 
MLX_KEY_LEFT_SUPER 
MLX_KEY_RIGHT_SHIFT 
MLX_KEY_RIGHT_CONTROL 
MLX_KEY_RIGHT_ALT 
MLX_KEY_RIGHT_SUPER 
MLX_KEY_MENU 

Definition at line 132 of file MLX42.h.

133{
134 MLX_KEY_SPACE = 32,
136 MLX_KEY_COMMA = 44,
137 MLX_KEY_MINUS = 45,
138 MLX_KEY_PERIOD = 46,
139 MLX_KEY_SLASH = 47,
140 MLX_KEY_0 = 48,
141 MLX_KEY_1 = 49,
142 MLX_KEY_2 = 50,
143 MLX_KEY_3 = 51,
144 MLX_KEY_4 = 52,
145 MLX_KEY_5 = 53,
146 MLX_KEY_6 = 54,
147 MLX_KEY_7 = 55,
148 MLX_KEY_8 = 56,
149 MLX_KEY_9 = 57,
151 MLX_KEY_EQUAL = 61,
152 MLX_KEY_A = 65,
153 MLX_KEY_B = 66,
154 MLX_KEY_C = 67,
155 MLX_KEY_D = 68,
156 MLX_KEY_E = 69,
157 MLX_KEY_F = 70,
158 MLX_KEY_G = 71,
159 MLX_KEY_H = 72,
160 MLX_KEY_I = 73,
161 MLX_KEY_J = 74,
162 MLX_KEY_K = 75,
163 MLX_KEY_L = 76,
164 MLX_KEY_M = 77,
165 MLX_KEY_N = 78,
166 MLX_KEY_O = 79,
167 MLX_KEY_P = 80,
168 MLX_KEY_Q = 81,
169 MLX_KEY_R = 82,
170 MLX_KEY_S = 83,
171 MLX_KEY_T = 84,
172 MLX_KEY_U = 85,
173 MLX_KEY_V = 86,
174 MLX_KEY_W = 87,
175 MLX_KEY_X = 88,
176 MLX_KEY_Y = 89,
177 MLX_KEY_Z = 90,
182 MLX_KEY_ESCAPE = 256,
183 MLX_KEY_ENTER = 257,
184 MLX_KEY_TAB = 258,
185 MLX_KEY_BACKSPACE = 259,
186 MLX_KEY_INSERT = 260,
187 MLX_KEY_DELETE = 261,
188 MLX_KEY_RIGHT = 262,
189 MLX_KEY_LEFT = 263,
190 MLX_KEY_DOWN = 264,
191 MLX_KEY_UP = 265,
192 MLX_KEY_PAGE_UP = 266,
193 MLX_KEY_PAGE_DOWN = 267,
194 MLX_KEY_HOME = 268,
195 MLX_KEY_END = 269,
196 MLX_KEY_CAPS_LOCK = 280,
198 MLX_KEY_NUM_LOCK = 282,
200 MLX_KEY_PAUSE = 284,
201 MLX_KEY_F1 = 290,
202 MLX_KEY_F2 = 291,
203 MLX_KEY_F3 = 292,
204 MLX_KEY_F4 = 293,
205 MLX_KEY_F5 = 294,
206 MLX_KEY_F6 = 295,
207 MLX_KEY_F7 = 296,
208 MLX_KEY_F8 = 297,
209 MLX_KEY_F9 = 298,
210 MLX_KEY_F10 = 299,
211 MLX_KEY_F11 = 300,
212 MLX_KEY_F12 = 301,
213 MLX_KEY_F13 = 302,
214 MLX_KEY_F14 = 303,
215 MLX_KEY_F15 = 304,
216 MLX_KEY_F16 = 305,
217 MLX_KEY_F17 = 306,
218 MLX_KEY_F18 = 307,
219 MLX_KEY_F19 = 308,
220 MLX_KEY_F20 = 309,
221 MLX_KEY_F21 = 310,
222 MLX_KEY_F22 = 311,
223 MLX_KEY_F23 = 312,
224 MLX_KEY_F24 = 313,
225 MLX_KEY_F25 = 314,
226 MLX_KEY_KP_0 = 320,
227 MLX_KEY_KP_1 = 321,
228 MLX_KEY_KP_2 = 322,
229 MLX_KEY_KP_3 = 323,
230 MLX_KEY_KP_4 = 324,
231 MLX_KEY_KP_5 = 325,
232 MLX_KEY_KP_6 = 326,
233 MLX_KEY_KP_7 = 327,
234 MLX_KEY_KP_8 = 328,
235 MLX_KEY_KP_9 = 329,
236 MLX_KEY_KP_DECIMAL = 330,
237 MLX_KEY_KP_DIVIDE = 331,
240 MLX_KEY_KP_ADD = 334,
241 MLX_KEY_KP_ENTER = 335,
242 MLX_KEY_KP_EQUAL = 336,
243 MLX_KEY_LEFT_SHIFT = 340,
245 MLX_KEY_LEFT_ALT = 342,
246 MLX_KEY_LEFT_SUPER = 343,
249 MLX_KEY_RIGHT_ALT = 346,
251 MLX_KEY_MENU = 348,
252} keys_t;
@ MLX_KEY_KP_DIVIDE
Definition MLX42.h:237
@ MLX_KEY_MENU
Definition MLX42.h:251
@ MLX_KEY_RIGHT_SUPER
Definition MLX42.h:250
@ MLX_KEY_F14
Definition MLX42.h:214
@ MLX_KEY_F19
Definition MLX42.h:219
@ MLX_KEY_PRINT_SCREEN
Definition MLX42.h:199
@ MLX_KEY_3
Definition MLX42.h:143
@ MLX_KEY_KP_8
Definition MLX42.h:234
@ MLX_KEY_7
Definition MLX42.h:147
@ MLX_KEY_KP_5
Definition MLX42.h:231
@ MLX_KEY_END
Definition MLX42.h:195
@ MLX_KEY_1
Definition MLX42.h:141
@ MLX_KEY_F3
Definition MLX42.h:203
@ MLX_KEY_KP_ADD
Definition MLX42.h:240
@ MLX_KEY_BACKSLASH
Definition MLX42.h:179
@ MLX_KEY_LEFT_CONTROL
Definition MLX42.h:244
@ MLX_KEY_F25
Definition MLX42.h:225
@ MLX_KEY_ENTER
Definition MLX42.h:183
@ MLX_KEY_F23
Definition MLX42.h:223
@ MLX_KEY_E
Definition MLX42.h:156
@ MLX_KEY_PAUSE
Definition MLX42.h:200
@ MLX_KEY_NUM_LOCK
Definition MLX42.h:198
@ MLX_KEY_RIGHT_BRACKET
Definition MLX42.h:180
@ MLX_KEY_RIGHT_CONTROL
Definition MLX42.h:248
@ MLX_KEY_SLASH
Definition MLX42.h:139
@ MLX_KEY_KP_0
Definition MLX42.h:226
@ MLX_KEY_S
Definition MLX42.h:170
@ MLX_KEY_GRAVE_ACCENT
Definition MLX42.h:181
@ MLX_KEY_F7
Definition MLX42.h:207
@ MLX_KEY_UP
Definition MLX42.h:191
@ MLX_KEY_INSERT
Definition MLX42.h:186
@ MLX_KEY_DOWN
Definition MLX42.h:190
@ MLX_KEY_F21
Definition MLX42.h:221
@ MLX_KEY_4
Definition MLX42.h:144
@ MLX_KEY_F20
Definition MLX42.h:220
@ MLX_KEY_KP_9
Definition MLX42.h:235
@ MLX_KEY_F4
Definition MLX42.h:204
@ MLX_KEY_L
Definition MLX42.h:163
@ MLX_KEY_KP_MULTIPLY
Definition MLX42.h:238
@ MLX_KEY_F9
Definition MLX42.h:209
@ MLX_KEY_6
Definition MLX42.h:146
@ MLX_KEY_LEFT_BRACKET
Definition MLX42.h:178
@ MLX_KEY_W
Definition MLX42.h:174
@ MLX_KEY_KP_EQUAL
Definition MLX42.h:242
@ MLX_KEY_F22
Definition MLX42.h:222
@ MLX_KEY_RIGHT_SHIFT
Definition MLX42.h:247
@ MLX_KEY_F12
Definition MLX42.h:212
@ MLX_KEY_Q
Definition MLX42.h:168
@ MLX_KEY_M
Definition MLX42.h:164
@ MLX_KEY_PAGE_UP
Definition MLX42.h:192
@ MLX_KEY_SEMICOLON
Definition MLX42.h:150
@ MLX_KEY_KP_3
Definition MLX42.h:229
@ MLX_KEY_5
Definition MLX42.h:145
@ MLX_KEY_PAGE_DOWN
Definition MLX42.h:193
@ MLX_KEY_F6
Definition MLX42.h:206
@ MLX_KEY_X
Definition MLX42.h:175
@ MLX_KEY_0
Definition MLX42.h:140
@ MLX_KEY_RIGHT
Definition MLX42.h:188
@ MLX_KEY_Y
Definition MLX42.h:176
@ MLX_KEY_8
Definition MLX42.h:148
@ MLX_KEY_I
Definition MLX42.h:160
@ MLX_KEY_Z
Definition MLX42.h:177
@ MLX_KEY_F1
Definition MLX42.h:201
@ MLX_KEY_B
Definition MLX42.h:153
@ MLX_KEY_DELETE
Definition MLX42.h:187
@ MLX_KEY_F
Definition MLX42.h:157
@ MLX_KEY_KP_SUBTRACT
Definition MLX42.h:239
@ MLX_KEY_D
Definition MLX42.h:155
@ MLX_KEY_LEFT_ALT
Definition MLX42.h:245
@ MLX_KEY_LEFT_SUPER
Definition MLX42.h:246
@ MLX_KEY_2
Definition MLX42.h:142
@ MLX_KEY_CAPS_LOCK
Definition MLX42.h:196
@ MLX_KEY_F8
Definition MLX42.h:208
@ MLX_KEY_RIGHT_ALT
Definition MLX42.h:249
@ MLX_KEY_SCROLL_LOCK
Definition MLX42.h:197
@ MLX_KEY_F13
Definition MLX42.h:213
@ MLX_KEY_F5
Definition MLX42.h:205
@ MLX_KEY_A
Definition MLX42.h:152
@ MLX_KEY_O
Definition MLX42.h:166
@ MLX_KEY_F11
Definition MLX42.h:211
@ MLX_KEY_9
Definition MLX42.h:149
@ MLX_KEY_V
Definition MLX42.h:173
@ MLX_KEY_HOME
Definition MLX42.h:194
@ MLX_KEY_KP_1
Definition MLX42.h:227
@ MLX_KEY_TAB
Definition MLX42.h:184
@ MLX_KEY_F24
Definition MLX42.h:224
@ MLX_KEY_SPACE
Definition MLX42.h:134
@ MLX_KEY_KP_2
Definition MLX42.h:228
@ MLX_KEY_LEFT
Definition MLX42.h:189
@ MLX_KEY_F18
Definition MLX42.h:218
@ MLX_KEY_F17
Definition MLX42.h:217
@ MLX_KEY_COMMA
Definition MLX42.h:136
@ MLX_KEY_F15
Definition MLX42.h:215
@ MLX_KEY_K
Definition MLX42.h:162
@ MLX_KEY_G
Definition MLX42.h:158
@ MLX_KEY_PERIOD
Definition MLX42.h:138
@ MLX_KEY_LEFT_SHIFT
Definition MLX42.h:243
@ MLX_KEY_KP_DECIMAL
Definition MLX42.h:236
@ MLX_KEY_J
Definition MLX42.h:161
@ MLX_KEY_KP_6
Definition MLX42.h:232
@ MLX_KEY_R
Definition MLX42.h:169
@ MLX_KEY_KP_4
Definition MLX42.h:230
@ MLX_KEY_U
Definition MLX42.h:172
@ MLX_KEY_KP_ENTER
Definition MLX42.h:241
@ MLX_KEY_ESCAPE
Definition MLX42.h:182
@ MLX_KEY_F16
Definition MLX42.h:216
@ MLX_KEY_EQUAL
Definition MLX42.h:151
@ MLX_KEY_H
Definition MLX42.h:159
@ MLX_KEY_C
Definition MLX42.h:154
@ MLX_KEY_F10
Definition MLX42.h:210
@ MLX_KEY_T
Definition MLX42.h:171
@ MLX_KEY_MINUS
Definition MLX42.h:137
@ MLX_KEY_BACKSPACE
Definition MLX42.h:185
@ MLX_KEY_P
Definition MLX42.h:167
@ MLX_KEY_APOSTROPHE
Definition MLX42.h:135
@ MLX_KEY_F2
Definition MLX42.h:202
@ MLX_KEY_KP_7
Definition MLX42.h:233
@ MLX_KEY_N
Definition MLX42.h:165
enum keys keys_t

◆ mlx_errno

Enumerator
MLX_SUCCESS 
MLX_INVEXT 
MLX_INVFILE 
MLX_INVPNG 
MLX_INVXPM 
MLX_INVPOS 
MLX_INVDIM 
MLX_INVIMG 
MLX_VERTFAIL 
MLX_FRAGFAIL 
MLX_SHDRFAIL 
MLX_MEMFAIL 
MLX_GLADFAIL 
MLX_GLFWFAIL 
MLX_WINFAIL 
MLX_STRTOOBIG 
MLX_ERRMAX 

Definition at line 370 of file MLX42.h.

371{
372 MLX_SUCCESS = 0, // No Errors
373 MLX_INVEXT, // File has an invalid extension
374 MLX_INVFILE, // File was invalid / does not exist.
375 MLX_INVPNG, // Something is wrong with the given PNG file.
376 MLX_INVXPM, // Something is wrong with the given XPM file.
377 MLX_INVPOS, // The specified X/Y positions are out of bounds.
378 MLX_INVDIM, // The specified W/H dimensions are out of bounds.
379 MLX_INVIMG, // The provided image is invalid, might indicate mismanagement of images.
380 MLX_VERTFAIL, // Failed to compile the vertex shader.
381 MLX_FRAGFAIL, // Failed to compile the fragment shader.
382 MLX_SHDRFAIL, // Failed to compile the shaders.
383 MLX_MEMFAIL, // Dynamic memory allocation has failed.
384 MLX_GLADFAIL, // OpenGL loader has failed.
385 MLX_GLFWFAIL, // GLFW failed to initialize.
386 MLX_WINFAIL, // Failed to create a window.
387 MLX_STRTOOBIG, // The string is too big to be drawn.
388 MLX_ERRMAX, // Error count
enum mlx_errno mlx_errno_t
@ MLX_INVIMG
Definition MLX42.h:379
@ MLX_MEMFAIL
Definition MLX42.h:383
@ MLX_STRTOOBIG
Definition MLX42.h:387
@ MLX_INVEXT
Definition MLX42.h:373
@ MLX_INVFILE
Definition MLX42.h:374
@ MLX_FRAGFAIL
Definition MLX42.h:381
@ MLX_INVXPM
Definition MLX42.h:376
@ MLX_SHDRFAIL
Definition MLX42.h:382
@ MLX_VERTFAIL
Definition MLX42.h:380
@ MLX_GLADFAIL
Definition MLX42.h:384
@ MLX_INVPOS
Definition MLX42.h:377
@ MLX_WINFAIL
Definition MLX42.h:386
@ MLX_GLFWFAIL
Definition MLX42.h:385
@ MLX_INVPNG
Definition MLX42.h:375
@ MLX_SUCCESS
Definition MLX42.h:372
@ MLX_INVDIM
Definition MLX42.h:378
@ MLX_ERRMAX
Definition MLX42.h:388

◆ mlx_settings

Enumerator
MLX_STRETCH_IMAGE 
MLX_FULLSCREEN 
MLX_MAXIMIZED 
MLX_DECORATED 
MLX_HEADLESS 
MLX_SETTINGS_MAX 

Definition at line 397 of file MLX42.h.

398{
399 MLX_STRETCH_IMAGE = 0, // Should images resize with the window as it's being resized or not. Default: false
400 MLX_FULLSCREEN, // Should the window be in Fullscreen, note it will fullscreen at the given resolution. Default: false
401 MLX_MAXIMIZED, // Start the window in a maximized state, overwrites the fullscreen state if this is true. Default: false
402 MLX_DECORATED, // Have the window be decorated with a window bar. Default: true
403 MLX_HEADLESS, // Run in headless mode, no window is created. (NOTE: Still requires some form of window manager such as xvfb)
404 MLX_SETTINGS_MAX, // Setting count.
enum mlx_settings mlx_settings_t
@ MLX_DECORATED
Definition MLX42.h:402
@ MLX_MAXIMIZED
Definition MLX42.h:401
@ MLX_HEADLESS
Definition MLX42.h:403
@ MLX_FULLSCREEN
Definition MLX42.h:400
@ MLX_SETTINGS_MAX
Definition MLX42.h:404
@ MLX_STRETCH_IMAGE
Definition MLX42.h:399

◆ modifier_key

Key modifiers, such as shift, control or alt. These keys are flags meaning you can combine them to detect key combinations such as CTRL + ALT so CTRL | ALT.

Parameters
SHIFTThe shift key.
CONTROLThe control key.
ALTThe alt key.
SUPERKEYThe Superkey such as the Windows Key or Command.
CAPSLOCKThe capslock key.
NUMLOCKThe numlock key.
Enumerator
MLX_SHIFT 
MLX_CONTROL 
MLX_ALT 
MLX_SUPERKEY 
MLX_CAPSLOCK 
MLX_NUMLOCK 

Definition at line 72 of file MLX42.h.

73{
74 MLX_SHIFT = 0x0001,
75 MLX_CONTROL = 0x0002,
76 MLX_ALT = 0x0004,
77 MLX_SUPERKEY = 0x0008,
78 MLX_CAPSLOCK = 0x0010,
79 MLX_NUMLOCK = 0x0020,
@ MLX_ALT
Definition MLX42.h:76
@ MLX_CAPSLOCK
Definition MLX42.h:78
@ MLX_SUPERKEY
Definition MLX42.h:77
@ MLX_NUMLOCK
Definition MLX42.h:79
@ MLX_CONTROL
Definition MLX42.h:75
@ MLX_SHIFT
Definition MLX42.h:74
enum modifier_key modifier_key_t

◆ mouse_key

The mouse button keycodes.

Parameters
LEFTThe left mouse button.
RIGHTThe right mouse button.
MIDDLEThe middle mouse button, aka the Scrollwheel.
Enumerator
MLX_MOUSE_BUTTON_LEFT 
MLX_MOUSE_BUTTON_RIGHT 
MLX_MOUSE_BUTTON_MIDDLE 

Definition at line 88 of file MLX42.h.

89{
enum mouse_key mouse_key_t
@ MLX_MOUSE_BUTTON_MIDDLE
Definition MLX42.h:92
@ MLX_MOUSE_BUTTON_LEFT
Definition MLX42.h:90
@ MLX_MOUSE_BUTTON_RIGHT
Definition MLX42.h:91

◆ mouse_mode

Various mouse/cursor states.

Parameters
NORMALSimple visible default cursor.
HIDDENThe cursor is not rendered but still functions.
DISABLEDThe cursor is not rendered, nor is it functional.
Enumerator
MLX_MOUSE_NORMAL 
MLX_MOUSE_HIDDEN 
MLX_MOUSE_DISABLED 

Definition at line 101 of file MLX42.h.

102{
103 MLX_MOUSE_NORMAL = 0x00034001,
104 MLX_MOUSE_HIDDEN = 0x00034002,
105 MLX_MOUSE_DISABLED = 0x00034003,
@ MLX_MOUSE_DISABLED
Definition MLX42.h:105
@ MLX_MOUSE_HIDDEN
Definition MLX42.h:104
@ MLX_MOUSE_NORMAL
Definition MLX42.h:103
enum mouse_mode mouse_mode_t

Function Documentation

◆ mlx_close_hook()

void mlx_close_hook ( mlx_t mlx,
mlx_closefunc  func,
void param 
)

This function sets the close callback, which is called in attempt to close the window device such as a close window widget used in the window bar.

Parameters
[in]mlxThe MLX instance handle.
[in]funcThe close callback function.
[in]paramAn additional optional parameter.

Definition at line 63 of file mlx_window.c.

64{
67
69 mlxctx->close_hook.func = func;
70 mlxctx->close_hook.param = param;
72}
#define MLX_NONNULL(var)
Definition MLX42_Int.h:46
GLenum func
Definition glad.h:3336
GLuint GLsizei GLsizei * length
Definition glad.h:3372
GLenum GLfloat param
Definition glad.h:1968
static void mlx_close_callback(GLFWwindow *window)
Definition mlx_window.c:53
Definition MLX42.h:361
void * context
Definition MLX42.h:363
void * window
Definition MLX42.h:362
Here is the call graph for this function:

◆ mlx_close_window()

void mlx_close_window ( mlx_t mlx)

Notifies MLX that it should stop rendering and exit the main loop. This is not the same as terminate, this simply tells MLX to close the window.

Parameters
[in]mlxThe MLX instance handle.

Definition at line 26 of file mlx_exit.c.

Here is the caller graph for this function:

◆ mlx_create_cursor()

mlx_win_cursor_t * mlx_create_cursor ( mlx_texture_t texture)

Allows for the creation of custom cursors with a given texture.

Use mlx_set_cursor to select the specific cursor. Cursors are destroyed at mlx_terminate().

Parameters
[in]textureThe texture to use as cursor.
Returns
The cursor object or null on failure.

Definition at line 27 of file mlx_cursor.c.

28{
30
33 .width = texture->width,
34 .height = texture->height,
35 .pixels = texture->pixels
36 };
37
38 if ((cursor = glfwCreateCursor(&image, 0, 0)))
39 return (cursor);
40 return ((void *)mlx_error(MLX_MEMFAIL));
41}
cursor
Definition MLX42.h:118
bool mlx_error(mlx_errno_t val)
Definition mlx_error.c:43
GLuint texture
Definition glad.h:2899
GLenum GLenum GLsizei void * image
Definition glad.h:5132
Here is the call graph for this function:

◆ mlx_create_std_cursor()

mlx_win_cursor_t * mlx_create_std_cursor ( cursor_t  type)

Retrieves the system standard cursor.

Parameters
[in]typeThe standard cursor type to create.
Returns
The cursor object or null on failure.

Definition at line 17 of file mlx_cursor.c.

18{
19 MLX_ASSERT(type >= MLX_CURSOR_ARROW && type < MLX_CURSOR_VRESIZE, "Invalid standard cursor type");
20
23 return (cursor);
24 return ((void *)mlx_error(MLX_MEMFAIL));
25}
#define MLX_ASSERT(cond, msg)
Definition MLX42_Int.h:45
GLint GLint GLsizei GLint GLenum GLenum type
Definition glad.h:1980
Here is the call graph for this function:

◆ mlx_cursor_hook()

void mlx_cursor_hook ( mlx_t mlx,
mlx_cursorfunc  func,
void param 
)

This function sets the cursor callback, which is called when the mouse position changes. Position is relative to the window.

Parameters
[in]mlxThe MLX instance handle.
[in]funcThe cursor callback function.
[in]paramAn additional optional parameter.

Definition at line 65 of file mlx_mouse.c.

66{
69
70 mlx_ctx_t* const mlxctx = mlx->context;
71 mlxctx->cursor_hook.func = func;
72 mlxctx->cursor_hook.param = param;
74}
static void mlx_cursor_cb(GLFWwindow *window, double xpos, double ypos)
Definition mlx_mouse.c:33
Here is the call graph for this function:

◆ mlx_delete_image()

void mlx_delete_image ( mlx_t mlx,
mlx_image_t image 
)

Deleting an image will remove it from the render queue as well as any and all instances it might have. Additionally, just as extra measures sets all the data to NULL.

If you simply wish to stop rendering an image without de-allocation set the 'enabled' boolean in the image struct.

Parameters
[in]mlxThe MLX instance handle.
[in]imageThe image to delete.

Definition at line 204 of file mlx_images.c.

205{
208
210
211 // Delete all instances in the render queue
213 while ((quelst = mlx_lstremove(&mlxctx->render_queue, image, &mlx_equal_inst)))
214 mlx_freen(2, quelst->content, quelst);
215
217 if ((imglst = mlx_lstremove(&mlxctx->images, image, &mlx_equal_image)))
218 {
219 glDeleteTextures(1, &((mlx_image_ctx_t*)image->context)->texture);
220 mlx_freen(5, image->pixels, image->instances, image->context, imglst, image);
221 }
222}
mlx_list_t * mlx_lstremove(mlx_list_t **lst, void *value, bool(*comp)(void *, void *))
Definition mlx_list.c:100
bool mlx_equal_image(void *lstcontent, void *value)
Definition mlx_compare.c:17
bool mlx_freen(int32_t count,...)
Definition mlx_utils.c:89
bool mlx_equal_inst(void *lstcontent, void *value)
Definition mlx_compare.c:25
#define glDeleteTextures
Definition glad.h:2904
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_delete_texture()

void mlx_delete_texture ( mlx_texture_t texture)

Deletes a texture by freeing its allocated data.

Parameters
[in]textureThe texture to free.

Definition at line 37 of file mlx_texture.c.

38{
40
41 mlx_freen(2, texture->pixels, texture);
42}
Here is the call graph for this function:

◆ mlx_delete_xpm42()

void mlx_delete_xpm42 ( xpm_t xpm)

Deletes an XPM42 texture by freeing its allocated data.

This will not remove any already drawn XPMs, it simply deletes the XPM buffer.

Parameters
[in]xpmThe xpm texture to delete.

Definition at line 203 of file mlx_xpm42.c.

204{
207 free(xpm);
208}
uint8_t * pixels
Definition MLX42.h:268
Definition MLX42.h:280
mlx_texture_t texture
Definition MLX42.h:281

◆ mlx_destroy_cursor()

void mlx_destroy_cursor ( mlx_win_cursor_t cursor)

Destroys the given cursor object.

Parameters
[in]cursorThe cursor object to destroy.

Definition at line 43 of file mlx_cursor.c.

◆ mlx_focus()

void mlx_focus ( mlx_t mlx)

This function brings the specified window to front and sets input focus.

Do not use this function to steal focus from other applications unless you are certain that is what the user wants. Focus stealing can be extremely disruptive.

Parameters
[in]mlxThe MLX instance handle.

Definition at line 126 of file mlx_utils.c.

127{
129
131}

◆ mlx_get_font()

const mlx_texture_t * mlx_get_font ( void  )

Retrieve the texture data for the built-in font.

Returns
Pointer to the built-in font texture.

Definition at line 46 of file mlx_font.c.

47{
48 return ((const mlx_texture_t*)&font_atlas);
49}
static struct s_font font_atlas

◆ mlx_get_monitor_size()

void mlx_get_monitor_size ( int32_t  index,
int32_t width,
int32_t height 
)

Gets the size of the specified monitor.

Parameters
[in]indexNormally 0, in case of multiple windows, can be specified
[in]widthThe width of the window.
[in]heightThe height of the window.

Definition at line 17 of file mlx_monitor.c.

18{
19 MLX_ASSERT(index >= 0, "Index out of bounds");
22
23 *width = 0;
24 *height = 0;
25
29 return;
30
31 const GLFWvidmode* vidmode;
33 {
34 *width = vidmode->width;
35 *height = vidmode->height;
36 }
37}
GLuint index
Definition glad.h:3345
GLint GLsizei GLsizei height
Definition glad.h:1965
GLint GLsizei width
Definition glad.h:1965

◆ mlx_get_mouse_pos()

void mlx_get_mouse_pos ( mlx_t mlx,
int32_t x,
int32_t y 
)

Returns the current, relative, mouse cursor position on the window, starting from the top left corner.

Negative values or values greater than window width or height indicate that it is outside the window.

Parameters
[in]mlxThe MLX instance handle.
[out]xThe position.
[out]yThe position.

Definition at line 90 of file mlx_mouse.c.

91{
95
96 double xd, yd;
98 *x = (int32_t)xd;
99 *y = (int32_t)yd;
100}
GLint y
Definition glad.h:1965
GLdouble x
Definition glad.h:2847

◆ mlx_get_texoffset()

int32_t mlx_get_texoffset ( char  c)

This function lets you retrieve the X offset of the given char in the font texture.

NOTE: A single character is 10 * 20 in pixels!

Parameters
[in]cThe character to get the offset from.
Returns
Non-negative if found or -1 if not found.

Definition at line 51 of file mlx_font.c.

52{
53 const bool _isprint = isprint(c);
54
55 // NOTE: Cheesy branchless operation :D
56 // +2 To skip line separator in texture
57 return (-1 * !_isprint + ((FONT_WIDTH + 2) * (c - 32)) * _isprint);
58}
#define FONT_WIDTH
Definition font.h:15
Here is the caller graph for this function:

◆ mlx_get_time()

double mlx_get_time ( void  )

Gets the elapsed time since MLX was initialized.

Returns
The amount of time elapsed in seconds.

Definition at line 121 of file mlx_utils.c.

122{
123 return (glfwGetTime());
124}

◆ mlx_get_window_pos()

void mlx_get_window_pos ( mlx_t mlx,
int32_t xpos,
int32_t ypos 
)

Gets the window's position.

Parameters
[in]mlxThe MLX instance handle.
[out]xposThe x position.
[out]yposThe y position.

Definition at line 106 of file mlx_window.c.

107{
111
113}

◆ mlx_image_to_window()

int32_t mlx_image_to_window ( mlx_t mlx,
mlx_image_t img,
int32_t  x,
int32_t  y 
)

Draws a new instance of an image, it will then share the same pixel buffer as the image.

NOTE: Keep in mind that the instance array gets reallocated, try to store the return value to the instance! NOT the pointer! It will become invalid!

WARNING: Try to display as few images on the window as possible, drawing too many images will cause a loss in performance!

Parameters
[in]mlxThe MLX instance handle.
[in]imgThe image to draw on the screen.
[in]xThe X position.
[in]yThe Y position.
Returns
Index to the instance, or -1 on failure.

Definition at line 121 of file mlx_images.c.

122{
125
126 // Allocate buffers...
127 img->count++;
128 bool did_realloc;
130 draw_queue_t* queue = calloc(1, sizeof(draw_queue_t));
131 if (!instances || !queue)
132 {
133 if (did_realloc)
134 free(instances);
135 return (free(queue), mlx_error(MLX_MEMFAIL), -1);
136 }
137
138 // Set data...
139 queue->image = img;
140 int32_t index = queue->instanceid = img->count - 1;
141 img->instances = instances;
142 img->instances[index].x = x;
143 img->instances[index].y = y;
144
145 // NOTE: We keep updating the Z for the convenience of the user.
146 // Always update Z depth to prevent overlapping images by default.
147 img->instances[index].z = ((mlx_ctx_t*)mlx->context)->zdepth++;
148 img->instances[index].enabled = true;
149
150 // Add draw call...
151 sort_queue = true;
153 if ((templst = mlx_lstnew(queue)))
154 {
155 mlx_lstadd_front(&((mlx_ctx_t*)mlx->context)->render_queue, templst);
156 return (index);
157 }
158 return (mlx_freen(2, instances, queue), mlx_error(MLX_MEMFAIL), -1);
159}
void mlx_lstadd_front(mlx_list_t **lst, mlx_list_t *new)
Definition mlx_list.c:81
bool sort_queue
Definition mlx_init.c:162
mlx_list_t * mlx_lstnew(void *content)
Definition mlx_list.c:45
GLint void * img
Definition glad.h:3003
mlx_instance_t * mlx_grow_instances(mlx_image_t *img, bool *did_realloc)
Definition mlx_images.c:87
int32_t x
Definition MLX42.h:303
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_init()

mlx_t * mlx_init ( int32_t  width,
int32_t  height,
const char title,
bool  resize 
)

Initializes a new MLX42 Instance.

Parameters
[in]widthThe width of the window.
[in]heightThe height of the window.
[in]titleThe title of the window.
[in]resizeEnable window resizing.
Returns
Ptr to the MLX handle or null on failure.

Definition at line 164 of file mlx_init.c.

165{
167 MLX_ASSERT(width > 0, "Window width must be positive");
168 MLX_ASSERT(height > 0, "Window height must be positive");
169
170 bool init;
171 mlx_t* mlx;
172 if (!(init = glfwInit()))
173 return ((void*)mlx_error(MLX_GLFWFAIL));
174 if (!(mlx = calloc(1, sizeof(mlx_t))))
175 return ((void*)mlx_error(MLX_MEMFAIL));
176 if (!(mlx->context = calloc(1, sizeof(mlx_ctx_t))))
177 return (free(mlx), (void*)mlx_error(MLX_MEMFAIL));
178
179 mlx_ctx_t* const mlxctx = mlx->context;
180 mlx->window = NULL;
181 mlx->width = width;
182 mlx->height = height;
183 mlxctx->initialWidth = width;
184 mlxctx->initialHeight = height;
185
186 // NOTE(W2): For emscripten, this value will be ignored anyway.
188#ifdef EMSCRIPTEN
194#else
200#endif
201#ifdef __APPLE__
203#endif
208 return (mlx_terminate(mlx), NULL);
210 return (mlx);
211}
mlx_settings
Definition MLX42.h:398
void mlx_terminate(mlx_t *mlx)
Definition mlx_exit.c:36
#define GL_TRUE
Definition glad.h:140
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
static bool mlx_create_buffers(mlx_t *mlx)
Definition mlx_init.c:23
static bool mlx_init_render(mlx_t *mlx)
Definition mlx_init.c:101
int32_t width
Definition MLX42.h:364
int32_t height
Definition MLX42.h:365
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_is_key_down()

bool mlx_is_key_down ( mlx_t mlx,
keys_t  key 
)

Returns true or false if the key is down or not.

Parameters
[in]mlxThe MLX instance handle.
[in]keyThe keycode to check, use MLX_KEY_... to specify!
Returns
True or false if the key is down or not.

Definition at line 44 of file mlx_keys.c.

45{
47
48 return (glfwGetKey(mlx->window, key) == GLFW_PRESS);
49}

◆ mlx_is_mouse_down()

bool mlx_is_mouse_down ( mlx_t mlx,
mouse_key_t  key 
)

Checks whether a mouse button is pressed or not.

Parameters
[in]mlxThe MLX instance handle.
[in]keyA specific mouse key. e.g MLX_MOUSE_BUTTON_0
Returns
True or false if the mouse key is down or not.

Definition at line 76 of file mlx_mouse.c.

77{
79
80 return (glfwGetMouseButton(mlx->window, key) == GLFW_PRESS);
81}

◆ mlx_key_hook()

void mlx_key_hook ( mlx_t mlx,
mlx_keyfunc  func,
void param 
)

This function sets the key callback, which is called when a key is pressed on the keyboard. Useful for single keypress detection.

Parameters
[in]mlxThe MLX instance handle.
[in]funcThe keypress callback function.
[in]paramAn additional optional parameter.

Definition at line 33 of file mlx_keys.c.

34{
37
39 mlxctx->key_hook.func = func;
40 mlxctx->key_hook.param = param;
42}
static void mlx_key_callback(GLFWwindow *window, int32_t key, int32_t scancode, int32_t action, int32_t mods)
Definition mlx_keys.c:17
Here is the call graph for this function:

◆ mlx_load_png()

mlx_texture_t * mlx_load_png ( const char path)

Decode/load a PNG file into a buffer.

Parameters
[in]pathPath to the PNG file.
Returns
If successful the texture data is returned, else NULL.

Definition at line 17 of file mlx_png.c.

18{
20
22 if (!(image = malloc(sizeof(mlx_texture_t))))
23 return ((void*)mlx_error(MLX_MEMFAIL));
24
25 uint32_t error;
27 if ((error = lodepng_decode32_file(&image->pixels, &image->width, &image->height, path)))
28 {
29 free(image);
30 // Explicitly print error on purpose
31 fprintf(stderr, "MLX42: LodePNG: %s\n", lodepng_error_text(error));
32 return ((void*)mlx_error(MLX_INVPNG));
33 }
34 return (image);
35}
#define BPP
Definition MLX42_Int.h:42
unsigned lodepng_decode32_file(unsigned char **out, unsigned *w, unsigned *h, const char *filename)
const char * lodepng_error_text(unsigned code)
uint8_t bytes_per_pixel
Definition MLX42.h:267
Here is the call graph for this function:

◆ mlx_load_xpm42()

xpm_t * mlx_load_xpm42 ( const char path)

Loads an XPM42 texture from the given file path.

Parameters
[in]pathThe file path to the XPM texture.
Returns
The XPM texture struct containing its information.

Definition at line 181 of file mlx_xpm42.c.

182{
183 FILE* file;
184 xpm_t* xpm = NULL;
185
187 if (!strstr(path, ".xpm42"))
188 return ((void*)mlx_error(MLX_INVEXT));
189 if (!(file = fopen(path, "r")))
190 return ((void*)mlx_error(MLX_INVFILE));
191 if (!(xpm = calloc(1, sizeof(xpm_t))))
192 return ((void*)mlx_error(MLX_MEMFAIL));
194 {
197 xpm = NULL;
198 }
199 fclose(file);
200 return (xpm);
201}
static bool mlx_read_xpm_header(xpm_t *xpm, FILE *file)
Definition mlx_xpm42.c:156
Here is the call graph for this function:

◆ mlx_loop()

void mlx_loop ( mlx_t mlx)

Initializes the rendering of MLX, this function won't return until mlx_close_window is called, meaning it will loop until the user requests that the window should close.

Parameters
[in]mlxThe MLX instance handle.

In Emscripten the lood is defined differently, there the this function is passed to the while loop instead

Definition at line 97 of file mlx_loop.c.

98{
100
101#ifdef EMSCRIPTEN
102 static double start, oldstart = 0;
103#else
104 double start, oldstart = 0;
106 {
107#endif
108 start = glfwGetTime();
110 oldstart = start;
111
112 glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
115
116 if ((mlx->width > 1 || mlx->height > 1))
118
122
125#ifndef EMSCRIPTEN
126 }
127#endif
128}
void mlx_flush_batch(mlx_ctx_t *mlx)
Definition mlx_images.c:17
void mlx_update_matrix(const mlx_t *mlx)
Definition mlx_window.c:21
#define glClearColor
Definition glad.h:1994
#define GL_COLOR_BUFFER_BIT
Definition glad.h:138
GLuint start
Definition glad.h:2963
#define GL_DEPTH_BUFFER_BIT
Definition glad.h:136
#define glClear
Definition glad.h:1991
static void mlx_render_images(mlx_t *mlx)
Definition mlx_loop.c:30
static void mlx_exec_loop_hooks(mlx_t *mlx)
Definition mlx_loop.c:17
double delta_time
Definition MLX42.h:366
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_loop_hook()

bool mlx_loop_hook ( mlx_t mlx,
void(*)(void *)  f,
void param 
)

Generic loop hook for any custom hooks to add to the main loop. Executes a function per frame, so be careful.

Parameters
[in]mlxThe MLX instance handle.
[in]fThe function.
[in]paramThe parameter to pass on to the function.
Returns
Whether or not the hook was added successfully.

Definition at line 70 of file mlx_loop.c.

71{
74
76 if (!(hook = malloc(sizeof(mlx_hook_t))))
77 return (mlx_error(MLX_MEMFAIL));
78
80 if (!(lst = mlx_lstnew(hook)))
81 {
82 free(hook);
83 return (mlx_error(MLX_MEMFAIL));
84 }
85 hook->func = f;
86 hook->param = param;
87 const mlx_ctx_t *mlxctx = mlx->context;
88 mlx_lstadd_back((mlx_list_t**)(&mlxctx->hooks), lst);
89 return (true);
90}
void mlx_lstadd_back(mlx_list_t **lst, mlx_list_t *new)
Definition mlx_list.c:67
GLdouble f
Definition glad.h:2085
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_mouse_hook()

void mlx_mouse_hook ( mlx_t mlx,
mlx_mousefunc  func,
void param 
)

This function sets the mouse callback, which is called when a mouse does any sort of action such as pressing a key.

Parameters
[in]mlxThe MLX instance handle.
[in]funcThe mouse callback function.
[in]paramAn additional optional parameter.

Definition at line 54 of file mlx_mouse.c.

55{
58
59 mlx_ctx_t* const mlxctx = mlx->context;
60 mlxctx->mouse_hook.func = func;
61 mlxctx->mouse_hook.param = param;
63}
static void mlx_mouse_cb(GLFWwindow *window, int32_t button, int32_t action, int32_t mods)
Definition mlx_mouse.c:25
Here is the call graph for this function:

◆ mlx_new_image()

mlx_image_t * mlx_new_image ( mlx_t mlx,
uint32_t  width,
uint32_t  height 
)

Creates and allocates a new image buffer.

Parameters
[in]mlxThe MLX instance handle.
[in]widthThe desired width of the image.
[in]heightThe desired height of the image.
Returns
Pointer to the image buffer, if it failed to allocate then NULL.

Definition at line 161 of file mlx_images.c.

162{
164
165 if (!width || !height || width > INT16_MAX || height > INT16_MAX)
166 return ((void*)mlx_error(MLX_INVDIM));
167
168 const mlx_ctx_t* mlxctx = mlx->context;
169 mlx_image_t* newimg = calloc(1, sizeof(mlx_image_t));
171 if (!newimg || !newctx)
172 {
174 return ((void *)mlx_error(MLX_MEMFAIL));
175 }
176 newimg->enabled = true;
177 newimg->context = newctx;
178 (*(uint32_t*)&newimg->width) = width;
179 (*(uint32_t*)&newimg->height) = height;
180 if (!(newimg->pixels = calloc(width * height, sizeof(int32_t))))
181 {
183 return ((void *)mlx_error(MLX_MEMFAIL));
184 }
185
187 if (!(newentry = mlx_lstnew(newimg)))
188 {
189 mlx_freen(3, newimg->pixels, newimg->context, newimg);
190 return ((void *)mlx_error(MLX_MEMFAIL));
191 }
192
193 // Generate OpenGL texture
194 glGenTextures(1, &newctx->texture);
201 return (newimg);
202}
#define GL_TEXTURE_MIN_FILTER
Definition glad.h:305
#define GL_TEXTURE_WRAP_S
Definition glad.h:306
#define glTexParameteri
Definition glad.h:1976
#define GL_NEAREST
Definition glad.h:298
#define glGenTextures
Definition glad.h:2907
#define glBindTexture
Definition glad.h:2901
#define GL_TEXTURE_WRAP_T
Definition glad.h:307
#define GL_TEXTURE_MAG_FILTER
Definition glad.h:304
#define GL_TEXTURE_2D
Definition glad.h:243
#define GL_CLAMP_TO_EDGE
Definition glad.h:690
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_put_pixel()

void mlx_put_pixel ( mlx_image_t image,
uint32_t  x,
uint32_t  y,
uint32_t  color 
)

Sets / puts a pixel onto an image.

NOTE: It is considered undefined behaviour when putting a pixel beyond the bounds of an image.

Parameters
[in]imageThe MLX instance handle.
[in]xThe X coordinate position.
[in]yThe Y coordinate position.
[in]colorThe color value to put.

Definition at line 26 of file mlx_put_pixel.c.

27{
29 MLX_ASSERT(x < image->width, "Pixel is out of bounds");
30 MLX_ASSERT(y < image->height, "Pixel is out of bounds");
31
32 uint8_t* pixelstart = &image->pixels[(y * image->width + x) * BPP];
34}
GLuint color
Definition glad.h:3749
void mlx_draw_pixel(uint8_t *pixel, uint32_t color)
Here is the call graph for this function:

◆ mlx_put_string()

mlx_image_t * mlx_put_string ( mlx_t mlx,
const char str,
int32_t  x,
int32_t  y 
)

Draws a string on an image and then outputs it to the window.

Parameters
[in]mlxThe MLX instance handle.
[in]strThe string to draw.
[in]xThe X location.
[in]yThe Y location.
Returns
Image ptr to the string.

Definition at line 60 of file mlx_font.c.

61{
64
66 const size_t len = strlen(str);
67 if (len > MLX_MAX_STRING)
68 return ((void*)mlx_error(MLX_STRTOOBIG));
70 return (NULL);
71
72 // Draw the text itself
74 for (size_t i = 0; i < len; i++, imgoffset += FONT_WIDTH)
76
77 if (mlx_image_to_window(mlx, strimage, x, y) == -1)
79 return (strimage);
80}
int32_t mlx_image_to_window(mlx_t *mlx, mlx_image_t *img, int32_t x, int32_t y)
Definition mlx_images.c:121
void mlx_delete_image(mlx_t *mlx, mlx_image_t *image)
Definition mlx_images.c:204
mlx_image_t * mlx_new_image(mlx_t *mlx, uint32_t width, uint32_t height)
Definition mlx_images.c:161
#define MLX_MAX_STRING
Definition MLX42_Int.h:44
#define FONT_HEIGHT
Definition font.h:16
static void mlx_draw_char(mlx_image_t *image, int32_t texoffset, int32_t imgoffset)
Definition mlx_font.c:29
int32_t mlx_get_texoffset(char c)
Definition mlx_font.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_resize_hook()

void mlx_resize_hook ( mlx_t mlx,
mlx_resizefunc  func,
void param 
)

This function sets the resize callback, which is called when the window is resized

Parameters
[in]mlxThe MLX instance handle.
[in]funcThe resize callback function.
[in]paramAn additional optional parameter.

Definition at line 74 of file mlx_window.c.

75{
78
80 mlxctx->resize_hook.func = func;
81 mlxctx->resize_hook.param = param;
83}
static void mlx_resize_callback(GLFWwindow *window, int32_t width, int32_t height)
Definition mlx_window.c:44
Here is the call graph for this function:

◆ mlx_resize_image()

bool mlx_resize_image ( mlx_image_t img,
uint32_t  nwidth,
uint32_t  nheight 
)

Allows you to resize an image, a new pixel buffer is allocated to fit & the previous data is scaled to fit the new size.

Parameters
[in]imgThe image to resize.
[in]nwidthThe new width.
[in]nheightThe new height.
Returns
True if image was resized or false on error.

Definition at line 224 of file mlx_images.c.

225{
227
228 if (!nwidth || !nheight || nwidth > INT16_MAX || nheight > INT16_MAX)
229 return (mlx_error(MLX_INVDIM));
230 if (nwidth != img->width || nheight != img->height)
231 {
232 uint32_t* origin = (uint32_t*)img->pixels;
233 float wstep = (float)img->width / nwidth;
234 float hstep = (float)img->height / nheight;
235
237 if (!tempbuff)
238 return (mlx_error(MLX_MEMFAIL));
239 img->pixels = tempbuff;
241
242 uint32_t* destin = (uint32_t*)img->pixels;
243 for (uint32_t j = 0; j < nheight; j++)
244 for (uint32_t i = 0; i < nwidth; i++)
245 destin[j * nwidth + i] = origin[(uint32_t)(j * hstep) * img->width + (uint32_t)(i * wstep)];
246 (*(uint32_t*)&img->width) = nwidth;
247 (*(uint32_t*)&img->height) = nheight;
248 free(origin);
249 }
250 return (true);
251}
GLint j
Definition glad.h:2733
#define glTexImage2D
Definition glad.h:1985
#define GL_UNSIGNED_BYTE
Definition glad.h:251
#define GL_RGBA
Definition glad.h:286
Here is the call graph for this function:

◆ mlx_scroll_hook()

void mlx_scroll_hook ( mlx_t mlx,
mlx_scrollfunc  func,
void param 
)

This function sets the scroll callback, which is called when a scrolling device is used, such as a mouse wheel.

Parameters
[in]mlxThe MLX instance handle.
[in]funcThe scroll wheel callback function.
[in]paramAn additional optional parameter.

Definition at line 43 of file mlx_mouse.c.

44{
47
48 mlx_ctx_t* const mlxctx = mlx->context;
49 mlxctx->scroll_hook.func = func;
50 mlxctx->scroll_hook.param = param;
52}
static void mlx_scroll_cb(GLFWwindow *window, double xoffset, double yoffset)
Definition mlx_mouse.c:17
Here is the call graph for this function:

◆ mlx_set_cursor()

void mlx_set_cursor ( mlx_t mlx,
mlx_win_cursor_t cursor 
)

Sets the current cursor to the given custom cursor.

Parameters
[in]mlxThe MLX instance handle.
[in]cursorThe cursor object to display, if null default cursor is selected.

Definition at line 50 of file mlx_cursor.c.

◆ mlx_set_cursor_mode()

void mlx_set_cursor_mode ( mlx_t mlx,
mouse_mode_t  mode 
)

Defines the state for the cursor.

Parameters
[in]mlxThe MLX instance handle.
[in]modeA specified mouse mode.

Definition at line 58 of file mlx_cursor.c.

59{
61
63}
GLenum mode
Definition glad.h:1953

◆ mlx_set_icon()

void mlx_set_icon ( mlx_t mlx,
mlx_texture_t image 
)

Lets you set a custom image as the program icon.

NOTE: In MacOS this function does nothing, you should use the bundles icon to set the dock bar icon.

See also
: https://9to5mac.com/2021/11/08/change-mac-icons/
: https://github.com/glfw/glfw/issues/2041
Parameters
[in]mlxThe MLX instance handle.
[in]imageThe image to use as icon.

Definition at line 85 of file mlx_window.c.

86{
89
90 const GLFWimage icon = {
91 .width = image->width,
92 .height = image->height,
93 .pixels = image->pixels
94 };
95
97}

◆ mlx_set_instance_depth()

void mlx_set_instance_depth ( mlx_instance_t instance,
int32_t  zdepth 
)

Sets the depth / Z axis value of an instance.

NOTE: Keep in mind that images that are on the same Z layer cut each other off. so if you don't see your image anymore make sure it's not conflicting by being on the same layer as another image.

Parameters
[in]instanceThe instance on which to change the depth.
[in]zdepthThe new depth value.

NOTE: The reason why we don't sort directly is that the user might call this function multiple times in a row and we don't want to sort for every change. Pre-loop wise that is.

Definition at line 105 of file mlx_images.c.

106{
108
109 if (instance->z == zdepth)
110 return;
111 instance->z = zdepth;
112
113 /**
114 * NOTE: The reason why we don't sort directly is that
115 * the user might call this function multiple times in a row and we don't
116 * want to sort for every change. Pre-loop wise that is.
117 */
118 sort_queue = true;
119}

◆ mlx_set_mouse_pos()

void mlx_set_mouse_pos ( mlx_t mlx,
int32_t  x,
int32_t  y 
)

Sets the mouse position.

Parameters
[in]mlxThe MLX instance handle.
[in]posThe position.

Definition at line 83 of file mlx_mouse.c.

84{
86
87 glfwSetCursorPos(mlx->window, (double)x, (double)y);
88}

◆ mlx_set_setting()

void mlx_set_setting ( mlx_settings_t  setting,
int32_t  value 
)

Set a setting for MLX42. Settings can manipulate the core behaviour of the engine.

Parameters
[in]settingThe settings value, See mlx_settings_t type.
[in]valueSettings value to determine the state of the setting. Can be a boolean or an enum / macro.

Definition at line 213 of file mlx_init.c.

214{
215 MLX_ASSERT(setting >= 0 && setting < MLX_SETTINGS_MAX, "Invalid settings value");
217}
GLfloat value
Definition glad.h:2667
Here is the caller graph for this function:

◆ mlx_set_window_limit()

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 size limits of the specified window. Will force the window to not be resizable past or below the given values.

Pass -1 for no limit to any of the min/max parameters to ignore that boundary. For instance if you want a min window size but the max window size can be whatever.

Parameters
[in]mlxThe MLX instance handle.
[in]min_wThe min width of the window.
[in]max_wThe max width of the window.
[in]min_hThe min height of the window.
[in]max_hThe max height of the window.

Definition at line 124 of file mlx_window.c.

◆ mlx_set_window_pos()

void mlx_set_window_pos ( mlx_t mlx,
int32_t  xpos,
int32_t  ypos 
)

Sets the window's position.

Do not use this function to move an already visible window unless you have very good reasons for doing so, as it will confuse and annoy the user.

Parameters
[in]mlxThe MLX instance handle.
[in]xposThe x position.
[in]yposThe y position.

Definition at line 99 of file mlx_window.c.

100{
102
104}

◆ mlx_set_window_size()

void mlx_set_window_size ( mlx_t mlx,
int32_t  new_width,
int32_t  new_height 
)

Changes the window size to the newly specified values. Use this to update the window width and height values in the mlx handle.

Parameters
[in]mlxThe MLX instance handle.
[in]new_widthThe new desired width.
[in]new_heightThe new desired height.

Definition at line 115 of file mlx_window.c.

◆ mlx_set_window_title()

void mlx_set_window_title ( mlx_t mlx,
const char title 
)

Sets the title of the window.

Parameters
[in]mlxThe MLX instance handle.
[in]titleThe window title.

Definition at line 131 of file mlx_window.c.

132{
135
137}

◆ mlx_strerror()

const char * mlx_strerror ( mlx_errno_t  val)

Gets the english description of the error code.

Parameters
[in]valThe error code.
Returns
The error string that describes the error code.

Definition at line 54 of file mlx_error.c.

55{
56 MLX_ASSERT(val >= 0, "Index must be positive");
57 MLX_ASSERT(val < MLX_ERRMAX, "Index out of bounds");
58
59 return (mlx_errors[val]);
60}
GLuint GLfloat * val
Definition glad.h:3979
static const char * mlx_errors[MLX_ERRMAX]
Definition mlx_error.c:18
Here is the caller graph for this function:

◆ mlx_terminate()

void mlx_terminate ( mlx_t mlx)

Terminates MLX and cleans up any of its used resources. Using any functions that require mlx afterwards will be considered undefined behaviour, beware of segfaults.

Parameters
[in]mlxThe MLX instance handle.

All of glfw & glads resources are cleaned up by the terminate function. Now it's time to clean up our own mess.

Definition at line 36 of file mlx_exit.c.

37{
39
40 mlx_ctx_t *const mlxctx = mlx->context;
41
42 glUseProgram(0);
43 glLinkProgram(mlxctx->shaderprogram);
44 glDeleteProgram(mlxctx->shaderprogram);
46 mlx_lstclear((mlx_list_t**)(&mlxctx->hooks), &free);
47 mlx_lstclear((mlx_list_t**)(&mlxctx->render_queue), &free);
49 mlx_freen(2, mlxctx, mlx);
50}
void mlx_lstclear(mlx_list_t **lst, void(*del)(void *))
Definition mlx_list.c:33
#define glDeleteProgram
Definition glad.h:3359
#define glLinkProgram
Definition glad.h:3428
#define glUseProgram
Definition glad.h:3434
static void mlx_free_image(void *content)
Definition mlx_exit.c:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlx_texture_to_image()

mlx_image_t * mlx_texture_to_image ( mlx_t mlx,
mlx_texture_t texture 
)

Converts a given texture to an image.

Parameters
[in]mlxThe MLX instance handle.
[in]textureThe texture to use to create the image from.
Returns
mlx_image_t* The image created from the texture.

Definition at line 17 of file mlx_texture.c.

18{
21
23 if (image == NULL)
24 return (NULL);
25
28 for (uint32_t i = 0; i < texture->height; i++)
29 {
30 pixelx = &texture->pixels[(i * texture->width) * texture->bytes_per_pixel];
31 pixeli = &image->pixels[(i * image->width) * texture->bytes_per_pixel];
32 memmove(pixeli, pixelx, texture->width * texture->bytes_per_pixel);
33 }
34 return (image);
35}
Here is the call graph for this function:

Variable Documentation

◆ mlx_errno

Definition at line 161 of file mlx_init.c.