MLX42 1.0
MLX42
Loading...
Searching...
No Matches
mlx_font.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* :::::::: */
4/* mlx_font.c :+: :+: */
5/* +:+ */
6/* By: W2Wizard <main@w2wizard.dev> +#+ */
7/* +#+ */
8/* Created: 2022/02/22 12:01:37 by W2Wizard #+# #+# */
9/* Updated: 2022/06/27 19:53:36 by lde-la-h ######## odam.nl */
10/* */
11/* ************************************************************************** */
12
13#include "font.h"
14#include "MLX42/MLX42_Int.h"
15
16//= Private =//
17
18/**
19 * Does the actual copying of pixels form the atlas buffer to the
20 * image buffer.
21 *
22 * Skips any non-printable characters.
23 *
24 * @param image The image to draw on.
25 * @param texture The font_atlas.
26 * @param texoffset The character texture X offset.
27 * @param imgoffset The image X offset.
28 */
30{
31 if (texoffset < 0)
32 return;
33
34 char* pixelx;
36 for (uint32_t y = 0; y < FONT_HEIGHT; y++)
37 {
39 pixeli = image->pixels + ((y * image->width + imgoffset) * BPP);
41 }
42}
43
44//= Public =//
45
47{
48 return ((const mlx_texture_t*)&font_atlas);
49}
50
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}
59
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
@ MLX_STRTOOBIG
Definition MLX42.h:387
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_NONNULL(var)
Definition MLX42_Int.h:46
bool mlx_error(mlx_errno_t val)
Definition mlx_error.c:43
#define MLX_MAX_STRING
Definition MLX42_Int.h:44
#define BPP
Definition MLX42_Int.h:42
#define FONT_HEIGHT
Definition font.h:16
#define FONT_WIDTH
Definition font.h:15
static struct s_font font_atlas
GLint y
Definition glad.h:1965
GLdouble x
Definition glad.h:2847
GLenum GLenum GLsizei void * image
Definition glad.h:5132
GLuint GLsizei GLsizei * length
Definition glad.h:3372
const mlx_texture_t * mlx_get_font(void)
Definition mlx_font.c:46
mlx_image_t * mlx_put_string(mlx_t *mlx, const char *str, int32_t x, int32_t y)
Definition mlx_font.c:60
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
Definition MLX42.h:361
char * pixels
Definition font.h:25
uint32_t width
Definition font.h:22