24unsigned int glfonsRGBA(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
28#ifdef GLFONTSTASH_IMPLEMENTATION
34typedef struct GLFONScontext GLFONScontext;
36static int glfons__renderCreate(
void* userPtr,
int width,
int height)
38 GLFONScontext* gl = (GLFONScontext*)userPtr;
41 glDeleteTextures(1, &gl->tex);
44 glGenTextures(1, &gl->tex);
45 if (!gl->tex)
return 0;
48 glBindTexture(GL_TEXTURE_2D, gl->tex);
49 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, gl->width, gl->height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0);
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
54static int glfons__renderResize(
void* userPtr,
int width,
int height)
57 return glfons__renderCreate(userPtr, width, height);
60static void glfons__renderUpdate(
void* userPtr,
int* rect,
const unsigned char* data)
62 GLFONScontext* gl = (GLFONScontext*)userPtr;
63 int w = rect[2] - rect[0];
64 int h = rect[3] - rect[1];
66 if (gl->tex == 0)
return;
67 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
68 glBindTexture(GL_TEXTURE_2D, gl->tex);
69 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
70 glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->width);
71 glPixelStorei(GL_UNPACK_SKIP_PIXELS, rect[0]);
72 glPixelStorei(GL_UNPACK_SKIP_ROWS, rect[1]);
73 glTexSubImage2D(GL_TEXTURE_2D, 0, rect[0], rect[1], w, h, GL_ALPHA,GL_UNSIGNED_BYTE, data);
77static void glfons__renderDraw(
void* userPtr,
const float* verts,
const float* tcoords,
const unsigned int* colors,
int nverts)
79 GLFONScontext* gl = (GLFONScontext*)userPtr;
80 if (gl->tex == 0)
return;
81 glBindTexture(GL_TEXTURE_2D, gl->tex);
82 glEnable(GL_TEXTURE_2D);
83 glEnableClientState(GL_VERTEX_ARRAY);
84 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
85 glEnableClientState(GL_COLOR_ARRAY);
87 glVertexPointer(2, GL_FLOAT,
sizeof(
float)*2, verts);
88 glTexCoordPointer(2, GL_FLOAT,
sizeof(
float)*2, tcoords);
89 glColorPointer(4, GL_UNSIGNED_BYTE,
sizeof(
unsigned int), colors);
91 glDrawArrays(GL_TRIANGLES, 0, nverts);
93 glDisable(GL_TEXTURE_2D);
94 glDisableClientState(GL_VERTEX_ARRAY);
95 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
96 glDisableClientState(GL_COLOR_ARRAY);
99static void glfons__renderDelete(
void* userPtr)
101 GLFONScontext* gl = (GLFONScontext*)userPtr;
103 glDeleteTextures(1, &gl->tex);
114 gl = (GLFONScontext*)malloc(
sizeof(GLFONScontext));
115 if (gl == NULL)
goto error;
116 memset(gl, 0,
sizeof(GLFONScontext));
118 memset(¶ms, 0,
sizeof(params));
119 params.
width = width;
121 params.
flags = (
unsigned char)flags;
132 if (gl != NULL) free(gl);
141unsigned int glfonsRGBA(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a)
143 return (r) | (g << 8) | (b << 16) | (a << 24);
FONS_DEF void fonsDeleteInternal(FONScontext *s)
FONS_DEF FONScontext * fonsCreateInternal(FONSparams *params)
struct FONScontext FONScontext
FONScontext * glfonsCreate(int width, int height, int flags)
unsigned int glfonsRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void glfonsDelete(FONScontext *ctx)
@ error
throw a parse_error exception in case of a tag
int(* renderCreate)(void *uptr, int width, int height)
void(* renderDelete)(void *uptr)
int(* renderResize)(void *uptr, int width, int height)
void(* renderUpdate)(void *uptr, int *rect, const unsigned char *data)
void(* renderDraw)(void *uptr, const float *verts, const float *tcoords, const unsigned int *colors, int nverts)