Logo ROOT   6.14/05
Reference Guide
TEveTextGL.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Alja & Matevz Tadel 2008
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TEveTextGL.h"
13 #include "TEveText.h"
14 #include "TGLUtil.h"
15 #include "TGLCamera.h"
16 
17 #include "TGLRnrCtx.h"
18 #include "TGLIncludes.h"
19 #include "TGLBoundingBox.h"
20 
21 /** \class TEveTextGL
22 \ingroup TEve
23 OpenGL renderer class for TEveText.
24 */
25 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Constructor.
30 
32  TGLObject(),
33  fM(0),
34  fFont()
35 {
36  fDLCache = kFALSE; // Disable display list.
37 }
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Set model object.
41 
43 {
44  fM = SetModelDynCast<TEveText>(obj);
45  return kTRUE;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Set bounding box.
50 
52 {
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Actual rendering code.
58 /// Virtual from TGLLogicalShape.
59 
60 void TEveTextGL::DirectDraw(TGLRnrCtx & rnrCtx) const
61 {
62  static const TEveException eH("TEveTextGL::DirectDraw ");
63 
64  Int_t fm = fM->GetFontMode();
65  if (fm == TGLFont::kBitmap || fm == TGLFont::kPixmap || fm == TGLFont::kTexture)
67  else
69 
71 
72  // bbox initialisation
74  {
75  Float_t bbox[6];
76  fFont.BBox(fM->GetText(), bbox[0], bbox[1], bbox[2],
77  bbox[3], bbox[4], bbox[5]);
78 
79  if (fFont.GetMode() == TGLFont::kExtrude) {
80  // Depth goes, the other z-way, swap.
81  Float_t tmp = bbox[2];
82  bbox[2] = bbox[5] * fM->GetExtrude();
83  bbox[5] = tmp * fM->GetExtrude();
84  } else {
85  bbox[2] = -0.005*(bbox[4] - bbox[1]);
86  bbox[5] = -0.005*(bbox[4] - bbox[1]);
87  }
88 
89  TGLVertex3 low (bbox[0], bbox[1], bbox[2]);
90  TGLVertex3 high(bbox[3], bbox[4], bbox[5]);
91 
92  TEveTextGL* ncthis = const_cast<TEveTextGL*>(this);
93  ncthis->fBoundingBox.SetAligned(low, high);
95  }
96 
97  // rendering
98  glPushMatrix();
100  switch (fFont.GetMode())
101  {
102  case TGLFont::kBitmap:
103  case TGLFont::kPixmap:
104  if (rnrCtx.Selection()) {
105  // calculate 3D coordinates for picking
106  const GLdouble *pm = rnrCtx.RefCamera().RefLastNoPickProjM().CArr();
107  GLdouble mm[16];
108  GLint vp[4];
109  glGetDoublev(GL_MODELVIEW_MATRIX, mm);
110  glGetIntegerv(GL_VIEWPORT, vp);
111 
112  fX[0][0] = fX[0][1] = fX[0][2] = 0;
113  GLdouble x, y, z;
114  gluProject(fX[0][0], fX[0][1], fX[0][2], mm, pm, vp, &x, &y, &z);
115  Float_t bbox[6];
116  fFont.BBox(fM->GetText(), bbox[0], bbox[1], bbox[2],
117  bbox[3], bbox[4], bbox[5]);
118  gluUnProject(x + bbox[0], y + bbox[1], z, mm, pm, vp, &fX[0][0], &fX[0][1], &fX[0][2]);
119  gluUnProject(x + bbox[3], y + bbox[1], z, mm, pm, vp, &fX[1][0], &fX[1][1], &fX[1][2]);
120  gluUnProject(x + bbox[3], y + bbox[4], z, mm, pm, vp, &fX[2][0], &fX[2][1], &fX[2][2]);
121  gluUnProject(x + bbox[0], y + bbox[4], z, mm, pm, vp, &fX[3][0], &fX[3][1], &fX[3][2]);
122 
123  glBegin(GL_POLYGON);
124  glVertex3dv(fX[0]);
125  glVertex3dv(fX[1]);
126  glVertex3dv(fX[2]);
127  glVertex3dv(fX[3]);
128  glEnd();
129  } else {
130  glRasterPos3i(0, 0, 0);
131  fFont.Render(fM->GetText());
132  }
133  break;
134  case TGLFont::kOutline:
135  case TGLFont::kExtrude:
136  case TGLFont::kPolygon:
137  glPolygonOffset(fM->GetPolygonOffset(0), fM->GetPolygonOffset(1));
138  if (fM->GetExtrude() != 1.0) {
139  glPushMatrix();
140  glScalef(1.0f, 1.0f, fM->GetExtrude());
141  fFont.Render(fM->GetText());
142  glPopMatrix();
143  } else {
144  fFont.Render(fM->GetText());
145  }
146  break;
147  case TGLFont::kTexture:
148  glPolygonOffset(fM->GetPolygonOffset(0), fM->GetPolygonOffset(1));
149  fFont.Render(fM->GetText());
150  break;
151  default:
152  throw(eH + "unsupported FTGL-type.");
153  }
154  fFont.PostRender();
155  glPopMatrix();
156 }
Int_t GetFontFile() const
Definition: TEveText.h:50
OpenGL renderer class for TEveText.
Definition: TEveTextGL.h:20
void SetAligned(const TGLVertex3 &lowVertex, const TGLVertex3 &highVertex)
Set ALIGNED box from two low/high vertices.
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:40
virtual void PreRender(Bool_t autoLight=kTRUE, Bool_t lightOn=kFALSE) const
Set-up GL state before FTFont rendering.
void Render(const char *txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
Bool_t Selection() const
Definition: TGLRnrCtx.h:222
void UpdateBoundingBoxesOfPhysicals()
Update bounding-boxed of all dependent physicals.
void BBox(const char *txt, Float_t &llx, Float_t &lly, Float_t &llz, Float_t &urx, Float_t &ury, Float_t &urz) const
Get bounding box.
EMode GetMode() const
virtual void DirectDraw(TGLRnrCtx &rnrCtx) const
Actual rendering code.
Definition: TEveTextGL.cxx:60
TGLCamera & RefCamera()
Definition: TGLRnrCtx.h:157
Float_t GetExtrude() const
Definition: TEveText.h:66
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void RegisterFontNoScale(Int_t size, Int_t file, Int_t mode, TGLFont &out)
Get font in the GL rendering context.
Definition: TGLRnrCtx.cxx:367
static constexpr double mm
Bool_t IsEmpty() const
Double_t x[n]
Definition: legend1.C:17
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:82
const char * GetText() const
Definition: TEveText.h:57
Base-class for direct OpenGL renderers.
Definition: TGLObject.h:21
TEveText * fM
Definition: TEveTextGL.h:27
void RegisterFont(Int_t size, Int_t file, Int_t mode, TGLFont &out)
Get font in the GL rendering context.
Definition: TGLRnrCtx.cxx:384
TGLFont fFont
Definition: TEveTextGL.h:28
Int_t GetFontMode() const
Definition: TEveText.h:51
virtual Bool_t SetModel(TObject *obj, const Option_t *opt=0)
Set model object.
Definition: TEveTextGL.cxx:42
const Double_t * CArr() const
Definition: TGLUtil.h:663
Float_t GetPolygonOffset(Int_t i) const
Definition: TEveText.h:69
const Bool_t kFALSE
Definition: RtypesCore.h:88
Bool_t GetLighting() const
Definition: TEveText.h:60
#define ClassImp(name)
Definition: Rtypes.h:359
void SetEmpty()
Set bounding box empty - all vertices at (0,0,0)
virtual void SetBBox()
Set bounding box.
Definition: TEveTextGL.cxx:51
Double_t y[n]
Definition: legend1.C:17
Mother of all ROOT objects.
Definition: TObject.h:37
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
virtual void PostRender() const
Reset GL state after FTFont rendering.
Exception class thrown by TEve classes and macros.
Definition: TEveUtil.h:102
TGLBoundingBox fBoundingBox
Also plays the role of ID.
Bool_t fDLCache
display-list validity bit-field
Double_t fX[4][3]
Definition: TEveTextGL.h:29
TGLMatrix & RefLastNoPickProjM() const
Definition: TGLCamera.h:174
const Bool_t kTRUE
Definition: RtypesCore.h:87
void SetDepth(Float_t d)
TEveTextGL()
Constructor.
Definition: TEveTextGL.cxx:31
Bool_t GetAutoLighting() const
Definition: TEveText.h:63
Int_t GetFontSize() const
Definition: TEveText.h:49