prosperon/source/engine/font.h

48 lines
1.2 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
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 {
2023-05-24 20:45:50 -05:00
float Size[2]; // Size of glyph
float Bearing[2]; // Offset from baseline to left/top of glyph
2023-05-30 15:41:02 -05:00
int Advance; // Horizontal offset to advance to next glyph
int leftbearing;
struct rect rect;
2021-11-30 21:29:18 -06:00
};
struct sFont {
2023-05-12 13:22:05 -05:00
uint32_t fontTexture;
2023-05-30 15:41:02 -05:00
uint32_t height; /* in pixels */
2024-07-09 01:03:39 -05:00
float ascent;
float descent;
float linegap;
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;
void font_free(font *f);
void font_init();
2022-01-19 16:43:21 -06:00
struct sFont *MakeFont(const char *fontfile, int height);
2024-04-09 16:48:15 -05:00
void font_set(font *f);
2023-10-04 17:57:37 -05:00
void sdrawCharacter(struct Character c, HMM_Vec2 cursor, float scale, struct rgba color);
2022-01-31 17:04:59 -06:00
void text_settype(struct sFont *font);
struct boundingbox text_bb(const char *text, float scale, float lw, float tracking);
int renderText(const char *text, HMM_Vec2 pos, float scale, struct rgba color, float lw, int caret, float tracking);
2021-11-30 21:29:18 -06:00
2024-05-12 18:36:14 -05:00
int text_flush();
2023-05-06 21:16:10 -05:00
2021-11-30 21:29:18 -06:00
#endif