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
|
// render each block as a polygon extruded into Z
void BlockGroup::BuildDisplayList()
{
static GLUtesselator *tobj = NULL;
if( ! mod.world->IsGUI() )
return;
std::vector<std::vector<GLdouble> > contours;
FOR_EACH( blk, blocks )
{
std::vector<GLdouble> verts;
FOR_EACH( it, blk->pts )
{
verts.push_back( it->x );
verts.push_back( it->y );
verts.push_back( blk->local_z.max );
}
contours.push_back( verts );
}
if( displaylist == 0 )
{
CalcSize(); // todo: is this redundant? count calls per model
// to figure this out.
displaylist = glGenLists(1);
assert(displaylist !=0 );
// Stage polygons need not be convex, so we have to
// tesselate them for rendering in OpenGL.
tobj = gluNewTess();
assert(tobj != NULL);
//GG: inizio
gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid (CALLBACK*) ())
&glVertex3dv);
gluTessCallback(tobj, GLU_TESS_EDGE_FLAG, (GLvoid (CALLBACK*) ())
&glEdgeFlag);
gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid (CALLBACK*) ()) &glBegin);
gluTessCallback(tobj, GLU_TESS_END, (GLvoid (CALLBACK*) ()) &glEnd);
// these use the standard GL calls
gluTessCallback(tobj, GLU_TESS_ERROR, (GLvoid (CALLBACK*) ())
&errorCallback);
gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid (CALLBACK*) ())
&combineCallback);
//GG: fine
}
glNewList( displaylist, GL_COMPILE );
Gl::pose_shift( mod.GetGeom().pose );
// draw filled polys
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(0.5, 0.5);
mod.PushColor( mod.color );
// primo contorno
gluTessBeginPolygon(tobj, NULL);
FOR_EACH( contour, contours )
{
gluTessBeginContour(tobj);
//for( size_t v = 0; v < contours.size(); v+=3 )
for( size_t v = 0; v < contour->size(); v += 3 )
gluTessVertex(tobj, &(*contour)[v], &(*contour)[v]);
gluTessEndContour(tobj);
}
gluTessEndPolygon(tobj);
...
}
|