MCPcopy Create free account
hub / github.com/android/ndk-samples / RenderHUD

Method RenderHUD

endless-tunnel/app/src/main/cpp/play_scene.cpp:605–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

603}
604
605void PlayScene::RenderHUD() {
606 float aspect = SceneManager::GetInstance()->GetScreenAspect();
607 glm::mat4 orthoMat = glm::ortho(0.0f, aspect, 0.0f, 1.0f);
608 glm::mat4 modelMat;
609 glm::mat4 mat;
610
611 glDisable(GL_DEPTH_TEST);
612
613 // render score digits
614 int i, unit;
615 static char score_str[6];
616 int score = GetScore();
617 for (i = 0, unit = 10000; i < 5; i++, unit /= 10) {
618 score_str[i] = '0' + (score / unit) % 10;
619 }
620 score_str[i] = '\0';
621
622 mTextRenderer->SetFontScale(SCORE_FONT_SCALE);
623 mTextRenderer->RenderText(score_str, SCORE_POS_X, SCORE_POS_Y);
624
625 // render current sign
626 if (mSignText) {
627 modelMat = glm::mat4(1.0f);
628 float t = Clock() - mSignStartTime;
629 if (t < SIGN_ANIM_DUR) {
630 float scale = t / SIGN_ANIM_DUR;
631 modelMat = glm::scale(modelMat, glm::vec3(1.0f, scale, 1.0f));
632 } else if (mSignTimeLeft < SIGN_ANIM_DUR) {
633 float scale = mSignTimeLeft / SIGN_ANIM_DUR;
634 modelMat = glm::scale(modelMat, glm::vec3(1.0f, scale, 1.0f));
635 }
636
637 mTextRenderer->SetMatrix(modelMat);
638 mTextRenderer->SetFontScale(SIGN_FONT_SCALE);
639 mTextRenderer->RenderText(mSignText, aspect * 0.5f, 0.5f);
640 mTextRenderer->ResetMatrix();
641 }
642
643 // render life icons
644 glLineWidth(LIFE_LINE_WIDTH);
645 float lifeX = LIFE_POS_X < 0.0f ? aspect + LIFE_POS_X : LIFE_POS_X;
646 modelMat = glm::translate(glm::mat4(1.0), glm::vec3(lifeX, LIFE_POS_Y, 0.0f));
647 modelMat = glm::scale(modelMat, glm::vec3(1.0f, LIFE_SCALE_Y, 1.0f));
648 int ubound = (mBlinkingHeart && BlinkFunc(0.2f)) ? mLives + 1 : mLives;
649 for (int i = 0; i < ubound; i++) {
650 mat = orthoMat * modelMat;
651 mTrivialShader->RenderSimpleGeom(&mat, mLifeGeom);
652 modelMat = glm::translate(modelMat, glm::vec3(LIFE_SPACING_X, 0.0f, 0.0f));
653 }
654
655 glEnable(GL_DEPTH_TEST);
656}
657
658void PlayScene::RenderMenu() {
659 float aspect = SceneManager::GetInstance()->GetScreenAspect();

Callers

nothing calls this directly

Calls 8

ClockFunction · 0.85
BlinkFuncFunction · 0.85
GetScreenAspectMethod · 0.80
RenderTextMethod · 0.80
SetMatrixMethod · 0.80
ResetMatrixMethod · 0.80
RenderSimpleGeomMethod · 0.80
SetFontScaleMethod · 0.45

Tested by

no test coverage detected