GLSL_PREFIX = """ #ifndef INC_{0} #define INC_{0} """.strip() GLSL_FUNCTIONS = """ bool {0}(vec2 pos, int code) {{ if (pos.x < .0 || pos.y < .0 || pos.x >= 1. || pos.y >= 1. || code < 0 || code >= {1}_COUNT) {{ return false; }} ivec2 pos2 = ivec2(pos.x * 8., (1 - pos.y) * 8.); ivec2 subpos = pos2 % 4; int v = int(pow(2., subpos.y * 4. + subpos.x)); int d = int(pos2.y * .25) * 2 + int(pos2.x * .25); return ({0}_glyphs[code * 4 + d] & v) > 0; }} float {0}_at(vec2 uv, vec2 pos, int code) {{ return {0}(uv - pos, code) ? 1. : 0.; }} """.strip() GLSL_SET_FUNCTIONS = """ int {0}_set_glyph(int set, float v) {{ if (v < .0 || v >= 1. || set < 0. || set >= {1}_SETS) {{ return 0; }} return {0}_sets[set * 2] + int(v * {0}_sets[set * 2 + 1]); }} """.strip() GLSL_SUFFIX = """ #endif /* INC_{0} */ """.strip() GLSL_SENTENCES_PREFIX = """ #ifndef INC_{0}_SENTENCES #define INC_{0}_SENTENCES """.strip() GLSL_SENTENCES_FUNCTIONS = """ float {0}_sentence(vec2 uv, vec2 pos, int n) {{ float d = 0.; int i; if (n < .0 || n > {1}_SENTENCE_COUNT) {{ return d; }} for (i = 0; i < {0}_sentences_lengths[n]; i++) {{ d += {0}_at(uv, pos + vec2(i, 0.), {0}_sentences[n * {1}_SENTENCE_MAX_LEN + i]); }} return d; }} """.strip() GLSL_SENTENCES_SUFFIX = """ #endif /* INC_{0}_SENTENCES */ """.strip()