1 #include "NLTPolygonSetGL.h"
2 #include "NLTPolygonSet.h"
6 #include <TGLIncludes.h>
11 /**************************************************************************/
13 NLTPolygonSetGL::NLTPolygonSetGL() : TGLObject()
15 // fDLCache = false; // Disable DL.
18 NLTPolygonSetGL::~NLTPolygonSetGL()
21 /**************************************************************************/
22 Bool_t NLTPolygonSetGL::SetModel(TObject* obj, const Option_t* /*opt*/)
24 return SetModelCheckClass(obj, NLTPolygonSet::Class());
27 /**************************************************************************/
29 void NLTPolygonSetGL::SetBBox()
31 SetAxisAlignedBBox(((NLTPolygonSet*)fExternalObj)->AssertBBox());
34 /**************************************************************************/
35 static GLUtriangulatorObj *GetTesselator()
41 typedef void (CALLBACK *tessfuncptr_t)();
42 #elif defined(R__AIXGCC)
43 typedef void (*tessfuncptr_t)(...);
45 typedef void (*tessfuncptr_t)();
50 Error("GetTesselator::Init", "could not create tesselation object");
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);
62 GLUtriangulatorObj *fTess;
65 return singleton.fTess;
68 /**************************************************************************/
69 void NLTPolygonSetGL::DirectDraw(TGLRnrCtx & /*rnrCtx*/) const
71 // printf("NLTPolygonSetGL::DirectDraw %s \n",fExternalObj->GetName() );
72 NLTPolygonSet& PS = * (NLTPolygonSet*) fExternalObj;
73 if(PS.fPols.size() == 0) return;
75 glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
77 glDisable(GL_LIGHTING);
78 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
79 glEnable(GL_COLOR_MATERIAL);
80 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
81 glDisable(GL_CULL_FACE);
84 glEnable(GL_POLYGON_OFFSET_FILL);
85 glPolygonOffset(1.,1.);
86 GLUtriangulatorObj *tessObj = GetTesselator();
88 Vector* pnts = PS.fPnts;
89 for (NLTPolygonSet::vpPolygon_ci i = PS.fPols.begin(); i!= PS.fPols.end(); i++)
91 Int_t vi; //current vertex index of curent polygon
92 Int_t N = (*i).fNPnts; // number of points in current polygon
96 for(Int_t k=0; k<N; k++)
99 glVertex3fv(pnts[vi].c_vec());
104 gluBeginPolygon(tessObj);
105 gluNextContour(tessObj, (GLenum)GLU_UNKNOWN);
106 glNormal3f(0., 0., 1.);
109 for (Int_t k = 0; k<N; k++)
112 coords[0] = pnts[vi].x;
113 coords[1] = pnts[vi].y;
114 gluTessVertex(tessObj, coords, pnts[vi].c_vec());
116 gluEndPolygon(tessObj);
119 glDisable(GL_POLYGON_OFFSET_FILL);
123 ColorFromIdx(PS.fLineColor, lcol);
125 glEnable(GL_LINE_SMOOTH);
127 glLineWidth(PS.fLineWidth);
129 for (NLTPolygonSet::vpPolygon_ci i = PS.fPols.begin(); i!= PS.fPols.end(); i++)
131 glBegin(GL_LINE_LOOP);
132 for(Int_t k=0; k<(*i).fNPnts; k++)
135 glVertex3fv(PS.fPnts[vi].c_vec());