00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llhudrender.h"
00035
00036 #include "llgl.h"
00037 #include "llviewercamera.h"
00038 #include "v3math.h"
00039 #include "llquaternion.h"
00040 #include "llfontgl.h"
00041 #include "llimagegl.h"
00042 #include "llglheaders.h"
00043 #include "llviewerwindow.h"
00044
00045 void hud_render_utf8text(const std::string &str, const LLVector3 &pos_agent,
00046 const LLFontGL &font,
00047 const U8 style,
00048 const F32 x_offset, const F32 y_offset,
00049 const LLColor4& color,
00050 const BOOL orthographic)
00051 {
00052 LLWString wstr(utf8str_to_wstring(str));
00053 hud_render_text(wstr, pos_agent, font, style, x_offset, y_offset, color, orthographic);
00054 }
00055
00056 void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent,
00057 const LLFontGL &font,
00058 const U8 style,
00059 const F32 x_offset, const F32 y_offset,
00060 const LLColor4& color,
00061 const BOOL orthographic)
00062 {
00063
00064 LLVector3 dir_vec = pos_agent - gCamera->getOrigin();
00065 dir_vec /= dir_vec.magVec();
00066
00067 if (wstr.empty() || (!orthographic && dir_vec * gCamera->getAtAxis() <= 0.f))
00068 {
00069 return;
00070 }
00071
00072 LLVector3 right_axis;
00073 LLVector3 up_axis;
00074 if (orthographic)
00075 {
00076 right_axis.setVec(0.f, -1.f / gViewerWindow->getWindowHeight(), 0.f);
00077 up_axis.setVec(0.f, 0.f, 1.f / gViewerWindow->getWindowHeight());
00078 }
00079 else
00080 {
00081 gCamera->getPixelVectors(pos_agent, up_axis, right_axis);
00082 }
00083 LLCoordFrame render_frame = *gCamera;
00084 LLQuaternion rot;
00085 if (!orthographic)
00086 {
00087 rot = render_frame.getQuaternion();
00088 rot = rot * LLQuaternion(-F_PI_BY_TWO, gCamera->getYAxis());
00089 rot = rot * LLQuaternion(F_PI_BY_TWO, gCamera->getXAxis());
00090 }
00091 else
00092 {
00093 rot = LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 0.f, 1.f));
00094 rot = rot * LLQuaternion(-F_PI_BY_TWO, LLVector3(0.f, 1.f, 0.f));
00095 }
00096 F32 angle;
00097 LLVector3 axis;
00098 rot.getAngleAxis(&angle, axis);
00099
00100 LLVector3 render_pos = pos_agent + (floorf(x_offset) * right_axis) + (floorf(y_offset) * up_axis);
00101
00102
00103 F64 modelview[16];
00104 F64 projection[16];
00105 GLint viewport[4];
00106 glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
00107 glGetDoublev(GL_PROJECTION_MATRIX, projection);
00108 glGetIntegerv(GL_VIEWPORT, viewport);
00109
00110 F64 winX, winY, winZ;
00111 gluProject(render_pos.mV[0], render_pos.mV[1], render_pos.mV[2],
00112 modelview, projection, viewport,
00113 &winX, &winY, &winZ);
00114
00115
00116 glMatrixMode(GL_PROJECTION);
00117 glPushMatrix();
00118 glMatrixMode(GL_MODELVIEW);
00119
00120 LLUI::pushMatrix();
00121
00122 gViewerWindow->setup2DRender();
00123
00124 LLUI::loadIdentity();
00125 LLUI::translate((F32) winX*1.0f/LLFontGL::sScaleX, (F32) winY*1.0f/(LLFontGL::sScaleY), -(((F32) winZ*2.f)-1.f));
00126
00127
00128 F32 right_x;
00129
00130 font.render(wstr, 0, 0, 0, color, LLFontGL::LEFT, LLFontGL::BASELINE, style, wstr.length(), 1000, &right_x);
00131 LLUI::popMatrix();
00132
00133 glMatrixMode(GL_PROJECTION);
00134 glPopMatrix();
00135 glMatrixMode(GL_MODELVIEW);
00136 }