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// since Apr 29, 2008: https://github.com/ulrichard/ftgl/commit/c96146ed441d2442eaf2d78a9d46f37fce332fe8
22#if __has_include(<FTGL/ftgl.h>)
23# include <FTGL/ftgl.h>
24#else
25# include "FTFont.h"
26# include "FTGLExtrdFont.h"
27# include "FTGLOutlineFont.h"
28# include "FTGLPolygonFont.h"
29# include "FTGLTextureFont.h"
30# include "FTGLPixmapFont.h"
31# include "FTGLBitmapFont.h"
32#endif
33
34#define FTGL_BITMAP 0
35#define FTGL_PIXMAP 1
36#define FTGL_OUTLINE 2
37#define FTGL_POLYGON 3
38#define FTGL_EXTRUDE 4
39#define FTGL_TEXTURE 5
40
41/** \class TGLText
42\ingroup opengl
43GL Text.
44
45To draw a 3D text in a GL window. This class uses uses FTGL to render text.
46FTGL is a package making the interface between the Free Type fonts and GL.
47*/
48
49
50////////////////////////////////////////////////////////////////////////////////
51
53{
54 fX = 0;
55 fY = 0;
56 fZ = 0;
57 fAngle1 = 90;
58 fAngle2 = 0;
59 fAngle3 = 0;
60 fGLTextFont = 0;
61 SetGLTextFont(13); // Default font.
62}
63
64
65////////////////////////////////////////////////////////////////////////////////
66/// TGLext normal constructor.
67
68TGLText::TGLText(Double_t x, Double_t y, Double_t z, const char * /*text*/)
69{
70 fX = x;
71 fY = y;
72 fZ = z;
73 fAngle1 = 90;
74 fAngle2 = 0;
75 fAngle3 = 0;
76 fGLTextFont = 0;
77 SetGLTextFont(13); // Default font.
78}
79
80
81////////////////////////////////////////////////////////////////////////////////
82
84{
85 if (fGLTextFont) delete fGLTextFont;
86}
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Draw text
91
93{
94 if (!fGLTextFont) return;
95
96 glPushMatrix();
97 glTranslatef(x, y, z);
98
100 Double_t s = GetTextSize();
101 glScalef(s,s,s);
102
103 // Text alignment
104 Float_t llx, lly, llz, urx, ury, urz;
105 fGLTextFont->BBox(text, llx, lly, llz, urx, ury, urz);
106 Short_t halign = fTextAlign/10;
107 Short_t valign = fTextAlign - 10*halign;
108 Float_t dx = 0, dy = 0;
109 switch (halign) {
110 case 1 : dx = 0 ; break;
111 case 2 : dx = -urx/2; break;
112 case 3 : dx = -urx ; break;
113 }
114 switch (valign) {
115 case 1 : dy = 0 ; break;
116 case 2 : dy = -ury/2; break;
117 case 3 : dy = -ury ; break;
118 }
119 glTranslatef(dx, dy, 0);
120
121 //In XY plane
122 glRotatef(fAngle1,1.,0.,0.);
123
124 //In XZ plane
125 glRotatef(fAngle2,0.,1.,0.);
126
127 //In YZ plane
128 glRotatef(fAngle3,0.,0.,1.);
129
130 // Render text
131 fGLTextFont->Render(text);
132
133 glPopMatrix();
134}
135
136
137////////////////////////////////////////////////////////////////////////////////
138
139void TGLText::PaintBBox(const char *text)
140{
141 Float_t llx, lly, llz, urx, ury, urz;
142 fGLTextFont->BBox(text, llx, lly, llz, urx, ury, urz);
143 glBegin(GL_LINES);
144 glVertex3f( 0, 0, 0); glVertex3f( urx, 0, 0);
145 glVertex3f( 0, 0, 0); glVertex3f( 0, ury, 0);
146 glVertex3f( 0, ury, 0); glVertex3f( urx, ury, 0);
147 glVertex3f( urx, ury, 0); glVertex3f( urx, 0, 0);
148 glEnd();
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Calculate bounding-box for given string.
153
154void TGLText::BBox(const char* string, float& llx, float& lly, float& llz,
155 float& urx, float& ury, float& urz)
156{
157 fGLTextFont->BBox(string, llx, lly, llz, urx, ury, urz);
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Set the text rotation angles.
162
164{
165 fAngle1 = a1;
166 fAngle2 = a2;
167 fAngle3 = a3;
168}
169
170
171////////////////////////////////////////////////////////////////////////////////
172
174{
175 int fontid = fontnumber / 10;
176
177 const char *fontname=0;
178 if (fontid == 0) fontname = "arialbd.ttf";
179 if (fontid == 1) fontname = "timesi.ttf";
180 if (fontid == 2) fontname = "timesbd.ttf";
181 if (fontid == 3) fontname = "timesbi.ttf";
182 if (fontid == 4) fontname = "arial.ttf";
183 if (fontid == 5) fontname = "ariali.ttf";
184 if (fontid == 6) fontname = "arialbd.ttf";
185 if (fontid == 7) fontname = "arialbi.ttf";
186 if (fontid == 8) fontname = "cour.ttf";
187 if (fontid == 9) fontname = "couri.ttf";
188 if (fontid == 10) fontname = "courbd.ttf";
189 if (fontid == 11) fontname = "courbi.ttf";
190 if (fontid == 12) fontname = "symbol.ttf";
191 if (fontid == 13) fontname = "times.ttf";
192 if (fontid == 14) fontname = "wingding.ttf";
193
194 // try to load font (font must be in Root.TTFontPath resource)
195 const char *ttpath = gEnv->GetValue("Root.TTFontPath",
196 TROOT::GetTTFFontDir());
197 char *ttfont = gSystem->Which(ttpath, fontname, kReadPermission);
198
199 if (fGLTextFont) delete fGLTextFont;
200
201// fGLTextFont = new FTGLOutlineFont(ttfont);
202
203 fGLTextFont = new FTGLPolygonFont(ttfont);
204
205 if (!fGLTextFont->FaceSize(1))
206 Error("SetGLTextFont","Cannot set FTGL::FaceSize");
207 delete [] ttfont;
208}
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
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
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:582
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:39
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:37
Short_t fTextAlign
Text alignment.
Definition TAttText.h:26
void PaintBBox(const char *text)
Definition TGLText.cxx:139
void SetGLTextAngles(Double_t a1, Double_t a2, Double_t a3)
Set the text rotation angles.
Definition TGLText.cxx:163
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:92
TGLText()
Definition TGLText.cxx:52
~TGLText() override
Definition TGLText.cxx:83
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:154
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:173
static void Color(const TGLColor &color)
Set color from TGLColor.
Definition TGLUtil.cxx:1688
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17