forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveTextGL.cxx
156 lines (134 loc) · 5.02 KB
/
TEveTextGL.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// @(#)root/eve:$Id$
// Authors: Alja & Matevz Tadel 2008
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveTextGL.h"
#include "TEveText.h"
#include "TGLUtil.h"
#include "TGLCamera.h"
#include "TGLRnrCtx.h"
#include "TGLIncludes.h"
#include "TGLBoundingBox.h"
/** \class TEveTextGL
\ingroup TEve
OpenGL renderer class for TEveText.
*/
ClassImp(TEveTextGL);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveTextGL::TEveTextGL() :
TGLObject(),
fM(0),
fFont()
{
fDLCache = kFALSE; // Disable display list.
}
////////////////////////////////////////////////////////////////////////////////
/// Set model object.
Bool_t TEveTextGL::SetModel(TObject* obj, const Option_t* /*opt*/)
{
fM = SetModelDynCast<TEveText>(obj);
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Set bounding box.
void TEveTextGL::SetBBox()
{
fBoundingBox.SetEmpty();
}
////////////////////////////////////////////////////////////////////////////////
/// Actual rendering code.
/// Virtual from TGLLogicalShape.
void TEveTextGL::DirectDraw(TGLRnrCtx & rnrCtx) const
{
static const TEveException eH("TEveTextGL::DirectDraw ");
Int_t fm = fM->GetFontMode();
if (fm == TGLFont::kBitmap || fm == TGLFont::kPixmap || fm == TGLFont::kTexture)
rnrCtx.RegisterFont(fM->GetFontSize(), fM->GetFontFile(), fM->GetFontMode(), fFont);
else
rnrCtx.RegisterFontNoScale(fM->GetFontSize(), fM->GetFontFile(), fM->GetFontMode(), fFont);
fFont.SetDepth(fM->GetExtrude());
// bbox initialisation
if (fBoundingBox.IsEmpty() && fFont.GetMode() > TGLFont::kPixmap)
{
Float_t bbox[6];
fFont.BBox(fM->GetText(), bbox[0], bbox[1], bbox[2],
bbox[3], bbox[4], bbox[5]);
if (fFont.GetMode() == TGLFont::kExtrude) {
// Depth goes, the other z-way, swap.
Float_t tmp = bbox[2];
bbox[2] = bbox[5] * fM->GetExtrude();
bbox[5] = tmp * fM->GetExtrude();
} else {
bbox[2] = -0.005*(bbox[4] - bbox[1]);
bbox[5] = -0.005*(bbox[4] - bbox[1]);
}
TGLVertex3 low (bbox[0], bbox[1], bbox[2]);
TGLVertex3 high(bbox[3], bbox[4], bbox[5]);
TEveTextGL* ncthis = const_cast<TEveTextGL*>(this);
ncthis->fBoundingBox.SetAligned(low, high);
ncthis->UpdateBoundingBoxesOfPhysicals();
}
// rendering
glPushMatrix();
fFont.PreRender(fM->GetAutoLighting(), fM->GetLighting());
switch (fFont.GetMode())
{
case TGLFont::kBitmap:
case TGLFont::kPixmap:
if (rnrCtx.Selection()) {
// calculate 3D coordinates for picking
const GLdouble *pm = rnrCtx.RefCamera().RefLastNoPickProjM().CArr();
GLdouble mm[16];
GLint vp[4];
glGetDoublev(GL_MODELVIEW_MATRIX, mm);
glGetIntegerv(GL_VIEWPORT, vp);
fX[0][0] = fX[0][1] = fX[0][2] = 0;
GLdouble x, y, z;
gluProject(fX[0][0], fX[0][1], fX[0][2], mm, pm, vp, &x, &y, &z);
Float_t bbox[6];
fFont.BBox(fM->GetText(), bbox[0], bbox[1], bbox[2],
bbox[3], bbox[4], bbox[5]);
gluUnProject(x + bbox[0], y + bbox[1], z, mm, pm, vp, &fX[0][0], &fX[0][1], &fX[0][2]);
gluUnProject(x + bbox[3], y + bbox[1], z, mm, pm, vp, &fX[1][0], &fX[1][1], &fX[1][2]);
gluUnProject(x + bbox[3], y + bbox[4], z, mm, pm, vp, &fX[2][0], &fX[2][1], &fX[2][2]);
gluUnProject(x + bbox[0], y + bbox[4], z, mm, pm, vp, &fX[3][0], &fX[3][1], &fX[3][2]);
glBegin(GL_POLYGON);
glVertex3dv(fX[0]);
glVertex3dv(fX[1]);
glVertex3dv(fX[2]);
glVertex3dv(fX[3]);
glEnd();
} else {
glRasterPos3i(0, 0, 0);
fFont.Render(fM->GetText());
}
break;
case TGLFont::kOutline:
case TGLFont::kExtrude:
case TGLFont::kPolygon:
glPolygonOffset(fM->GetPolygonOffset(0), fM->GetPolygonOffset(1));
if (fM->GetExtrude() != 1.0) {
glPushMatrix();
glScalef(1.0f, 1.0f, fM->GetExtrude());
fFont.Render(fM->GetText());
glPopMatrix();
} else {
fFont.Render(fM->GetText());
}
break;
case TGLFont::kTexture:
glPolygonOffset(fM->GetPolygonOffset(0), fM->GetPolygonOffset(1));
fFont.Render(fM->GetText());
break;
default:
throw(eH + "unsupported FTGL-type.");
}
fFont.PostRender();
glPopMatrix();
}