prosperon/source/engine/font.h

53 lines
1.4 KiB
C
Raw Normal View History

2021-11-30 21:29:18 -06:00
#ifndef FONT_H
#define FONT_H
2023-05-04 17:07:00 -05:00
#include "sokol/sokol_gfx.h"
#include "render.h"
2023-05-24 20:45:50 -05:00
#include "HandmadeMath.h"
2021-11-30 21:29:18 -06:00
2024-10-17 17:23:33 -05:00
typedef enum {
LEFT,
RIGHT,
CENTER,
JUSTIFY
} ALIGN;
2022-11-19 17:13:57 -06:00
struct shader;
struct window;
2021-11-30 21:29:18 -06:00
2024-05-12 18:36:14 -05:00
extern sg_buffer text_ssbo;
2021-11-30 21:29:18 -06:00
/// Holds all state information relevant to a character as loaded using FreeType
struct Character {
2024-10-14 20:07:32 -05:00
float Advance; // Horizontal offset to advance to next glyph
2024-10-13 19:44:28 -05:00
float leftbearing; // X offset from cursor to render at
float topbearing; // Y offset from cursor to render at
2024-10-14 20:07:32 -05:00
struct rect rect; // the rect on the font image to render from, uv coordinates
HMM_Vec2 size; // The pixel size of this letter
2021-11-30 21:29:18 -06:00
};
struct sFont {
2023-05-30 15:41:02 -05:00
uint32_t height; /* in pixels */
2024-10-13 19:44:28 -05:00
float ascent; // pixels
float descent; // pixels
float linegap; //pixels
2023-12-22 07:14:44 -06:00
struct Character Characters[256];
2023-05-12 13:22:05 -05:00
sg_image texID;
2024-05-12 18:36:14 -05:00
texture *texture;
2021-11-30 21:29:18 -06:00
};
2024-04-09 16:48:15 -05:00
typedef struct sFont font;
2024-10-14 20:07:32 -05:00
typedef struct Character glyph;
2024-04-09 16:48:15 -05:00
void font_free(font *f);
2022-01-19 16:43:21 -06:00
struct sFont *MakeFont(const char *fontfile, int height);
2023-10-04 17:57:37 -05:00
void sdrawCharacter(struct Character c, HMM_Vec2 cursor, float scale, struct rgba color);
2024-10-14 20:07:32 -05:00
void renderText(const char *text, HMM_Vec2 pos, font *f, float scale, struct rgba color, float wrap);
HMM_Vec2 measure_text(const char *text, font *f, float scale, float letterSpacing, float wrap);
2021-11-30 21:29:18 -06:00
2024-10-14 20:07:32 -05:00
// Flushes all letters from renderText calls into the provided buffer
2024-07-18 17:09:35 -05:00
int text_flush(sg_buffer *buf);
2023-05-06 21:16:10 -05:00
2021-11-30 21:29:18 -06:00
#endif