MLX42 1.0
MLX42
Loading...
Searching...
No Matches
MLX42.h
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* :::::::: */
4/* MLX42.h :+: :+: */
5/* +:+ */
6/* By: W2Wizard <main@w2wizard.dev> +#+ */
7/* +#+ */
8/* Created: 2021/12/28 02:29:06 by W2Wizard #+# #+# */
9/* Updated: 2023/03/30 16:23:19 by ntamayo- ######## odam.nl */
10/* */
11/* ************************************************************************** */
12
13/**
14 *
15 * MLX42 is a cross-platform low level and simple graphics
16 * library written in C and uses OpenGL and GLFW for it's underlying windowing
17 * and rendering system.
18 *
19 * It's a much more up-to-date alternative to the miniLibX which has been
20 * extensively proven to be fragile, unmaintained, deprecated and just
21 * plain painfully bad to work with. Also its code quality is dubious.
22 *
23 * Some structs contain potential void* which are to be ignored as they
24 * simply represent points of abstraction to the hidden internal header.
25 * This abstraction is crucial as the whole point of this lib so to hide
26 * all the bells and whistles in the "engine". Most user's have no need
27 * for the inner workings eitherway (shaders, vertex buffer, ...).
28 */
29
30#ifndef MLX42_H
31# define MLX42_H
32# include <stddef.h>
33# include <stdint.h>
34# include <stdbool.h>
35# ifdef __cplusplus
36extern "C" {
37# endif
38
39//= Types =//
40
41/**
42 * The input key codes are copied straight from GLFW.
43 * Any new entries should have the exact same values as defined in the glfw3.h.
44 */
45
46/**
47 * A key action such as pressing or releasing a key.
48 *
49 * @param RELEASE Execute when the key is being released.
50 * @param PRESS Execute when the key is being pressed.
51 * @param REPEAT Execute when the key is being held down.
52 */
59
60/**
61 * Key modifiers, such as shift, control or alt.
62 * These keys are flags meaning you can combine them to detect
63 * key combinations such as CTRL + ALT so CTRL | ALT.
64 *
65 * @param SHIFT The shift key.
66 * @param CONTROL The control key.
67 * @param ALT The alt key.
68 * @param SUPERKEY The Superkey such as the Windows Key or Command.
69 * @param CAPSLOCK The capslock key.
70 * @param NUMLOCK The numlock key.
71 */
72typedef enum modifier_key
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,
81
82/**
83 * The mouse button keycodes.
84 * @param LEFT The left mouse button.
85 * @param RIGHT The right mouse button.
86 * @param MIDDLE The middle mouse button, aka the Scrollwheel.
87 */
94
95/**
96 * Various mouse/cursor states.
97 * @param NORMAL Simple visible default cursor.
98 * @param HIDDEN The cursor is not rendered but still functions.
99 * @param DISABLED The cursor is not rendered, nor is it functional.
100 */
101typedef enum mouse_mode
102{
103 MLX_MOUSE_NORMAL = 0x00034001,
104 MLX_MOUSE_HIDDEN = 0x00034002,
105 MLX_MOUSE_DISABLED = 0x00034003,
107
108/**
109 * Various cursors that are standard.
110 * @param ARROW The regular arrow cursor.
111 * @param IBEAM The text input I-beam cursor shape.
112 * @param CROSSHAIR The crosshair shape cursor.
113 * @param HAND The hand shape cursor.
114 * @param HRESIZE The horizontal resize arrow shape.
115 * @param VRESIZE The vertical resize arrow shape.
116 */
117typedef enum cursor
118{
119 MLX_CURSOR_ARROW = 0x00036001,
120 MLX_CURSOR_IBEAM = 0x00036002,
122 MLX_CURSOR_HAND = 0x00036004,
123 MLX_CURSOR_HRESIZE = 0x00036005,
124 MLX_CURSOR_VRESIZE = 0x00036006,
126
127/**
128 * All sorts of keyboard keycodes.
129 *
130 * KP = Keypad.
131 */
132typedef enum keys
133{
253
254/**
255 * Base object for disk loaded textures.
256 * It contains rudementary information about the texture.
257 *
258 * @param width The width of the texture.
259 * @param height The height of the texture.
260 * @param pixels The literal pixel data.
261 * @param bytes_per_pixel The amount of bytes in a pixel, always 4.
262 */
263typedef struct mlx_texture
264{
265 uint32_t width;
266 uint32_t height;
268 uint8_t* pixels;
270
271/**
272 * Struct containing data regarding an XPM image.
273 *
274 * @param texture The texture data of the XPM.
275 * @param color_count The amount of colors available.
276 * @param cpp The amount of characters per pixel.
277 * @param mode The color mode, either (c)olor or (m)onochrome.
278 */
279typedef struct xpm
280{
282 int32_t color_count;
283 int32_t cpp;
284 char mode;
286
287/**
288 * An image instance can be summarized as just a simple
289 * x, y & z coordinate.
290 *
291 * Coordinates start from the top left of the screen at 0,0 and increase
292 * towards the bottom right.
293 *
294 * NOTE: To change the z value, use mlx_set_instance_depth!
295 *
296 * @param x The x location.
297 * @param y The y location.
298 * @param z The z depth, controls if the image is on the fore or background.
299 * @param enabled If true, the instance is drawn, else it's not.
300 */
301typedef struct mlx_instance
302{
303 int32_t x;
304 int32_t y;
305 int32_t z;
308
309/**
310 * Key function callback data.
311 * Data related to the mlx_key_hook function
312 *
313 * @param key The key that was pressed.
314 * @param action The action that was done with the key.
315 * @param os_key The os_key is unique for every key, and will have a
316 * different value/keycode depending on the platform.
317 * They may be consistent on different platforms.
318 * @param modifier The modifier key that was pressed, 0 if no key was pressed.
319 */
327
328/**
329 * An image with an individual buffer that can be rendered.
330 * Any value can be modified except the width/height and context.
331 *
332 * @param width The width of the image.
333 * @param height The height of the image.
334 * @param pixels The literal pixel data.
335 * @param instances An instance carrying the X, Y and Z location data.
336 * @param count The element count of the instances array.
337 * @param enabled If true the image is drawn onto the screen, else it's not.
338 * @param context Abstracted OpenGL data.
339 */
340typedef struct mlx_image
341{
342 const uint32_t width;
343 const uint32_t height;
344 uint8_t* pixels;
346 size_t count;
348 void* context;
350
351/**
352 * Main MLX handle, carries important data in regards to the program.
353 * @param window The window itself.
354 * @param context Abstracted opengl data.
355 * @param width The width of the window.
356 * @param height The height of the window.
357 * @param delta_time The time difference between the previous frame
358 * and the current frame.
359 */
360typedef struct mlx
361{
362 void* window;
363 void* context;
364 int32_t width;
365 int32_t height;
368
369// The error codes used to identify the correct error message.
370typedef enum mlx_errno
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
390
391// Global error code from the MLX42 library, 0 on no error.
393
394//= Global Settings =//
395
396// Set these values, if necessary, before calling `mlx_init` as they define the behaviour of MLX42.
397typedef enum mlx_settings
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.
406
407/**
408 * Callback function used to handle scrolling.
409 *
410 * @param[in] xdelta The mouse x delta.
411 * @param[in] ydelta The mouse y delta.
412 * @param[in] param Additional parameter to pass on to the function.
413 */
414typedef void (*mlx_scrollfunc)(double xdelta, double ydelta, void* param);
415
416/**
417 * Callback function used to handle mouse actions.
418 *
419 * @param[in] button The mouse button/key pressed.
420 * @param[in] action The mouse action that took place.
421 * @param[in] mods The modifier keys pressed together with the mouse key.
422 * @param[in] param Additional parameter to pass on to the function.
423 */
425
426/**
427 * Callback function used to handle raw mouse movement.
428 *
429 * @param[in] xpos The mouse x position.
430 * @param[in] ypos The mouse y position.
431 * @param[in] param Additional parameter to pass on to the function.
432 */
433typedef void (*mlx_cursorfunc)(double xpos, double ypos, void* param);
434
435/**
436 * Callback function used to handle key presses.
437 *
438 * @param[in] keydata The callback data, contains info on key, action, ...
439 * @param[in] param Additional parameter to pass on to the function.
440 */
441typedef void (*mlx_keyfunc)(mlx_key_data_t keydata, void* param);
442
443/**
444 * Callback function used to handle window resizing.
445 *
446 * WARNING: The function is called every frame during which the window is being
447 * resized, be aware!
448 *
449 * @param[in] width The new width of the window.
450 * @param[in] height The new height of the window.
451 * @param[in] param Additional parameter to pass on to the function.
452 */
453typedef void (*mlx_resizefunc)(int32_t width, int32_t height, void* param);
454
455/**
456 * Callback function used to handle window closing which is called when
457 * the user attempts to close the window, for example by clicking the
458 * close widget in the title bar.
459 *
460 * @param[in] param Additional parameter to pass on to the function.
461 */
462typedef void (*mlx_closefunc)(void* param);
463
464/**
465 * Typedef for a window cursor object, these eventually expand to
466 * the native cursor object, but are hidden from the user.
467 *
468 * Under GLFW they are named GLFWcursor and have a wrapper for each implementation.
469 * You can find the ACTUAL cursor in the following files at GLFW named under *_platform.h
470 */
471typedef void mlx_win_cursor_t;
472
473//= Error Functions =//
474
475/**
476 * Gets the english description of the error code.
477 *
478 * @param[in] val The error code.
479 * @return The error string that describes the error code.
480 */
481const char* mlx_strerror(mlx_errno_t val);
482
483//= Generic Functions =//
484
485/**
486 * Initializes a new MLX42 Instance.
487 *
488 * @param[in] width The width of the window.
489 * @param[in] height The height of the window.
490 * @param[in] title The title of the window.
491 * @param[in] resize Enable window resizing.
492 * @returns Ptr to the MLX handle or null on failure.
493 */
494mlx_t* mlx_init(int32_t width, int32_t height, const char* title, bool resize);
495
496/**
497 * Set a setting for MLX42.
498 * Settings can manipulate the core behaviour of the engine.
499 *
500 * @param[in] setting The settings value, See mlx_settings_t type.
501 * @param[in] value Settings value to determine the state of the setting. Can be a boolean or an enum / macro.
502 */
503void mlx_set_setting(mlx_settings_t setting, int32_t value);
504
505/**
506 * Notifies MLX that it should stop rendering and exit the main loop.
507 * This is not the same as terminate, this simply tells MLX to close the window.
508 *
509 * @param[in] mlx The MLX instance handle.
510 */
512
513/**
514 * Initializes the rendering of MLX, this function won't return until
515 * mlx_close_window is called, meaning it will loop until the user requests that
516 * the window should close.
517 *
518 * @param[in] mlx The MLX instance handle.
519 */
520void mlx_loop(mlx_t* mlx);
521
522/**
523 * Lets you set a custom image as the program icon.
524 *
525 * NOTE: In MacOS this function does nothing, you should use the bundles icon to set the dock bar icon.
526 * @see: https://9to5mac.com/2021/11/08/change-mac-icons/
527 * @see: https://github.com/glfw/glfw/issues/2041
528 *
529 * @param[in] mlx The MLX instance handle.
530 * @param[in] image The image to use as icon.
531 */
533
534/**
535 * Terminates MLX and cleans up any of its used resources.
536 * Using any functions that require mlx afterwards will
537 * be considered undefined behaviour, beware of segfaults.
538 *
539 * @param[in] mlx The MLX instance handle.
540 */
541void mlx_terminate(mlx_t* mlx);
542
543/**
544 * Gets the elapsed time since MLX was initialized.
545 *
546 * @return The amount of time elapsed in seconds.
547 */
548double mlx_get_time(void);
549
550//= Window/Monitor Functions =//
551
552/**
553 * This function brings the specified window to front and sets input focus.
554 *
555 * Do not use this function to steal focus from other applications unless
556 * you are certain that is what the user wants. Focus stealing can be
557 * extremely disruptive.
558 *
559 * @param[in] mlx The MLX instance handle.
560 */
561void mlx_focus(mlx_t* mlx);
562
563/**
564 * Gets the size of the specified monitor.
565 *
566 * @param[in] index Normally 0, in case of multiple windows, can be specified
567 * @param[in] width The width of the window.
568 * @param[in] height The height of the window.
569 */
570void mlx_get_monitor_size(int32_t index, int32_t* width, int32_t* height);
571
572/**
573 * Sets the window's position.
574 *
575 * Do not use this function to move an already visible window unless you
576 * have very good reasons for doing so, as it will confuse and annoy the user.
577 *
578 * @param[in] mlx The MLX instance handle.
579 * @param[in] xpos The x position.
580 * @param[in] ypos The y position.
581 */
582void mlx_set_window_pos(mlx_t* mlx, int32_t xpos, int32_t ypos);
583
584/**
585 * Gets the window's position.
586 *
587 * @param[in] mlx The MLX instance handle.
588 * @param[out] xpos The x position.
589 * @param[out] ypos The y position.
590 */
591void mlx_get_window_pos(mlx_t* mlx, int32_t* xpos, int32_t* ypos);
592
593/**
594 * Changes the window size to the newly specified values.
595 * Use this to update the window width and height values in the mlx handle.
596 *
597 * @param[in] mlx The MLX instance handle.
598 * @param[in] new_width The new desired width.
599 * @param[in] new_height The new desired height.
600 */
601void mlx_set_window_size(mlx_t* mlx, int32_t new_width, int32_t new_height);
602
603/**
604 * Sets the size limits of the specified window.
605 * Will force the window to not be resizable past or below the given values.
606 *
607 * Pass -1 for no limit to any of the min/max parameters to ignore that boundary.
608 * For instance if you want a min window size but the max window size can be whatever.
609 *
610 * @param[in] mlx The MLX instance handle.
611 * @param[in] min_w The min width of the window.
612 * @param[in] max_w The max width of the window.
613 * @param[in] min_h The min height of the window.
614 * @param[in] max_h The max height of the window.
615 */
616void mlx_set_window_limit(mlx_t* mlx, int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h);
617
618/**
619 * Sets the title of the window.
620 *
621 * @param[in] mlx The MLX instance handle.
622 * @param[in] title The window title.
623 */
624void mlx_set_window_title(mlx_t* mlx, const char* title);
625
626//= Input Functions =//
627
628/**
629 * Returns true or false if the key is down or not.
630 *
631 * @param[in] mlx The MLX instance handle.
632 * @param[in] key The keycode to check, use MLX_KEY_... to specify!
633 * @returns True or false if the key is down or not.
634 */
635bool mlx_is_key_down(mlx_t* mlx, keys_t key);
636
637/**
638 * Checks whether a mouse button is pressed or not.
639 *
640 * @param[in] mlx The MLX instance handle.
641 * @param[in] key A specific mouse key. e.g MLX_MOUSE_BUTTON_0
642 * @returns True or false if the mouse key is down or not.
643 */
645
646/**
647 * Returns the current, relative, mouse cursor position on the window, starting
648 * from the top left corner.
649 *
650 * Negative values or values greater than window width or height
651 * indicate that it is outside the window.
652 *
653 * @param[in] mlx The MLX instance handle.
654 * @param[out] x The position.
655 * @param[out] y The position.
656 */
657void mlx_get_mouse_pos(mlx_t* mlx, int32_t* x, int32_t* y);
658
659/**
660 * Sets the mouse position.
661 *
662 * @param[in] mlx The MLX instance handle.
663 * @param[in] pos The position.
664 */
665void mlx_set_mouse_pos(mlx_t* mlx, int32_t x, int32_t y);
666
667/**
668 * Defines the state for the cursor.
669 *
670 * @param[in] mlx The MLX instance handle.
671 * @param[in] mode A specified mouse mode.
672 */
674
675/**
676 * Retrieves the system standard cursor.
677 *
678 * @param[in] type The standard cursor type to create.
679 * @return The cursor object or null on failure.
680 */
682
683/**
684 * Allows for the creation of custom cursors with a given texture.
685 *
686 * Use mlx_set_cursor to select the specific cursor.
687 * Cursors are destroyed at mlx_terminate().
688 *
689 * @param[in] texture The texture to use as cursor.
690 * @returns The cursor object or null on failure.
691 */
693
694/**
695 * Destroys the given cursor object.
696 *
697 * @param[in] cursor The cursor object to destroy.
698 */
700
701/**
702 * Sets the current cursor to the given custom cursor.
703 *
704 * @param[in] mlx The MLX instance handle.
705 * @param[in] cursor The cursor object to display, if null default cursor is selected.
706 */
708
709//= Hooks =//
710
711/**
712 * This function sets the scroll callback, which is called when a scrolling
713 * device is used, such as a mouse wheel.
714 *
715 * @param[in] mlx The MLX instance handle.
716 * @param[in] func The scroll wheel callback function.
717 * @param[in] param An additional optional parameter.
718 */
720
721/**
722 * This function sets the mouse callback, which is called when a mouse
723 * does any sort of action such as pressing a key.
724 *
725 * @param[in] mlx The MLX instance handle.
726 * @param[in] func The mouse callback function.
727 * @param[in] param An additional optional parameter.
728 */
730
731/**
732 * This function sets the cursor callback, which is called when the
733 * mouse position changes. Position is relative to the window.
734 *
735 * @param[in] mlx The MLX instance handle.
736 * @param[in] func The cursor callback function.
737 * @param[in] param An additional optional parameter.
738 */
740
741/**
742 * This function sets the key callback, which is called when a key is pressed
743 * on the keyboard. Useful for single keypress detection.
744 *
745 * @param[in] mlx The MLX instance handle.
746 * @param[in] func The keypress callback function.
747 * @param[in] param An additional optional parameter.
748 */
750
751/**
752 * This function sets the close callback, which is called in attempt to close
753 * the window device such as a close window widget used in the window bar.
754 *
755 * @param[in] mlx The MLX instance handle.
756 * @param[in] func The close callback function.
757 * @param[in] param An additional optional parameter.
758 */
760
761/**
762 * This function sets the resize callback, which is called when the window is
763 * resized
764 *
765 * @param[in] mlx The MLX instance handle.
766 * @param[in] func The resize callback function.
767 * @param[in] param An additional optional parameter.
768 */
770
771/**
772 * Generic loop hook for any custom hooks to add to the main loop.
773 * Executes a function per frame, so be careful.
774 *
775 * @param[in] mlx The MLX instance handle.
776 * @param[in] f The function.
777 * @param[in] param The parameter to pass on to the function.
778 * @returns Whether or not the hook was added successfully.
779 */
780bool mlx_loop_hook(mlx_t* mlx, void (*f)(void*), void* param);
781
782//= Texture Functions =//
783
784/**
785 * Decode/load a PNG file into a buffer.
786 *
787 * @param[in] path Path to the PNG file.
788 * @return If successful the texture data is returned, else NULL.
789 */
790mlx_texture_t* mlx_load_png(const char* path);
791
792/**
793 * Loads an XPM42 texture from the given file path.
794 *
795 * @param[in] path The file path to the XPM texture.
796 * @returns The XPM texture struct containing its information.
797 */
798xpm_t* mlx_load_xpm42(const char* path);
799
800/**
801 * Deletes a texture by freeing its allocated data.
802 *
803 * @param[in] texture The texture to free.
804 */
806
807/**
808 * Deletes an XPM42 texture by freeing its allocated data.
809 *
810 * This will not remove any already drawn XPMs, it simply
811 * deletes the XPM buffer.
812 *
813 * @param[in] xpm The xpm texture to delete.
814 */
816
817/**
818 * Converts a given texture to an image.
819 *
820 * @param[in] mlx The MLX instance handle.
821 * @param[in] texture The texture to use to create the image from.
822 * @return mlx_image_t* The image created from the texture.
823 */
825
826//= Image Functions =//
827
828/**
829 * Sets / puts a pixel onto an image.
830 *
831 * NOTE: It is considered undefined behaviour when putting a pixel
832 * beyond the bounds of an image.
833 *
834 * @param[in] image The MLX instance handle.
835 * @param[in] x The X coordinate position.
836 * @param[in] y The Y coordinate position.
837 * @param[in] color The color value to put.
838 */
839void mlx_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t color);
840
841/**
842 * Creates and allocates a new image buffer.
843 *
844 * @param[in] mlx The MLX instance handle.
845 * @param[in] width The desired width of the image.
846 * @param[in] height The desired height of the image.
847 * @return Pointer to the image buffer, if it failed to allocate then NULL.
848 */
849mlx_image_t* mlx_new_image(mlx_t* mlx, uint32_t width, uint32_t height);
850
851/**
852 * Draws a new instance of an image, it will then share the same
853 * pixel buffer as the image.
854 *
855 * NOTE: Keep in mind that the instance array gets reallocated, try
856 * to store the return value to the instance!
857 * NOT the pointer! It will become invalid!
858 *
859 * WARNING: Try to display as few images on the window as possible,
860 * drawing too many images will cause a loss in performance!
861 *
862 * @param[in] mlx The MLX instance handle.
863 * @param[in] img The image to draw on the screen.
864 * @param[in] x The X position.
865 * @param[in] y The Y position.
866 * @return Index to the instance, or -1 on failure.
867 */
868int32_t mlx_image_to_window(mlx_t* mlx, mlx_image_t* img, int32_t x, int32_t y);
869
870/**
871 * Deleting an image will remove it from the render queue as well as any and all
872 * instances it might have. Additionally, just as extra measures sets all the
873 * data to NULL.
874 *
875 * If you simply wish to stop rendering an image without de-allocation
876 * set the 'enabled' boolean in the image struct.
877 *
878 * @param[in] mlx The MLX instance handle.
879 * @param[in] image The image to delete.
880 */
882
883/**
884 * Allows you to resize an image, a new pixel buffer is allocated
885 * to fit & the previous data is scaled to fit the new size.
886 *
887 * @param[in] img The image to resize.
888 * @param[in] nwidth The new width.
889 * @param[in] nheight The new height.
890 * @return True if image was resized or false on error.
891 */
892bool mlx_resize_image(mlx_image_t* img, uint32_t nwidth, uint32_t nheight);
893
894/**
895 * Sets the depth / Z axis value of an instance.
896 *
897 * NOTE: Keep in mind that images that are on the same Z layer cut each other off.
898 * so if you don't see your image anymore make sure it's not conflicting by being on
899 * the same layer as another image.
900 *
901 * @param[in] instance The instance on which to change the depth.
902 * @param[in] zdepth The new depth value.
903 */
904void mlx_set_instance_depth(mlx_instance_t* instance, int32_t zdepth);
905
906//= String Functions =//
907
908/**
909 * Draws a string on an image and then outputs it to the window.
910 *
911 * @param[in] mlx The MLX instance handle.
912 * @param[in] str The string to draw.
913 * @param[in] x The X location.
914 * @param[in] y The Y location.
915 * @return Image ptr to the string.
916 */
917mlx_image_t* mlx_put_string(mlx_t* mlx, const char* str, int32_t x, int32_t y);
918
919/**
920 * Retrieve the texture data for the built-in font.
921 *
922 * @return Pointer to the built-in font texture.
923 */
924const mlx_texture_t* mlx_get_font(void);
925
926/**
927 * This function lets you retrieve the X offset
928 * of the given char in the font texture.
929 *
930 * NOTE: A single character is 10 * 20 in pixels!
931 *
932 * @param[in] c The character to get the offset from.
933 * @return Non-negative if found or -1 if not found.
934 */
935int32_t mlx_get_texoffset(char c);
936
937# ifdef __cplusplus
938}
939# endif
940#endif
mlx_texture_t * mlx_load_png(const char *path)
Definition mlx_png.c:17
modifier_key
Definition MLX42.h:73
@ 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
int32_t mlx_image_to_window(mlx_t *mlx, mlx_image_t *img, int32_t x, int32_t y)
Definition mlx_images.c:121
enum mlx_settings mlx_settings_t
void mlx_set_instance_depth(mlx_instance_t *instance, int32_t zdepth)
Definition mlx_images.c:105
void mlx_set_window_limit(mlx_t *mlx, int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h)
Definition mlx_window.c:124
mlx_image_t * mlx_texture_to_image(mlx_t *mlx, mlx_texture_t *texture)
Definition mlx_texture.c:17
enum mouse_key mouse_key_t
struct mlx_key_data mlx_key_data_t
mouse_mode
Definition MLX42.h:102
@ MLX_MOUSE_DISABLED
Definition MLX42.h:105
@ MLX_MOUSE_HIDDEN
Definition MLX42.h:104
@ MLX_MOUSE_NORMAL
Definition MLX42.h:103
void mlx_focus(mlx_t *mlx)
Definition mlx_utils.c:126
const char * mlx_strerror(mlx_errno_t val)
Definition mlx_error.c:54
action
Definition MLX42.h:54
@ MLX_REPEAT
Definition MLX42.h:57
@ MLX_RELEASE
Definition MLX42.h:55
@ MLX_PRESS
Definition MLX42.h:56
keys
Definition MLX42.h:133
@ 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
void mlx_set_window_title(mlx_t *mlx, const char *title)
Definition mlx_window.c:131
mouse_key
Definition MLX42.h:89
@ MLX_MOUSE_BUTTON_MIDDLE
Definition MLX42.h:92
@ MLX_MOUSE_BUTTON_LEFT
Definition MLX42.h:90
@ MLX_MOUSE_BUTTON_RIGHT
Definition MLX42.h:91
const mlx_texture_t * mlx_get_font(void)
Definition mlx_font.c:46
mlx_t * mlx_init(int32_t width, int32_t height, const char *title, bool resize)
Definition mlx_init.c:164
enum keys keys_t
bool mlx_resize_image(mlx_image_t *img, uint32_t nwidth, uint32_t nheight)
Definition mlx_images.c:224
void mlx_delete_xpm42(xpm_t *xpm)
Definition mlx_xpm42.c:203
enum mouse_mode mouse_mode_t
mlx_image_t * mlx_put_string(mlx_t *mlx, const char *str, int32_t x, int32_t y)
Definition mlx_font.c:60
enum mlx_errno mlx_errno_t
void(* mlx_closefunc)(void *param)
Definition MLX42.h:462
enum cursor cursor_t
void mlx_resize_hook(mlx_t *mlx, mlx_resizefunc func, void *param)
Definition mlx_window.c:74
void mlx_destroy_cursor(mlx_win_cursor_t *cursor)
Definition mlx_cursor.c:43
void mlx_scroll_hook(mlx_t *mlx, mlx_scrollfunc func, void *param)
Definition mlx_mouse.c:43
mlx_settings
Definition MLX42.h:398
@ 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
void mlx_key_hook(mlx_t *mlx, mlx_keyfunc func, void *param)
Definition mlx_keys.c:33
xpm_t * mlx_load_xpm42(const char *path)
Definition mlx_xpm42.c:181
void mlx_close_hook(mlx_t *mlx, mlx_closefunc func, void *param)
Definition mlx_window.c:63
void mlx_close_window(mlx_t *mlx)
Definition mlx_exit.c:26
void(* mlx_mousefunc)(mouse_key_t button, action_t action, modifier_key_t mods, void *param)
Definition MLX42.h:424
void mlx_get_monitor_size(int32_t index, int32_t *width, int32_t *height)
Definition mlx_monitor.c:17
mlx_win_cursor_t * mlx_create_cursor(mlx_texture_t *texture)
Definition mlx_cursor.c:27
void mlx_set_icon(mlx_t *mlx, mlx_texture_t *image)
Definition mlx_window.c:85
void mlx_set_cursor(mlx_t *mlx, mlx_win_cursor_t *cursor)
Definition mlx_cursor.c:50
void mlx_mouse_hook(mlx_t *mlx, mlx_mousefunc func, void *param)
Definition mlx_mouse.c:54
void mlx_set_setting(mlx_settings_t setting, int32_t value)
Definition mlx_init.c:213
mlx_win_cursor_t * mlx_create_std_cursor(cursor_t type)
Definition mlx_cursor.c:17
enum action action_t
void mlx_put_pixel(mlx_image_t *image, uint32_t x, uint32_t y, uint32_t color)
void mlx_set_window_pos(mlx_t *mlx, int32_t xpos, int32_t ypos)
Definition mlx_window.c:99
struct xpm xpm_t
void mlx_win_cursor_t
Definition MLX42.h:471
void mlx_get_mouse_pos(mlx_t *mlx, int32_t *x, int32_t *y)
Definition mlx_mouse.c:90
mlx_errno
Definition MLX42.h:371
@ 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
void mlx_cursor_hook(mlx_t *mlx, mlx_cursorfunc func, void *param)
Definition mlx_mouse.c:65
void mlx_delete_image(mlx_t *mlx, mlx_image_t *image)
Definition mlx_images.c:204
void mlx_set_mouse_pos(mlx_t *mlx, int32_t x, int32_t y)
Definition mlx_mouse.c:83
void(* mlx_resizefunc)(int32_t width, int32_t height, void *param)
Definition MLX42.h:453
cursor
Definition MLX42.h:118
@ 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
void mlx_set_cursor_mode(mlx_t *mlx, mouse_mode_t mode)
Definition mlx_cursor.c:58
struct mlx_image mlx_image_t
mlx_image_t * mlx_new_image(mlx_t *mlx, uint32_t width, uint32_t height)
Definition mlx_images.c:161
struct mlx_texture mlx_texture_t
void mlx_loop(mlx_t *mlx)
Definition mlx_loop.c:97
int32_t mlx_get_texoffset(char c)
Definition mlx_font.c:51
bool mlx_is_mouse_down(mlx_t *mlx, mouse_key_t key)
Definition mlx_mouse.c:76
void(* mlx_scrollfunc)(double xdelta, double ydelta, void *param)
Definition MLX42.h:414
void(* mlx_cursorfunc)(double xpos, double ypos, void *param)
Definition MLX42.h:433
void(* mlx_keyfunc)(mlx_key_data_t keydata, void *param)
Definition MLX42.h:441
double mlx_get_time(void)
Definition mlx_utils.c:121
struct mlx_instance mlx_instance_t
void mlx_delete_texture(mlx_texture_t *texture)
Definition mlx_texture.c:37
void mlx_set_window_size(mlx_t *mlx, int32_t new_width, int32_t new_height)
Definition mlx_window.c:115
enum modifier_key modifier_key_t
bool mlx_is_key_down(mlx_t *mlx, keys_t key)
Definition mlx_keys.c:44
void mlx_get_window_pos(mlx_t *mlx, int32_t *xpos, int32_t *ypos)
Definition mlx_window.c:106
void mlx_terminate(mlx_t *mlx)
Definition mlx_exit.c:36
struct mlx mlx_t
bool mlx_loop_hook(mlx_t *mlx, void(*f)(void *), void *param)
Definition mlx_loop.c:70
GLfloat value
Definition glad.h:2667
GLuint texture
Definition glad.h:2899
GLenum func
Definition glad.h:3336
GLenum mode
Definition glad.h:1953
GLuint index
Definition glad.h:3345
GLint y
Definition glad.h:1965
GLint GLsizei GLsizei height
Definition glad.h:1965
GLint GLsizei width
Definition glad.h:1965
GLuint color
Definition glad.h:3749
GLdouble f
Definition glad.h:2085
GLdouble x
Definition glad.h:2847
GLenum GLenum GLsizei void * image
Definition glad.h:5132
GLint GLint GLsizei GLint GLenum GLenum type
Definition glad.h:1980
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat * val
Definition glad.h:3979
GLint void * img
Definition glad.h:3003
GLenum GLfloat param
Definition glad.h:1968
uint8_t * pixels
Definition MLX42.h:344
size_t count
Definition MLX42.h:346
void * context
Definition MLX42.h:348
mlx_instance_t * instances
Definition MLX42.h:345
const uint32_t width
Definition MLX42.h:342
const uint32_t height
Definition MLX42.h:343
bool enabled
Definition MLX42.h:347
bool enabled
Definition MLX42.h:306
int32_t z
Definition MLX42.h:305
int32_t x
Definition MLX42.h:303
int32_t y
Definition MLX42.h:304
action_t action
Definition MLX42.h:323
keys_t key
Definition MLX42.h:322
modifier_key_t modifier
Definition MLX42.h:325
int32_t os_key
Definition MLX42.h:324
uint32_t height
Definition MLX42.h:266
uint8_t * pixels
Definition MLX42.h:268
uint32_t width
Definition MLX42.h:265
uint8_t bytes_per_pixel
Definition MLX42.h:267
Definition MLX42.h:361
double delta_time
Definition MLX42.h:366
void * context
Definition MLX42.h:363
int32_t width
Definition MLX42.h:364
int32_t height
Definition MLX42.h:365
void * window
Definition MLX42.h:362
Definition MLX42.h:280
int32_t color_count
Definition MLX42.h:282
char mode
Definition MLX42.h:284
mlx_texture_t texture
Definition MLX42.h:281
int32_t cpp
Definition MLX42.h:283