MLX42 1.0
MLX42
Loading...
Searching...
No Matches
mlx_window.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* :::::::: */
4/* mlx_window.c :+: :+: */
5/* +:+ */
6/* By: W2wizard <main@w2wizard.dev> +#+ */
7/* +#+ */
8/* Created: 2022/02/08 01:14:59 by W2wizard #+# #+# */
9/* Updated: 2022/11/22 09:06:54 by jvan-hal ######## odam.nl */
10/* */
11/* ************************************************************************** */
12
13#include "MLX42/MLX42_Int.h"
14
15//= Private =//
16
17/**
18 * Recalculate the view projection matrix, used by images for screen pos
19 * Reference: https://bit.ly/3KuHOu1 (Matrix View Projection)
20 */
22{
23 const mlx_ctx_t* mlxctx = mlx->context;
24 const float depth = mlxctx->zdepth;
25
26 /**
27 * In case the setting to stretch the image is set, we maintain the width and height but not
28 * the depth.
29 */
30 const float width = mlx_settings[MLX_STRETCH_IMAGE] ? mlxctx->initialWidth : mlx->width;
31 const float height = mlx_settings[MLX_STRETCH_IMAGE] ? mlxctx->initialHeight : mlx->height;
32
33 const float matrix[16] = {
34 2.f / width, 0, 0, 0,
35 0, 2.f / -(height), 0, 0,
36 0, 0, -2.f / (depth - -depth), 0,
37 -1, -(height / -height),
38 -((depth + -depth) / (depth - -depth)), 1
39 };
40
41 glUniformMatrix4fv(glGetUniformLocation(mlxctx->shaderprogram, "ProjMatrix"), 1, GL_FALSE, matrix);
42}
43
45{
46 const mlx_t* mlx = glfwGetWindowUserPointer(window);
47 const mlx_ctx_t* mlxctx = mlx->context;
48
49 if (mlxctx->resize_hook.func)
50 mlxctx->resize_hook.func(width, height, mlxctx->resize_hook.param);
51}
52
53static void mlx_close_callback(GLFWwindow* window)
54{
55 const mlx_t* mlx = glfwGetWindowUserPointer(window);
56 const mlx_close_t close_hook = ((mlx_ctx_t*)mlx->context)->close_hook;
57
58 close_hook.func(close_hook.param);
59}
60
61//= Public =//
62
64{
67
69 mlxctx->close_hook.func = func;
70 mlxctx->close_hook.param = param;
72}
73
75{
78
80 mlxctx->resize_hook.func = func;
81 mlxctx->resize_hook.param = param;
83}
84
86{
89
90 const GLFWimage icon = {
91 .width = image->width,
92 .height = image->height,
93 .pixels = image->pixels
94 };
95
97}
98
105
114
123
130
132{
135
137}
void(* mlx_closefunc)(void *param)
Definition MLX42.h:462
mlx_settings
Definition MLX42.h:398
@ MLX_STRETCH_IMAGE
Definition MLX42.h:399
void(* mlx_resizefunc)(int32_t width, int32_t height, void *param)
Definition MLX42.h:453
#define MLX_NONNULL(var)
Definition MLX42_Int.h:46
#define glGetUniformLocation
Definition glad.h:3401
GLenum func
Definition glad.h:3336
#define glUniformMatrix4fv
Definition glad.h:3491
GLint GLsizei GLsizei height
Definition glad.h:1965
GLint GLsizei width
Definition glad.h:1965
GLenum GLenum GLsizei void * image
Definition glad.h:5132
GLint GLint GLsizei GLsizei GLsizei depth
Definition glad.h:2966
GLuint GLsizei GLsizei * length
Definition glad.h:3372
#define GL_FALSE
Definition glad.h:139
GLenum GLfloat param
Definition glad.h:1968
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
void mlx_set_window_title(mlx_t *mlx, const char *title)
Definition mlx_window.c:131
void mlx_resize_hook(mlx_t *mlx, mlx_resizefunc func, void *param)
Definition mlx_window.c:74
void mlx_close_hook(mlx_t *mlx, mlx_closefunc func, void *param)
Definition mlx_window.c:63
void mlx_set_icon(mlx_t *mlx, mlx_texture_t *image)
Definition mlx_window.c:85
static void mlx_resize_callback(GLFWwindow *window, int32_t width, int32_t height)
Definition mlx_window.c:44
void mlx_set_window_pos(mlx_t *mlx, int32_t xpos, int32_t ypos)
Definition mlx_window.c:99
static void mlx_close_callback(GLFWwindow *window)
Definition mlx_window.c:53
void mlx_update_matrix(const mlx_t *mlx)
Definition mlx_window.c:21
void mlx_set_window_size(mlx_t *mlx, int32_t new_width, int32_t new_height)
Definition mlx_window.c:115
void mlx_get_window_pos(mlx_t *mlx, int32_t *xpos, int32_t *ypos)
Definition mlx_window.c:106
mlx_closefunc func
Definition MLX42_Int.h:135
void * param
Definition MLX42_Int.h:134
Definition MLX42.h:361
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