forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveFrameBoxGL.cxx
153 lines (132 loc) · 4.56 KB
/
TEveFrameBoxGL.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveFrameBoxGL.h"
#include "TEveFrameBox.h"
#include "TGLIncludes.h"
#include "TGLUtil.h"
#include "TMath.h"
/** \class TEveFrameBoxGL
\ingroup TEve
A class encapsulating GL rendering of TEveFrameBox via a static member function.
*/
ClassImp(TEveFrameBoxGL);
////////////////////////////////////////////////////////////////////////////////
/// Render the frame with GL.
void TEveFrameBoxGL::RenderFrame(const TEveFrameBox& b, Bool_t fillp)
{
const Float_t * p = b.fFramePoints;
Float_t normal[3];
if (b.fFrameType == TEveFrameBox::kFT_Quad)
{
if (fillp)
{
TMath::Normal2Plane(p, p+3, p+6, normal);
glNormal3fv(normal);
glBegin(GL_POLYGON);
}
else
{
glBegin(GL_LINE_LOOP);
}
Int_t nPoints = b.fFrameSize / 3;
for (Int_t i = 0; i < nPoints; ++i, p += 3)
glVertex3fv(p);
glEnd();
}
else if (b.fFrameType == TEveFrameBox::kFT_Box)
{
if (fillp)
{
glBegin(GL_QUADS);
TMath::Normal2Plane(p, p+3, p+6, normal);
glNormal3fv(normal);
glVertex3fv(p); glVertex3fv(p + 3);
glVertex3fv(p + 6); glVertex3fv(p + 9);
// top: 7654
TMath::Normal2Plane(p+21, p+18, p+15, normal);
glNormal3fv(normal);
glVertex3fv(p + 21); glVertex3fv(p + 18);
glVertex3fv(p + 15); glVertex3fv(p + 12);
// back: 0451
TMath::Normal2Plane(p, p+12, p+15, normal);
glNormal3fv(normal);
glVertex3fv(p); glVertex3fv(p + 12);
glVertex3fv(p + 15); glVertex3fv(p + 3);
// front: 3267
TMath::Normal2Plane(p+9, p+6, p+18, normal);
glNormal3fv(normal);
glVertex3fv(p + 9); glVertex3fv(p + 6);
glVertex3fv(p + 18); glVertex3fv(p + 21);
// left: 0374
TMath::Normal2Plane(p, p+9, p+21, normal);
glNormal3fv(normal);
glVertex3fv(p); glVertex3fv(p + 9);
glVertex3fv(p + 21); glVertex3fv(p + 12);
// right: 1562
TMath::Normal2Plane(p+3, p+15, p+18, normal);
glNormal3fv(normal);
glVertex3fv(p + 3); glVertex3fv(p + 15);
glVertex3fv(p + 18); glVertex3fv(p + 6);
glEnd();
}
else
{
glBegin(GL_LINE_STRIP);
glVertex3fv(p); glVertex3fv(p + 3);
glVertex3fv(p + 6); glVertex3fv(p + 9);
glVertex3fv(p);
glVertex3fv(p + 12); glVertex3fv(p + 15);
glVertex3fv(p + 18); glVertex3fv(p + 21);
glVertex3fv(p + 12);
glEnd();
glBegin(GL_LINES);
glVertex3fv(p + 3); glVertex3fv(p + 15);
glVertex3fv(p + 6); glVertex3fv(p + 18);
glVertex3fv(p + 9); glVertex3fv(p + 21);
glEnd();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Render the frame-box with GL.
void TEveFrameBoxGL::Render(const TEveFrameBox* box)
{
const TEveFrameBox& b = *box;
glPushAttrib(GL_POLYGON_BIT | GL_LINE_BIT | GL_ENABLE_BIT);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_CULL_FACE);
if (b.fDrawBack)
{
GLboolean lmts;
glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &lmts);
if (!lmts) glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(2, 2);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (b.fBackRGBA[3] < 255)
{
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
}
TGLUtil::Color4ubv(b.fBackRGBA);
RenderFrame(b, kTRUE);
if (!lmts) glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
}
glDisable(GL_LIGHTING);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
TGLUtil::LineWidth(b.fFrameWidth);
TGLUtil::Color4ubv(b.fFrameRGBA);
RenderFrame(b, b.fFrameFill);
glPopAttrib();
}