Logo ROOT   6.12/07
Reference Guide
TEveFrameBoxGL.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
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 "TEveFrameBoxGL.h"
13 #include "TEveFrameBox.h"
14 
15 #include "TGLIncludes.h"
16 #include "TGLUtil.h"
17 
18 #include "TMath.h"
19 
20 /** \class TEveFrameBoxGL
21 \ingroup TEve
22 A class encapsulating GL rendering of TEveFrameBox via a static member function.
23 */
24 
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// Render the frame with GL.
29 
31 {
32  const Float_t * p = b.fFramePoints;
33  Float_t normal[3];
34 
36  {
37  if (fillp)
38  {
39  TMath::Normal2Plane(p, p+3, p+6, normal);
40  glNormal3fv(normal);
41  glBegin(GL_POLYGON);
42  }
43  else
44  {
45  glBegin(GL_LINE_LOOP);
46  }
47  Int_t nPoints = b.fFrameSize / 3;
48  for (Int_t i = 0; i < nPoints; ++i, p += 3)
49  glVertex3fv(p);
50  glEnd();
51  }
52  else if (b.fFrameType == TEveFrameBox::kFT_Box)
53  {
54  if (fillp)
55  {
56  glBegin(GL_QUADS);
57  TMath::Normal2Plane(p, p+3, p+6, normal);
58  glNormal3fv(normal);
59  glVertex3fv(p); glVertex3fv(p + 3);
60  glVertex3fv(p + 6); glVertex3fv(p + 9);
61  // top: 7654
62  TMath::Normal2Plane(p+21, p+18, p+15, normal);
63  glNormal3fv(normal);
64  glVertex3fv(p + 21); glVertex3fv(p + 18);
65  glVertex3fv(p + 15); glVertex3fv(p + 12);
66  // back: 0451
67  TMath::Normal2Plane(p, p+12, p+15, normal);
68  glNormal3fv(normal);
69  glVertex3fv(p); glVertex3fv(p + 12);
70  glVertex3fv(p + 15); glVertex3fv(p + 3);
71  // front: 3267
72  TMath::Normal2Plane(p+9, p+6, p+18, normal);
73  glNormal3fv(normal);
74  glVertex3fv(p + 9); glVertex3fv(p + 6);
75  glVertex3fv(p + 18); glVertex3fv(p + 21);
76  // left: 0374
77  TMath::Normal2Plane(p, p+9, p+21, normal);
78  glNormal3fv(normal);
79  glVertex3fv(p); glVertex3fv(p + 9);
80  glVertex3fv(p + 21); glVertex3fv(p + 12);
81  // right: 1562
82  TMath::Normal2Plane(p+3, p+15, p+18, normal);
83  glNormal3fv(normal);
84  glVertex3fv(p + 3); glVertex3fv(p + 15);
85  glVertex3fv(p + 18); glVertex3fv(p + 6);
86  glEnd();
87  }
88  else
89  {
90  glBegin(GL_LINE_STRIP);
91  glVertex3fv(p); glVertex3fv(p + 3);
92  glVertex3fv(p + 6); glVertex3fv(p + 9);
93  glVertex3fv(p);
94  glVertex3fv(p + 12); glVertex3fv(p + 15);
95  glVertex3fv(p + 18); glVertex3fv(p + 21);
96  glVertex3fv(p + 12);
97  glEnd();
98  glBegin(GL_LINES);
99  glVertex3fv(p + 3); glVertex3fv(p + 15);
100  glVertex3fv(p + 6); glVertex3fv(p + 18);
101  glVertex3fv(p + 9); glVertex3fv(p + 21);
102  glEnd();
103  }
104  }
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Render the frame-box with GL.
109 
111 {
112  const TEveFrameBox& b = *box;
113 
114  glPushAttrib(GL_POLYGON_BIT | GL_LINE_BIT | GL_ENABLE_BIT);
115 
116  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
117  glEnable(GL_COLOR_MATERIAL);
118  glDisable(GL_CULL_FACE);
119 
120  if (b.fDrawBack)
121  {
122  GLboolean lmts;
123  glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &lmts);
124  if (!lmts) glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
125 
126  glEnable(GL_POLYGON_OFFSET_FILL);
127  glPolygonOffset(2, 2);
128  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
129 
130  if (b.fBackRGBA[3] < 255)
131  {
132  glEnable(GL_BLEND);
133  glDepthMask(GL_FALSE);
134  }
135 
137  RenderFrame(b, kTRUE);
138 
139  if (!lmts) glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
140  }
141 
142  glDisable(GL_LIGHTING);
143  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
144  glEnable(GL_BLEND);
145  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
146  glEnable(GL_LINE_SMOOTH);
147 
150  RenderFrame(b, b.fFrameFill);
151 
152  glPopAttrib();
153 }
UChar_t fBackRGBA[4]
Definition: TEveFrameBox.h:38
float Float_t
Definition: RtypesCore.h:53
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Description of a 2D or 3D frame that can be used to visually group a set of objects.
Definition: TEveFrameBox.h:18
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
static void Render(const TEveFrameBox *box)
Render the frame-box with GL.
T * Normal2Plane(const T v1[3], const T v2[3], const T v3[3], T normal[3])
Definition: TMath.h:1180
Bool_t fDrawBack
Definition: TEveFrameBox.h:40
Float_t fFrameWidth
Definition: TEveFrameBox.h:34
Float_t * fFramePoints
Definition: TEveFrameBox.h:32
A class encapsulating GL rendering of TEveFrameBox via a static member function.
#define ClassImp(name)
Definition: Rtypes.h:359
EFrameType_e fFrameType
Definition: TEveFrameBox.h:30
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Bool_t fFrameFill
Definition: TEveFrameBox.h:39
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition: TGLUtil.cxx:1904
UChar_t fFrameRGBA[4]
Definition: TEveFrameBox.h:37
def normal(shape, name=None)
const Bool_t kTRUE
Definition: RtypesCore.h:87
Int_t fFrameSize
Definition: TEveFrameBox.h:31
static void Color4ubv(const UChar_t *rgba)
Wrapper for glColor4ubv.
Definition: TGLUtil.cxx:1740
static void RenderFrame(const TEveFrameBox &b, Bool_t fillp)
Render the frame with GL.