]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/NLTPolygonSetGL.cxx
Record changes.
[u/mrichter/AliRoot.git] / EVE / Reve / NLTPolygonSetGL.cxx
CommitLineData
debf9f47 1#include "NLTPolygonSetGL.h"
2#include "NLTPolygonSet.h"
3#include "PODs.h"
4
19208112 5#include <TGLRnrCtx.h>
debf9f47 6#include <TGLIncludes.h>
debf9f47 7
8
9using namespace Reve;
10
11/**************************************************************************/
12
13NLTPolygonSetGL::NLTPolygonSetGL() : TGLObject()
14{
19208112 15 // fDLCache = false; // Disable DL.
debf9f47 16}
17
18NLTPolygonSetGL::~NLTPolygonSetGL()
19{}
20
21/**************************************************************************/
19208112 22Bool_t NLTPolygonSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
debf9f47 23{
24 return SetModelCheckClass(obj, NLTPolygonSet::Class());
25}
26
27/**************************************************************************/
28
29void NLTPolygonSetGL::SetBBox()
30{
31 SetAxisAlignedBBox(((NLTPolygonSet*)fExternalObj)->AssertBBox());
32}
33
34/**************************************************************************/
35static GLUtriangulatorObj *GetTesselator()
36{
37 static struct Init {
38 Init()
39 {
40#if defined(R__WIN32)
41 typedef void (CALLBACK *tessfuncptr_t)();
42#elif defined(R__AIXGCC)
43 typedef void (*tessfuncptr_t)(...);
44#else
45 typedef void (*tessfuncptr_t)();
46#endif
47 fTess = gluNewTess();
48
49 if (!fTess) {
50 Error("GetTesselator::Init", "could not create tesselation object");
51 } else {
52 gluTessCallback(fTess, (GLenum)GLU_BEGIN, (tessfuncptr_t)glBegin);
53 gluTessCallback(fTess, (GLenum)GLU_END, (tessfuncptr_t)glEnd);
54 gluTessCallback(fTess, (GLenum)GLU_VERTEX, (tessfuncptr_t)glVertex3fv);
55 }
56 }
57 ~Init()
58 {
59 if(fTess)
60 gluDeleteTess(fTess);
61 }
62 GLUtriangulatorObj *fTess;
63 }singleton;
64
65 return singleton.fTess;
66}
67
68/**************************************************************************/
19208112 69void NLTPolygonSetGL::DirectDraw(TGLRnrCtx & /*rnrCtx*/) const
debf9f47 70{
32e219c2 71 // printf("NLTPolygonSetGL::DirectDraw %s \n",fExternalObj->GetName() );
debf9f47 72 NLTPolygonSet& PS = * (NLTPolygonSet*) fExternalObj;
32e219c2 73 if(PS.fPols.size() == 0) return;
debf9f47 74
75 glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
76
77 glDisable(GL_LIGHTING);
78 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
79 glEnable(GL_COLOR_MATERIAL);
32e219c2 80 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
debf9f47 81 glDisable(GL_CULL_FACE);
82
83 // polygons
debf9f47 84 glEnable(GL_POLYGON_OFFSET_FILL);
85 glPolygonOffset(1.,1.);
86 GLUtriangulatorObj *tessObj = GetTesselator();
32e219c2 87
88 Vector* pnts = PS.fPnts;
89 for (NLTPolygonSet::vpPolygon_ci i = PS.fPols.begin(); i!= PS.fPols.end(); i++)
debf9f47 90 {
32e219c2 91 Int_t vi; //current vertex index of curent polygon
92 Int_t N = (*i).fNPnts; // number of points in current polygon
93 if(N < 4)
debf9f47 94 {
32e219c2 95 glBegin(GL_POLYGON);
96 for(Int_t k=0; k<N; k++)
debf9f47 97 {
32e219c2 98 vi = (*i).fPnts[k];
99 glVertex3fv(pnts[vi].c_vec());
debf9f47 100 }
32e219c2 101 glEnd();
102 }
103 else {
104 gluBeginPolygon(tessObj);
105 gluNextContour(tessObj, (GLenum)GLU_UNKNOWN);
106 glNormal3f(0., 0., 1.);
107 Double_t coords[3];
108 coords[2] = 0.;
109 for (Int_t k = 0; k<N; k++)
110 {
111 vi = (*i).fPnts[k];
112 coords[0] = pnts[vi].x;
113 coords[1] = pnts[vi].y;
114 gluTessVertex(tessObj, coords, pnts[vi].c_vec());
debf9f47 115 }
32e219c2 116 gluEndPolygon(tessObj);
debf9f47 117 }
118 }
119 glDisable(GL_POLYGON_OFFSET_FILL);
120
121 // outline
122 UChar_t lcol[4];
123 ColorFromIdx(PS.fLineColor, lcol);
124 glColor4ubv(lcol);
125 glEnable(GL_LINE_SMOOTH);
126
127 glLineWidth(PS.fLineWidth);
32e219c2 128 Int_t vi;
129 for (NLTPolygonSet::vpPolygon_ci i = PS.fPols.begin(); i!= PS.fPols.end(); i++)
debf9f47 130 {
131 glBegin(GL_LINE_LOOP);
32e219c2 132 for(Int_t k=0; k<(*i).fNPnts; k++)
debf9f47 133 {
32e219c2 134 vi = (*i).fPnts[k];
135 glVertex3fv(PS.fPnts[vi].c_vec());
debf9f47 136 }
137 glEnd();
138 }
139
140 glPopAttrib();
141}
142