Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLText.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Olivier Couet 12/04/2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2006, 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 "TROOT.h"
13#include "TError.h"
14
15#include "TGLText.h"
16#include "TGLUtil.h"
17#include "TSystem.h"
18#include "TEnv.h"
19#include "TGLIncludes.h"
20
21// Direct inclusion of FTGL headers is deprecated in ftgl-2.1.3 while
22// ftgl-2.1.2 shipped with ROOT requires manual inclusion.
23#ifndef BUILTIN_FTGL
24# include <FTGL/ftgl.h>
25#else
26# include "FTFont.h"
27# include "FTGLExtrdFont.h"
28# include "FTGLOutlineFont.h"
29# include "FTGLPolygonFont.h"
30# include "FTGLTextureFont.h"
31# include "FTGLPixmapFont.h"
32# include "FTGLBitmapFont.h"
33#endif
34
35#define FTGL_BITMAP 0
36#define FTGL_PIXMAP 1
37#define FTGL_OUTLINE 2
38#define FTGL_POLYGON 3
39#define FTGL_EXTRUDE 4
40#define FTGL_TEXTURE 5
41
42/** \class TGLText
43\ingroup opengl
44GL Text.
45
46To draw a 3D text in a GL window. This class uses uses FTGL to render text.
47FTGL is a package making the interface between the Free Type fonts and GL.
48*/
49
51
52////////////////////////////////////////////////////////////////////////////////
53
55{
56 fX = 0;
57 fY = 0;
58 fZ = 0;
59 fAngle1 = 90;
60 fAngle2 = 0;
61 fAngle3 = 0;
62 fGLTextFont = 0;
63 SetGLTextFont(13); // Default font.
64}
65
66
67////////////////////////////////////////////////////////////////////////////////
68/// TGLext normal constructor.
69
70TGLText::TGLText(Double_t x, Double_t y, Double_t z, const char * /*text*/)
71{
72 fX = x;
73 fY = y;
74 fZ = z;
75 fAngle1 = 90;
76 fAngle2 = 0;
77 fAngle3 = 0;
78 fGLTextFont = 0;
79 SetGLTextFont(13); // Default font.
80}
81
82
83////////////////////////////////////////////////////////////////////////////////
84
86{
87 if (fGLTextFont) delete fGLTextFont;
88}
89
90
91////////////////////////////////////////////////////////////////////////////////
92/// Draw text
93
95{
96 if (!fGLTextFont) return;
97
98 glPushMatrix();
99 glTranslatef(x, y, z);
100
102 Double_t s = GetTextSize();
103 glScalef(s,s,s);
104
105 // Text alignment
106 Float_t llx, lly, llz, urx, ury, urz;
107 fGLTextFont->BBox(text, llx, lly, llz, urx, ury, urz);
108 Short_t halign = fTextAlign/10;
109 Short_t valign = fTextAlign - 10*halign;
110 Float_t dx = 0, dy = 0;
111 switch (halign) {
112 case 1 : dx = 0 ; break;
113 case 2 : dx = -urx/2; break;
114 case 3 : dx = -urx ; break;
115 }
116 switch (valign) {
117 case 1 : dy = 0 ; break;
118 case 2 : dy = -ury/2; break;
119 case 3 : dy = -ury ; break;
120 }
121 glTranslatef(dx, dy, 0);
122
123 //In XY plane
124 glRotatef(fAngle1,1.,0.,0.);
125
126 //In XZ plane
127 glRotatef(fAngle2,0.,1.,0.);
128
129 //In YZ plane
130 glRotatef(fAngle3,0.,0.,1.);
131
132 // Render text
133 fGLTextFont->Render(text);
134
135 glPopMatrix();
136}
137
138
139////////////////////////////////////////////////////////////////////////////////
140
141void TGLText::PaintBBox(const char *text)
142{
143 Float_t llx, lly, llz, urx, ury, urz;
144 fGLTextFont->BBox(text, llx, lly, llz, urx, ury, urz);
145 glBegin(GL_LINES);
146 glVertex3f( 0, 0, 0); glVertex3f( urx, 0, 0);
147 glVertex3f( 0, 0, 0); glVertex3f( 0, ury, 0);
148 glVertex3f( 0, ury, 0); glVertex3f( urx, ury, 0);
149 glVertex3f( urx, ury, 0); glVertex3f( urx, 0, 0);
150 glEnd();
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Calculate bounding-box for given string.
155
156void TGLText::BBox(const char* string, float& llx, float& lly, float& llz,
157 float& urx, float& ury, float& urz)
158{
159 fGLTextFont->BBox(string, llx, lly, llz, urx, ury, urz);
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Set the text rotation angles.
164
166{
167 fAngle1 = a1;
168 fAngle2 = a2;
169 fAngle3 = a3;
170}
171
172
173////////////////////////////////////////////////////////////////////////////////
174
176{
177 int fontid = fontnumber / 10;
178
179 const char *fontname=0;
180 if (fontid == 0) fontname = "arialbd.ttf";
181 if (fontid == 1) fontname = "timesi.ttf";
182 if (fontid == 2) fontname = "timesbd.ttf";
183 if (fontid == 3) fontname = "timesbi.ttf";
184 if (fontid == 4) fontname = "arial.ttf";
185 if (fontid == 5) fontname = "ariali.ttf";
186 if (fontid == 6) fontname = "arialbd.ttf";
187 if (fontid == 7) fontname = "arialbi.ttf";
188 if (fontid == 8) fontname = "cour.ttf";
189 if (fontid == 9) fontname = "couri.ttf";
190 if (fontid == 10) fontname = "courbd.ttf";
191 if (fontid == 11) fontname = "courbi.ttf";
192 if (fontid == 12) fontname = "symbol.ttf";
193 if (fontid == 13) fontname = "times.ttf";
194 if (fontid == 14) fontname = "wingding.ttf";
195
196 // try to load font (font must be in Root.TTFontPath resource)
197 const char *ttpath = gEnv->GetValue("Root.TTFontPath",
199 char *ttfont = gSystem->Which(ttpath, fontname, kReadPermission);
200
201 if (fGLTextFont) delete fGLTextFont;
202
203// fGLTextFont = new FTGLOutlineFont(ttfont);
204
205 fGLTextFont = new FTGLPolygonFont(ttfont);
206
207 if (!fGLTextFont->FaceSize(1))
208 Error("SetGLTextFont","Cannot set FTGL::FaceSize");
209 delete [] ttfont;
210}
#define GL_LINES
Definition GL_glu.h:284
float Float_t
Definition RtypesCore.h:57
short Font_t
Definition RtypesCore.h:81
short Short_t
Definition RtypesCore.h:39
#define ClassImp(name)
Definition Rtypes.h:382
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
Option_t Option_t fontnumber
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char fontname
Option_t Option_t TPoint TPoint const char text
@ kReadPermission
Definition TSystem.h:45
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:36
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:34
Short_t fTextAlign
Text alignment.
Definition TAttText.h:23
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
GL Text.
Definition TGLText.h:19
void PaintBBox(const char *text)
Definition TGLText.cxx:141
void SetGLTextAngles(Double_t a1, Double_t a2, Double_t a3)
Set the text rotation angles.
Definition TGLText.cxx:165
Double_t fY
Definition TGLText.h:25
void PaintGLText(Double_t x, Double_t y, Double_t z, const char *text)
Draw text.
Definition TGLText.cxx:94
TGLText()
Definition TGLText.cxx:54
~TGLText() override
Definition TGLText.cxx:85
Double_t fAngle3
Definition TGLText.h:29
Double_t fZ
Definition TGLText.h:26
void BBox(const char *string, float &llx, float &lly, float &llz, float &urx, float &ury, float &urz)
Calculate bounding-box for given string.
Definition TGLText.cxx:156
Double_t fX
Definition TGLText.h:24
Double_t fAngle2
Definition TGLText.h:28
Double_t fAngle1
Definition TGLText.h:27
FTFont * fGLTextFont
Definition TGLText.h:30
void SetGLTextFont(Font_t fontnumber)
Definition TGLText.cxx:175
static void Color(const TGLColor &color)
Set color from TGLColor.
Definition TGLUtil.cxx:1697
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
Definition TROOT.cxx:3193
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1548
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17