MLX42 1.0
MLX42
Loading...
Searching...
No Matches
mlx_font.c File Reference
#include "font.h"
#include "MLX42/MLX42_Int.h"
Include dependency graph for mlx_font.c:

Go to the source code of this file.

Functions

static void mlx_draw_char (mlx_image_t *image, int32_t texoffset, int32_t imgoffset)
 
const mlx_texture_tmlx_get_font (void)
 
int32_t mlx_get_texoffset (char c)
 
mlx_image_tmlx_put_string (mlx_t *mlx, const char *str, int32_t x, int32_t y)
 

Function Documentation

◆ mlx_draw_char()

static void mlx_draw_char ( mlx_image_t image,
int32_t  texoffset,
int32_t  imgoffset 
)
static

Does the actual copying of pixels form the atlas buffer to the image buffer.

Skips any non-printable characters.

Parameters
imageThe image to draw on.
textureThe font_atlas.
texoffsetThe character texture X offset.
imgoffsetThe image X offset.

Definition at line 29 of file mlx_font.c.

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}
#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
GLenum GLenum GLsizei void * image
Definition glad.h:5132
GLuint GLsizei GLsizei * length
Definition glad.h:3372
char * pixels
Definition font.h:25
uint32_t width
Definition font.h:22
Here is the caller graph for this function:

◆ 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}

◆ 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}
Here is the caller 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
@ 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
GLdouble x
Definition glad.h:2847
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
Here is the call graph for this function:
Here is the caller graph for this function: