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
50
51////////////////////////////////////////////////////////////////////////////////
52
54{
55 fX = 0;
56 fY = 0;
57 fZ = 0;
58 fAngle1 = 90;
59 fAngle2 = 0;
60 fAngle3 = 0;
61 fGLTextFont = 0;
62 SetGLTextFont(13); // Default font.
63}
64
65
66////////////////////////////////////////////////////////////////////////////////
67/// TGLext normal constructor.
68
69TGLText::TGLText(Double_t x, Double_t y, Double_t z, const char * /*text*/)
70{
71 fX = x;
72 fY = y;
73 fZ = z;
74 fAngle1 = 90;
75 fAngle2 = 0;
76 fAngle3 = 0;
77 fGLTextFont = 0;
78 SetGLTextFont(13); // Default font.
79}
80
81
82////////////////////////////////////////////////////////////////////////////////
83
85{
86 if (fGLTextFont) delete fGLTextFont;
87}
88
89
90////////////////////////////////////////////////////////////////////////////////
91/// Draw text
92
94{
95 if (!fGLTextFont) return;
96
98 glTranslatef(x, y, z);
99
101 Double_t s = GetTextSize();
102 glScalef(s,s,s);
103
104 // Text alignment
105 Float_t llx, lly, llz, urx, ury, urz;
106 fGLTextFont->BBox(text, llx, lly, llz, urx, ury, urz);
109 Float_t dx = 0, dy = 0;
110 switch (halign) {
111 case 1 : dx = 0 ; break;
112 case 2 : dx = -urx/2; break;
113 case 3 : dx = -urx ; break;
114 }
115 switch (valign) {
116 case 1 : dy = 0 ; break;
117 case 2 : dy = -ury/2; break;
118 case 3 : dy = -ury ; break;
119 }
120 glTranslatef(dx, dy, 0);
121
122 //In XY plane
123 glRotatef(fAngle1,1.,0.,0.);
124
125 //In XZ plane
126 glRotatef(fAngle2,0.,1.,0.);
127
128 //In YZ plane
129 glRotatef(fAngle3,0.,0.,1.);
130
131 // Render text
132 fGLTextFont->Render(text);
133
134 glPopMatrix();
135}
136
137
138////////////////////////////////////////////////////////////////////////////////
139
140void TGLText::PaintBBox(const char *text)
141{
142 Float_t llx, lly, llz, urx, ury, urz;
143 fGLTextFont->BBox(text, llx, lly, llz, urx, ury, urz);
144 glBegin(GL_LINES);
145 glVertex3f( 0, 0, 0); glVertex3f( urx, 0, 0);
146 glVertex3f( 0, 0, 0); glVertex3f( 0, ury, 0);
147 glVertex3f( 0, ury, 0); glVertex3f( urx, ury, 0);
148 glVertex3f( urx, ury, 0); glVertex3f( urx, 0, 0);
149 glEnd();
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Calculate bounding-box for given string.
154
155void TGLText::BBox(const char* string, float& llx, float& lly, float& llz,
156 float& urx, float& ury, float& urz)
157{
158 fGLTextFont->BBox(string, llx, lly, llz, urx, ury, urz);
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Set the text rotation angles.
163
170
171
172////////////////////////////////////////////////////////////////////////////////
173
175{
176 int fontid = fontnumber / 10;
177
178 const char *fontname=0;
179 if (fontid == 0) fontname = "arialbd.ttf";
180 if (fontid == 1) fontname = "timesi.ttf";
181 if (fontid == 2) fontname = "timesbd.ttf";
182 if (fontid == 3) fontname = "timesbi.ttf";
183 if (fontid == 4) fontname = "arial.ttf";
184 if (fontid == 5) fontname = "ariali.ttf";
185 if (fontid == 6) fontname = "arialbd.ttf";
186 if (fontid == 7) fontname = "arialbi.ttf";
187 if (fontid == 8) fontname = "cour.ttf";
188 if (fontid == 9) fontname = "couri.ttf";
189 if (fontid == 10) fontname = "courbd.ttf";
190 if (fontid == 11) fontname = "courbi.ttf";
191 if (fontid == 12) fontname = "symbol.ttf";
192 if (fontid == 13) fontname = "times.ttf";
193 if (fontid == 14) fontname = "wingding.ttf";
194
195 // try to load font (font must be in Root.TTFontPath resource)
196 const char *ttpath = gEnv->GetValue("Root.TTFontPath",
199
200 if (fGLTextFont) delete fGLTextFont;
201
202// fGLTextFont = new FTGLOutlineFont(ttfont);
203
205
206 if (!fGLTextFont->FaceSize(1))
207 Error("SetGLTextFont","Cannot set FTGL::FaceSize");
208 delete [] ttfont;
209}
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
short Font_t
Font number (short)
Definition RtypesCore.h:95
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:208
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:55
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:38
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:36
Short_t fTextAlign
Text alignment.
Definition TAttText.h:25
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:490
void PaintBBox(const char *text)
Definition TGLText.cxx:140
void SetGLTextAngles(Double_t a1, Double_t a2, Double_t a3)
Set the text rotation angles.
Definition TGLText.cxx:164
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:93
TGLText()
Definition TGLText.cxx:53
~TGLText() override
Definition TGLText.cxx:84
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:155
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:174
static void Color(const TGLColor &color)
Set color from TGLColor.
Definition TGLUtil.cxx:1688
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
Definition TROOT.cxx:3244
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1559
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17