| 406 | } |
| 407 | |
| 408 | void font_impl::render(int pWindowId, |
| 409 | const float pPos[], const float pColor[], const char* pText, |
| 410 | size_t pFontSize, bool pIsVertical) |
| 411 | { |
| 412 | static const glm::mat4 I(1); |
| 413 | |
| 414 | CheckGL("Begin font_impl::render "); |
| 415 | if(!mIsFontLoaded) { |
| 416 | return; |
| 417 | } |
| 418 | |
| 419 | glDepthMask(GL_FALSE); |
| 420 | glDepthFunc(GL_ALWAYS); |
| 421 | glEnable(GL_BLEND); |
| 422 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 423 | mProgram.bind(); |
| 424 | |
| 425 | glUniformMatrix4fv(mPMatIndex, 1, GL_FALSE, (GLfloat*)&mProjMat); |
| 426 | glUniform4fv(mClrIndex, 1, pColor); |
| 427 | |
| 428 | glActiveTexture(GL_TEXTURE0); |
| 429 | glBindTexture(GL_TEXTURE_2D, mAtlas->atlasTextureId()); |
| 430 | glUniform1i(mTexIndex, 0); |
| 431 | |
| 432 | bindResources(pWindowId); |
| 433 | |
| 434 | float loc_x = pPos[0]; |
| 435 | float loc_y = pPos[1]; |
| 436 | |
| 437 | if (pFontSize<MIN_FONT_SIZE) { |
| 438 | pFontSize = size_t(MIN_FONT_SIZE); |
| 439 | } |
| 440 | else if (pFontSize>MAX_FONT_SIZE) { |
| 441 | pFontSize = size_t(MAX_FONT_SIZE); |
| 442 | } |
| 443 | |
| 444 | glm::mat4 R = (pIsVertical ? glm::rotate(I, glm::radians(90.f), glm::vec3(0,0,1)) : I); |
| 445 | |
| 446 | auto& glyphList = mGlyphLists[pFontSize - size_t(MIN_FONT_SIZE)]; |
| 447 | |
| 448 | for (size_t i=0; i<std::strlen(pText); ++i) |
| 449 | { |
| 450 | int ccode = pText[i]; |
| 451 | |
| 452 | if (ccode>=START_CHAR && ccode<=END_CHAR) { |
| 453 | |
| 454 | int idx = ccode - START_CHAR; |
| 455 | |
| 456 | Glyph* g = glyphList[idx]; |
| 457 | |
| 458 | if (!pIsVertical) |
| 459 | loc_x += g->mBearingX; |
| 460 | |
| 461 | glm::mat4 TR = glm::translate(I, glm::vec3(loc_x, loc_y, 0.0f)) * R; |
| 462 | |
| 463 | glUniformMatrix4fv(mMMatIndex, 1, GL_FALSE, (GLfloat*)&TR); |
| 464 | |
| 465 | glDrawArrays(GL_TRIANGLE_STRIP, gl::GLint(g->mOffset), 4); |
no test coverage detected