void renderString(int x, int y, string glstring){ UnicodeChar c; int uc; int span = 0; double wid = pow(2, ceil(log2(32 * stretch))); wchar_t* wstr = nullptr; MBToWC(glstring.c_str(), wstr, glstring.length()+128); glEnable(GL_TEXTURE_2D); for (unsigned int k = 0; k < wstrlen(wstr); k++) { uc = wstr[k]; c = chars[uc]; if (uc == (int)'\n') { UITrans(0, 20); span = 0; continue; } if (!c.aval) { loadchar(uc); c = chars[uc]; } glBindTexture(GL_TEXTURE_2D, c.tex); UITrans(x + 1 + span, y + 1); glColor4f(0.5, 0.5, 0.5, a); glBegin(GL_QUADS); glTexCoord2d(0.0, 0.0); UIVertex(c.xpos / stretch, 15 - c.ypos / stretch); glTexCoord2d(c.width / wid, 0.0); UIVertex(c.xpos / stretch + c.width / stretch, 15- c.ypos / stretch); glTexCoord2d(c.width / wid, c.height / wid); UIVertex(c.xpos / stretch + c.width / stretch, 15 + c.height / stretch - c.ypos / stretch); glTexCoord2d(0.0, c.height / wid); UIVertex(c.xpos / stretch, 15 + c.height / stretch - c.ypos / stretch); glEnd(); UITrans(-1, -1); glColor4f(r, g, b, a); glBegin(GL_QUADS); glTexCoord2d(0.0, 0.0); UIVertex(c.xpos / stretch, 15 - c.ypos / stretch); glTexCoord2d(c.width / wid, 0.0); UIVertex(c.xpos / stretch + c.width / stretch, 15 - c.ypos / stretch); glTexCoord2d(c.width / wid, c.height / wid); UIVertex(c.xpos / stretch + c.width / stretch, 15 + c.height / stretch - c.ypos / stretch); glTexCoord2d(0.0, c.height / wid); UIVertex(c.xpos / stretch, 15 + c.height / stretch - c.ypos / stretch); glEnd(); UITrans(-x - span, -y); span += c.advance / stretch; } glColor4f(1.0, 1.0, 1.0, 1.0); free(wstr); }
int getStrWidth(string s){ UnicodeChar c; int uc, res = 0; wchar_t* wstr = nullptr; MBToWC(s.c_str(), wstr, s.length()+128); for (unsigned int k = 0; k < wstrlen(wstr); k++){ uc = wstr[k]; c = chars[uc]; if (!c.aval) { loadchar(uc); c = chars[uc]; } res += c.advance / stretch; } free(wstr); return res; }
int getStrWidth(string s){ int ret = 0; unsigned int i = 0; wchar_t* wstr = nullptr; MBToWC(s.c_str(), wstr, 128); for (unsigned int k = 0; k < wstrlen(wstr); k++){ if (s[i] >= 0 && s[i] <= 127){ i += 1; ret += 10; } else{ i += 2; ret += 16; } } free(wstr); return ret; }
void renderString(int x, int y, string glstring){ unsigned int i = 0; int uc; double tx, ty, span = 0; //Textures::TEXTURE_RGBA Tex; TextureID ftex; wchar_t* wstr = nullptr; MBToWC(glstring.c_str(), wstr, 128); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, ww, wh, 0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glEnable(GL_TEXTURE_2D); for (unsigned int k = 0; k < wstrlen(wstr); k++){ glLoadIdentity(); glColor4f(r, g, b, a); glTranslated(x + 1 + span, y + 1, 0); uc = wstr[k]; if (!useUnicodeASCIIFont && glstring[i]>=0 && glstring[i] <= 127){ glprint(x + 1 + (int)span, y + 1, string() + glstring[i]); } else{ if (!unicodeTexAval[uc / 256]) { //printf("[Console][Event]"); //printf("Loading unicode font texture #%d\n", uc / 256); std::stringstream ss; ss << "Textures\\Fonts\\unicode\\unicode_glyph_" << uc / 256 << ".bmp"; ftex = Textures::LoadFontTexture(ss.str()); unicodeTex[uc / 256] = ftex; unicodeTexAval[uc / 256] = true; } else{ ftex = unicodeTex[uc / 256]; } tx = ((uc % 256) % 16) / 16.0; ty = 1 - ((uc % 256) / 16) / 16.0; glBindTexture(GL_TEXTURE_2D, ftex); glBegin(GL_QUADS); glColor4f(0.5, 0.5, 0.5, a); glTexCoord2d(tx, ty); glVertex2i(1, 1); glTexCoord2d(tx + 0.0625, ty); glVertex2i(17, 1); glTexCoord2d(tx + 0.0625, ty - 0.0625); glVertex2i(17, 17); glTexCoord2d(tx, ty - 0.0625); glVertex2i(1, 17); glColor4f(r, g, b, a); glTexCoord2d(tx, ty); glVertex2i(0, 0); glTexCoord2d(tx + 0.0625, ty); glVertex2i(16, 0); glTexCoord2d(tx + 0.0625, ty - 0.0625); glVertex2i(16, 16); glTexCoord2d(tx, ty - 0.0625); glVertex2i(0, 16); glEnd(); } if (glstring[i] >= 0 && glstring[i] <= 127){ i += 1; span += 10; } else{ i += 2; span += 16; } } glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glColor4f(1.0, 1.0, 1.0, 1.0); free(wstr); }