PageRenderTime 152ms CodeModel.GetById 32ms RepoModel.GetById 3ms app.codeStats 0ms

/indra/newview/llhudrender.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 149 lines | 102 code | 19 blank | 28 comment | 6 complexity | 6aeca5b387804bf4f4303c2039111abb MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llhudrender.cpp
  3. * @brief LLHUDRender class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llhudrender.h"
  28. #include "llrender.h"
  29. #include "llgl.h"
  30. #include "llviewercamera.h"
  31. #include "v3math.h"
  32. #include "llquaternion.h"
  33. #include "llfontgl.h"
  34. #include "llglheaders.h"
  35. #include "llviewerwindow.h"
  36. #include "llui.h"
  37. void hud_render_utf8text(const std::string &str, const LLVector3 &pos_agent,
  38. const LLFontGL &font,
  39. const U8 style,
  40. const LLFontGL::ShadowType shadow,
  41. const F32 x_offset, const F32 y_offset,
  42. const LLColor4& color,
  43. const BOOL orthographic)
  44. {
  45. LLWString wstr(utf8str_to_wstring(str));
  46. hud_render_text(wstr, pos_agent, font, style, shadow, x_offset, y_offset, color, orthographic);
  47. }
  48. void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent,
  49. const LLFontGL &font,
  50. const U8 style,
  51. const LLFontGL::ShadowType shadow,
  52. const F32 x_offset, const F32 y_offset,
  53. const LLColor4& color,
  54. const BOOL orthographic)
  55. {
  56. LLViewerCamera* camera = LLViewerCamera::getInstance();
  57. // Do cheap plane culling
  58. LLVector3 dir_vec = pos_agent - camera->getOrigin();
  59. dir_vec /= dir_vec.magVec();
  60. if (wstr.empty() || (!orthographic && dir_vec * camera->getAtAxis() <= 0.f))
  61. {
  62. return;
  63. }
  64. LLVector3 right_axis;
  65. LLVector3 up_axis;
  66. if (orthographic)
  67. {
  68. right_axis.setVec(0.f, -1.f / gViewerWindow->getWorldViewHeightScaled(), 0.f);
  69. up_axis.setVec(0.f, 0.f, 1.f / gViewerWindow->getWorldViewHeightScaled());
  70. }
  71. else
  72. {
  73. camera->getPixelVectors(pos_agent, up_axis, right_axis);
  74. }
  75. LLCoordFrame render_frame = *camera;
  76. LLQuaternion rot;
  77. if (!orthographic)
  78. {
  79. rot = render_frame.getQuaternion();
  80. rot = rot * LLQuaternion(-F_PI_BY_TWO, camera->getYAxis());
  81. rot = rot * LLQuaternion(F_PI_BY_TWO, camera->getXAxis());
  82. }
  83. else
  84. {
  85. rot = LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 0.f, 1.f));
  86. rot = rot * LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 1.f, 0.f));
  87. }
  88. F32 angle;
  89. LLVector3 axis;
  90. rot.getAngleAxis(&angle, axis);
  91. LLVector3 render_pos = pos_agent + (floorf(x_offset) * right_axis) + (floorf(y_offset) * up_axis);
  92. //get the render_pos in screen space
  93. F64 winX, winY, winZ;
  94. LLRect world_view_rect = gViewerWindow->getWorldViewRectRaw();
  95. S32 viewport[4];
  96. viewport[0] = world_view_rect.mLeft;
  97. viewport[1] = world_view_rect.mBottom;
  98. viewport[2] = world_view_rect.getWidth();
  99. viewport[3] = world_view_rect.getHeight();
  100. F64 mdlv[16];
  101. F64 proj[16];
  102. for (U32 i = 0; i < 16; i++)
  103. {
  104. mdlv[i] = (F64) gGLModelView[i];
  105. proj[i] = (F64) gGLProjection[i];
  106. }
  107. gluProject(render_pos.mV[0], render_pos.mV[1], render_pos.mV[2],
  108. mdlv, proj, (GLint*) viewport,
  109. &winX, &winY, &winZ);
  110. //fonts all render orthographically, set up projection``
  111. gGL.matrixMode(LLRender::MM_PROJECTION);
  112. gGL.pushMatrix();
  113. gGL.matrixMode(LLRender::MM_MODELVIEW);
  114. gGL.pushMatrix();
  115. LLUI::pushMatrix();
  116. gl_state_for_2d(world_view_rect.getWidth(), world_view_rect.getHeight());
  117. gViewerWindow->setup3DViewport();
  118. winX -= world_view_rect.mLeft;
  119. winY -= world_view_rect.mBottom;
  120. LLUI::loadIdentity();
  121. gGL.loadIdentity();
  122. LLUI::translate((F32) winX*1.0f/LLFontGL::sScaleX, (F32) winY*1.0f/(LLFontGL::sScaleY), -(((F32) winZ*2.f)-1.f));
  123. F32 right_x;
  124. font.render(wstr, 0, 0, 0, color, LLFontGL::LEFT, LLFontGL::BASELINE, style, shadow, wstr.length(), 1000, &right_x);
  125. LLUI::popMatrix();
  126. gGL.popMatrix();
  127. gGL.matrixMode(LLRender::MM_PROJECTION);
  128. gGL.popMatrix();
  129. gGL.matrixMode(LLRender::MM_MODELVIEW);
  130. }