void gl_draw_text(Scene_Camera* camera, Font* font, UChar* text, GLfloat size) { glBindVertexArray(font->quad->vao); glUseProgram(font->quad->shader->id); //TODO: this bugs out when I enable depth-testing due to z-fighting //on adjacent characters, I can probably fix it with blend mode? glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); gl_bind_texture(font->quad->shader->id, font->page->id, 0, "diffuse"); int32_t length = u_strlen(text); UChar32 character; for(int32_t i = 0; i < length; i++) { U16_GET_UNSAFE(text, i, character); gl_draw_font_glyph(camera, font, character, size); } glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glBindVertexArray(0); glUseProgram(0); }
static void TestGetChar() { static UChar input[]={ /* code unit,*/ 0xdc00, 0x20ac, 0xd841, 0x61, 0xd841, 0xdc02, 0xd842, 0xdc06, 0, 0xd842, 0xd7ff, 0xdc41, 0xe000, 0xd800 }; static UChar32 result[]={ /*codepoint-unsafe, codepoint-safe(not strict) codepoint-safe(strict)*/ (UChar32)0xfca10000, 0xdc00, UTF_ERROR_VALUE, 0x20ac, 0x20ac, 0x20ac, 0x12861, 0xd841, UTF_ERROR_VALUE, 0x61, 0x61, 0x61, 0x20402, 0x20402, 0x20402, 0x20402, 0x20402, 0x20402, 0x20806, 0x20806, 0x20806, 0x20806, 0x20806, 0x20806, 0x00, 0x00, 0x00, 0x203ff, 0xd842, UTF_ERROR_VALUE, 0xd7ff, 0xd7ff, 0xd7ff, 0xfc41, 0xdc41, UTF_ERROR_VALUE, 0xe000, 0xe000, 0xe000, 0x11734, 0xd800, UTF_ERROR_VALUE }; uint16_t i=0; UChar32 c; uint16_t offset=0; for(offset=0; offset<sizeof(input)/U_SIZEOF_UCHAR; offset++) { if(0<offset && offset<sizeof(input)/U_SIZEOF_UCHAR-1){ UTF16_GET_CHAR_UNSAFE(input, offset, c); if(c != result[i]){ log_err("ERROR: UTF16_GET_CHAR_UNSAFE failed for offset=%ld. Expected:%lx Got:%lx\n", offset, result[i], c); } U16_GET_UNSAFE(input, offset, c); if(c != result[i]){ log_err("ERROR: U16_GET_CHAR_UNSAFE failed for offset=%ld. Expected:%lx Got:%lx\n", offset, result[i], c); } } UTF16_GET_CHAR_SAFE(input, 0, offset, sizeof(input)/U_SIZEOF_UCHAR, c, FALSE); if(c != result[i+1]){ log_err("ERROR: UTF16_GET_CHAR_SAFE failed for offset=%ld. Expected:%lx Got:%lx\n", offset, result[i+1], c); } U16_GET(input, 0, offset, sizeof(input)/U_SIZEOF_UCHAR, c); if(c != result[i+1]){ log_err("ERROR: U16_GET failed for offset=%ld. Expected:%lx Got:%lx\n", offset, result[i+1], c); } UTF16_GET_CHAR_SAFE(input, 0, offset, sizeof(input)/U_SIZEOF_UCHAR, c, TRUE); if(c != result[i+2]){ log_err("ERROR: UTF16_GET_CHAR_SAFE(strict) failed for offset=%ld. Expected:%lx Got:%lx\n", offset, result[i+2], c); } i=(uint16_t)(i+3); } }