Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
22A class encapsulating GL rendering of TEveFrameBox via a static member function.
23*/
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// Render the frame with GL.
28
30{
31 const Float_t * p = b.fFramePoints;
32 Float_t normal[3];
33
34 if (b.fFrameType == TEveFrameBox::kFT_Quad)
35 {
36 if (fillp)
37 {
38 TMath::Normal2Plane(p, p+3, p+6, normal);
39 glNormal3fv(normal);
40 glBegin(GL_POLYGON);
41 }
42 else
43 {
44 glBegin(GL_LINE_LOOP);
45 }
46 Int_t nPoints = b.fFrameSize / 3;
47 for (Int_t i = 0; i < nPoints; ++i, p += 3)
48 glVertex3fv(p);
49 glEnd();
50 }
51 else if (b.fFrameType == TEveFrameBox::kFT_Box)
52 {
53 if (fillp)
54 {
55 glBegin(GL_QUADS);
56 TMath::Normal2Plane(p, p+3, p+6, normal);
57 glNormal3fv(normal);
58 glVertex3fv(p); glVertex3fv(p + 3);
59 glVertex3fv(p + 6); glVertex3fv(p + 9);
60 // top: 7654
61 TMath::Normal2Plane(p+21, p+18, p+15, normal);
62 glNormal3fv(normal);
63 glVertex3fv(p + 21); glVertex3fv(p + 18);
64 glVertex3fv(p + 15); glVertex3fv(p + 12);
65 // back: 0451
66 TMath::Normal2Plane(p, p+12, p+15, normal);
67 glNormal3fv(normal);
68 glVertex3fv(p); glVertex3fv(p + 12);
69 glVertex3fv(p + 15); glVertex3fv(p + 3);
70 // front: 3267
71 TMath::Normal2Plane(p+9, p+6, p+18, normal);
72 glNormal3fv(normal);
73 glVertex3fv(p + 9); glVertex3fv(p + 6);
74 glVertex3fv(p + 18); glVertex3fv(p + 21);
75 // left: 0374
76 TMath::Normal2Plane(p, p+9, p+21, normal);
77 glNormal3fv(normal);
78 glVertex3fv(p); glVertex3fv(p + 9);
79 glVertex3fv(p + 21); glVertex3fv(p + 12);
80 // right: 1562
81 TMath::Normal2Plane(p+3, p+15, p+18, normal);
82 glNormal3fv(normal);
83 glVertex3fv(p + 3); glVertex3fv(p + 15);
84 glVertex3fv(p + 18); glVertex3fv(p + 6);
85 glEnd();
86 }
87 else
88 {
89 glBegin(GL_LINE_STRIP);
90 glVertex3fv(p); glVertex3fv(p + 3);
91 glVertex3fv(p + 6); glVertex3fv(p + 9);
92 glVertex3fv(p);
93 glVertex3fv(p + 12); glVertex3fv(p + 15);
94 glVertex3fv(p + 18); glVertex3fv(p + 21);
95 glVertex3fv(p + 12);
96 glEnd();
97 glBegin(GL_LINES);
98 glVertex3fv(p + 3); glVertex3fv(p + 15);
99 glVertex3fv(p + 6); glVertex3fv(p + 18);
100 glVertex3fv(p + 9); glVertex3fv(p + 21);
101 glEnd();
102 }
103 }
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Render the frame-box with GL.
108
110{
111 const TEveFrameBox& b = *box;
112
113 glPushAttrib(GL_POLYGON_BIT | GL_LINE_BIT | GL_ENABLE_BIT);
114
115 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
116 glEnable(GL_COLOR_MATERIAL);
117 glDisable(GL_CULL_FACE);
118
119 if (b.fDrawBack)
120 {
121 GLboolean lmts;
122 glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &lmts);
123 if (!lmts) glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
124
125 glEnable(GL_POLYGON_OFFSET_FILL);
126 glPolygonOffset(2, 2);
127 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
128
129 if (b.fBackRGBA[3] < 255)
130 {
131 glEnable(GL_BLEND);
132 glDepthMask(GL_FALSE);
133 }
134
135 TGLUtil::Color4ubv(b.fBackRGBA);
137
138 if (!lmts) glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
139 }
140
141 glDisable(GL_LIGHTING);
142 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
143 glEnable(GL_BLEND);
144 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
145 glEnable(GL_LINE_SMOOTH);
146
147 TGLUtil::LineWidth(b.fFrameWidth);
148 TGLUtil::Color4ubv(b.fFrameRGBA);
149 RenderFrame(b, b.fFrameFill);
150
151 glPopAttrib();
152}
#define b(i)
Definition RSha256.hxx:100
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
static void RenderFrame(const TEveFrameBox &b, Bool_t fillp)
Render the frame with GL.
static void Render(const TEveFrameBox *box)
Render the frame-box with GL.
Description of a 2D or 3D frame that can be used to visually group a set of objects.
static void Color4ubv(const UChar_t *rgba)
Wrapper for glColor4ubv.
Definition TGLUtil.cxx:1770
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
Definition TGLUtil.cxx:1934
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
T * Normal2Plane(const T v1[3], const T v2[3], const T v3[3], T normal[3])
Calculates a normal vector of a plane.
Definition TMath.h:1299