File: GLFont.h

package info (click to toggle)
limesuite 18.06.0+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 24,728 kB
  • sloc: cpp: 154,989; ansic: 6,823; python: 140; sh: 50; makefile: 32
file content (55 lines) | stat: -rw-r--r-- 1,459 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef GL_FONT_H
#define GL_FONT_H

#include <GL/glew.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include <string>
#include <vector>

struct GLGlyph
{
    GLGlyph() : id(-1), width(0), height(0), u(0), v(0), offset_x(0), offset_y(0), advance_x(0) {};
    void reset() { id = -1; width=0; height=0; u=0; v=0; offset_x=0, offset_y=0, advance_x=0; bitmap.clear();};
    std::vector<unsigned char> bitmap;
    unsigned short id;
    unsigned short width;
    unsigned short height;
    unsigned short u;
    unsigned short v;
    short offset_x;
    short offset_y;
    short advance_x;
};

class GLFont
{
public:
    GLFont();
    ~GLFont();

    bool load(const char* file);
    bool loadFromArray(const char* array, unsigned int size);
    void render_textWorldSpace(const char *text, float x, float y, float scale, unsigned int rgba = 0x00000000);
    void render_textScreenSpace(const char *text, float x, float y, float scale, unsigned int rgba = 0x00000000);

    unsigned int lineHeight() const;
    unsigned int char_width(const char c) const;
    unsigned int string_width(const char *str) const;
    void getTextSize(const char* str, int& width, int &height, float fontSize);

    unsigned int getTextureID() {return m_texID;};

    int m_texwidth;
    int m_texheight;
    GLuint m_texID;
    GLuint m_vboID;
    GLGlyph *m_glyphs;
    const unsigned short m_glyphCount;
    unsigned char m_fontSize;
};

#endif