#ifndef TEXT_H_
#define TEXT_H_

extern float avgfps;
extern float avgupdates;
extern float avgfixed;

extern char *fpstext;
extern char *timertext;

extern int firstTextRun;

extern unsigned int TXT_WIDTH;
extern unsigned int TXT_HEIGHT;
extern float txt_quality;

extern unsigned int textFB, textFBsample, textTexture;
extern unsigned int cft_state;
int CreateFrameText();

extern unsigned int uiFB, uiFBsample, uiFBdepth;
extern unsigned int cfu_state;
int CreateFrameUI();

// glyph struct fonts using uthash
typedef struct Size { int x, y, np2x, np2y; } Size;
typedef struct Bearing { int x, y; } Bearing;
typedef struct GCharacter {
    unsigned int ch;
    Size *Size;
    Bearing *Bearing;
    unsigned int Advance;
    unsigned int TextureID;
    UT_hash_handle hh; /* makes this structure hashable */
} GCharacter;
//{ ch: "a", Size: { x: 0, y: 0}, Bearing: { x: 0, y: 0}, Advance: 0, ..
void add_glyph(struct GCharacter *s);
struct GCharacter *find_glyph(int pair_id);
void delete_glyph(struct GCharacter *s);

typedef struct Color3 { float r, g, b; } Color3;
typedef struct Vector3 { float x, y, z; } Vector3;

typedef struct Sentences {
    unsigned int i;
    float pxW, pxH; // pixel size/pow2 size = uv size
    unsigned int np2w, np2h; // nearest power2 texture size
    unsigned int textureid;
    float lastupdate;
    int alignment;
    struct Transform *transform;
    UT_hash_handle hh; /* makes this structure hashable */
} Sentences;
void add_sts(struct Sentences *s);
struct Sentences *find_sts(int sts_id);
void delete_sts(struct Sentences *s);

typedef struct SentenceUpdates {
    unsigned int i;
    int alignment;
    struct Transform *transform;
    //char *text;
    int refresh; 
    UT_hash_handle hh; /* makes this structure hashable */
} SentenceUpdates;
void add_uts(struct SentenceUpdates *s);
struct SentenceUpdates *find_uts(int uts_id);
void delete_uts(struct SentenceUpdates *s);

extern float txtPreScale;
extern float txtLineHeight;
extern int spamonce;
extern unsigned int VAO, VBO;
extern unsigned int highestTidx;
extern int rerenderText;

struct Align {
    int bottomleft,topleft; // bottomleft default
    int bottomright,topright;
    int world;
    int center;
    int middleleft,middleright;
    int middletop,middlebottom;
};
extern const struct Align Align;

int UpdateText(unsigned int tidx, struct Vec3 *pos, struct Vec3 *rot, float scale, int align);

int RenderText(unsigned int tidx, struct Vec3 *pos, struct Vec3 *rot, float scale, int align, char* text);

int PrepareAllText();

int RenderAllText2D();

int RenderAllText3D();

int loadFont();
int cleanupFonts(int reload);

int InitializeText();

#endif
