1 /***********************************************************************
11 Le culling et le backfacing ne marchent pas.
13 HISTORIQUE DES MODIFICATIONS :
14 --------------------------------
15 xx-xx-xx : xxx ; Creation.
16 11-03-96 : FMN ; Correction warning compilation
17 01-04-96 : CAL ; Integration MINSK portage WNT
18 28-06-96 : GG ; Auto checking of the polygon facet normal with
19 the order of the points (OPTIM)
20 09-08-96 : FMN ; Suppression appel glMatrixMode() avant glGetFloatv()
21 28-02-97 : FMN ; Suppression OpenGl_telem_light.h
22 18-07-97 : FMN ; Ajout desactivation des lights suivant front_lighting_model
23 21-07-97 : FMN ; Amelioration des performances OPTIMISATION_FMN
24 - suppression calcul inutile sur les front faces
25 27-08-97 : FMN ; Correction affichage des edges
26 On n'affiche que les edges dans le mode IS_EMPTY
27 10-09-97 : FMN ; Amelioration des perfs liees aux lights.
28 15-09-97 : PCT ; Ajout coordonnees textures
29 24-09-97 : FMN ; Suppression OPTIMISATION_FMN.
30 08-12-97 : FMN ; Suppression appel TsmGetAttri inutile.
31 31-12-97 : FMN ; Simplification pour le highlight
32 15-01-98 : FMN ; Ajout Hidden line
33 18-06-98 : CAL ; Correction PRO14340. Patch K4198 et K4199
34 08-03-01 : GG ; BUC60823 Avoid crash in the normal computation method
37 ************************************************************************/
39 #define G003 /* EUG 22-09-99 Degeneration management
42 /*----------------------------------------------------------------------*/
47 #include <OpenGl_tgl_all.hxx>
53 #include <OpenGl_cmn_varargs.hxx>
54 #include <OpenGl_Extension.hxx>
55 #include <OpenGl_telem_attri.hxx>
56 #include <OpenGl_tsm.hxx>
57 #include <OpenGl_telem.hxx>
58 #include <OpenGl_telem_util.hxx>
59 #include <OpenGl_telem_highlight.hxx>
60 #include <OpenGl_telem_inquire.hxx>
61 #include <OpenGl_telem_view.hxx>
62 #include <OpenGl_tgl_funcs.hxx>
63 #include <OpenGl_LightBox.hxx>
64 #include <OpenGl_TextureBox.hxx>
65 #include <OpenGl_Memory.hxx>
69 /*----------------------------------------------------------------------*/
76 #if !defined(APIENTRY)
79 # define STATIC static
83 typedef double GLUcoord;
87 extern int g_nDegenerateModel;
90 /*----------------------------------------------------------------------*/
95 static TStatus PolygonDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
96 static TStatus PolygonAdd( TSM_ELEM_DATA, Tint, cmn_key* );
97 static TStatus PolygonDelete( TSM_ELEM_DATA, Tint, cmn_key* );
98 static TStatus PolygonPrint( TSM_ELEM_DATA, Tint, cmn_key* );
99 static TStatus PolygonInquire( TSM_ELEM_DATA, Tint, cmn_key* );
101 /*----------------------------------------------------------------------*/
106 extern Tint ForbidSetTextureMapping; /* currently defined in tsm/tsm.c */
108 /*----------------------------------------------------------------------*/
110 * Definition de types
117 IMPLEMENT_MEMORY_OPERATORS
119 typedef EXTRA_VERTEX* extra_vertex;
123 Tint ts_num, ts_alloc;
124 void **tmesh_sequence;
125 GLenum triangle_type; /* FSXXX OPTI */
126 IMPLEMENT_MEMORY_OPERATORS
134 IMPLEMENT_MEMORY_OPERATORS
137 struct TEL_POLYGON_DATA
139 Tint num_vertices; /* Number of vertices */
140 Tint facet_flag; /* TEL_FA_NONE or TEL_FA_NORMAL */
141 Tint vertex_flag; /* TEL_VT_NONE or TEL_VT_NORMAL */
142 Tint shape_flag; /* TEL_SHAPE_UNKNOWN or TEL_SHAPE_COMPLEX or
143 TEL_SHAPE_CONVEX or TEL_SHAPE_CONCAVE */
144 GLboolean reverse_order; /* GL_TRUE if polygon vertex must be display in reverse order */
145 TEL_POINT fnormal; /* Facet normal */
146 tel_colour fcolour; /* Facet colour */
147 tel_point vertices; /* Vertices */
148 tel_colour vcolours; /* Vertex colour values */
149 tel_point vnormals; /* Vertex normals */
150 tel_texture_coord vtexturecoord; /* Texture Coordinates */
151 DISPLAY_ *display; /* FSXXX OPTI */
152 GLuint triangle_dl1; /* triangle display list 1 */
153 GLuint triangle_dl2; /* triangle display list 2 */
154 GLuint triangle_dl3; /* triangle display list 3 */
155 IMPLEMENT_MEMORY_OPERATORS
157 typedef TEL_POLYGON_DATA *tel_polygon_data;
159 static TEL_POLYGON_DATA polygon_defaults =
161 0, /* num_vertices */
162 TEL_FA_NONE, /* facet_flag */
163 TEL_VT_NONE, /* vertex_flag */
164 TEL_SHAPE_UNKNOWN, /* shape_flag */
165 GL_FALSE, /* reverse_order */
166 {{ ( float )0.0, ( float )0.0, ( float )0.0 }}, /* fnormal */
171 0, /* vtexturecoord */
173 0, /* triangle_dl1 */
174 0, /* triangle_dl2 */
179 static void bgntriangulate( tel_polygon_data, void (APIENTRY*)() );
180 static void endtriangulate(void);
181 static void draw_tmesh( tel_polygon_data, Tint );
182 static void draw_polygon( tel_polygon_data, Tint, Tint );
183 static void draw_polygon_concav( tel_polygon_data, Tint, Tint );
185 #if !defined(GLU_VERSION_1_2)
186 #define GLUtesselator GLUtriangulatorObj
187 void gluTessBeginContour();
188 void gluTessBeginPolygon();
189 void gluTessEndPolygon();
190 void gluTessEndContour();
193 static TStatus (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
195 PolygonDisplay, /* PickTraverse */
203 static void draw_edges( tel_polygon_data, tel_colour, Tint);
205 /*----------------------------------------------------------------------*/
208 TelPolygonInitClass( TelType* el )
213 /*----------------------------------------------------------------------*/
216 PolygonAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
219 tel_polygon_data data;
221 for( i = 0; i < n; i++ )
223 if( k[i]->id == NUM_VERTICES_ID )
229 if( !(k[i]->data.ldata) )
232 for( j = 0; j < n; j++ )
234 if( k[j]->id == VERTICES_ID )
240 data = new TEL_POLYGON_DATA();
245 memcpy( data, &polygon_defaults, sizeof(TEL_POLYGON_DATA) );
247 data->num_vertices = k[i]->data.ldata;
248 data->vertices = new TEL_POINT[data->num_vertices];
249 memcpy( data->vertices, k[j]->data.pdata, data->num_vertices*sizeof(TEL_POINT) );
251 for( i = 0; i < n; i++ )
256 data->facet_flag = TEL_FA_NORMAL;
257 memcpy( &data->fnormal, k[i]->data.pdata, sizeof(TEL_POINT) );
258 vecnrm( data->fnormal.xyz );
261 case FACET_COLOUR_VALS_ID:
262 data->fcolour = new TEL_COLOUR();
263 memcpy( data->fcolour, k[i]->data.pdata, sizeof(TEL_COLOUR) );
266 case VERTEX_COLOUR_VALS_ID:
267 data->vcolours = new TEL_COLOUR[data->num_vertices];
268 memcpy( data->vcolours, k[i]->data.pdata, data->num_vertices*sizeof(TEL_COLOUR) );
272 data->vertex_flag = TEL_VT_NORMAL;
273 data->vnormals = new TEL_POINT[data->num_vertices];
274 memcpy( data->vnormals, k[i]->data.pdata, data->num_vertices*sizeof(TEL_POINT) );
275 for( j = 0; j < data->num_vertices; j++ )
276 vecnrm( data->vnormals[j].xyz );
280 data->shape_flag = k[i]->data.ldata;
283 case VTEXTURECOORD_ID:
284 data->vtexturecoord = new TEL_TEXTURE_COORD[data->num_vertices];
285 memcpy( data->vtexturecoord, k[i]->data.pdata, data->num_vertices*sizeof(TEL_TEXTURE_COORD) );
290 if( data->facet_flag != TEL_FA_NORMAL ) {
292 TelGetPolygonNormal( data->vertices, NULL,
293 data->num_vertices, data->fnormal.xyz );
295 TelGetNormal( data->vertices[0].xyz, data->vertices[1].xyz,
296 data->vertices[2].xyz, data->fnormal.xyz );
297 vecnrm( data->fnormal.xyz );
302 TEL_POINT fnormal; /* Facet normal */
305 TelGetPolygonNormal( data->vertices, NULL,
306 data->num_vertices, fnormal.xyz );
308 TelGetNormal( data->vertices[0].xyz, data->vertices[1].xyz,
309 data->vertices[2].xyz, fnormal.xyz );
311 sens = fnormal.xyz[0]*data->fnormal.xyz[0] +
312 fnormal.xyz[1]*data->fnormal.xyz[1] +
313 fnormal.xyz[2]*data->fnormal.xyz[2];
314 if( sens < 0. ) data->reverse_order = GL_TRUE;
316 ((tsm_elem_data)(d.pdata))->pdata = data;
318 /* s'il n'est pas convexe, le polygone est triangule de la meme maniere
319 que les polygones a trous */
320 /* Pourrait etre place en tete de routine pour optimisation si je
321 savais recuperer le shape_flag a partir de d sans reconstruire data (!) */
324 if( data->shape_flag != TEL_SHAPE_CONVEX )
325 return(PolygonHolesAdd( d, n, k ));
330 /*----------------------------------------------------------------------*/
333 PolygonDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
335 /* Tint front_face = 1;*/
336 CMN_KEY k11, k12, k17, k111, k114;
338 Tint front_lighting_model;
340 TEL_COLOUR interior_colour;
341 TEL_COLOUR edge_colour;
345 k12.id = TelInteriorReflectanceEquation;
346 k17.id = TelInteriorStyle;
347 k111.id = TelInteriorColour;
348 k111.data.pdata = &interior_colour;
349 k114.id = TelEdgeColour;
350 k114.data.pdata = &edge_colour;
352 TsmGetAttri( 4, &k12, &k17, &k111, &k114);
354 front_lighting_model = k12.data.ldata;
355 interior_style = k17.data.ldata;
358 printf("PolygonDisplay \n");
362 * Use highlight colours
365 if( k[0]->id == TOn )
369 k11.id = TelHighlightIndex;
370 TsmGetAttri( 1, &k11 );
371 if( TelGetHighlightRep( TglActiveWs, k11.data.ldata, &hrep ) == TSuccess )
373 if( hrep.type == TelHLForcedColour )
375 interior_colour = hrep.col;
376 edge_colour = hrep.col;
377 front_lighting_model = CALL_PHIGS_REFL_NONE;
384 TelGetHighlightRep( TglActiveWs, 0, &hrep );
385 if( hrep.type == TelHLForcedColour )
387 interior_colour = hrep.col;
388 edge_colour = hrep.col;
389 front_lighting_model = CALL_PHIGS_REFL_NONE;
396 d = (tel_polygon_data)data.pdata;
399 if( interior_style != TSM_EMPTY && g_nDegenerateModel < 2 )
401 if( interior_style != TSM_EMPTY )
404 if (front_lighting_model == CALL_PHIGS_REFL_NONE)
408 glColor3fv( interior_colour.rgb );
410 if( d->shape_flag != TEL_SHAPE_CONVEX )
411 draw_polygon_concav( d, front_lighting_model, k[0]->id );
413 draw_polygon( d, front_lighting_model, k[0]->id );
417 /* OCC11904 -- Temporarily disable environment mapping */
418 glPushAttrib(GL_ENABLE_BIT);
419 glDisable(GL_TEXTURE_1D);
420 glDisable(GL_TEXTURE_2D);
422 switch ( g_nDegenerateModel ) {
425 case 0: /* no degeneration */
426 draw_edges ( d, &edge_colour, interior_style );
428 case 2: /* wireframe degeneration */
430 #ifdef xG003 /* GG260100 use interior color instead edge color */
431 draw_edges ( d, &interior_colour, interior_style );
433 draw_edges ( d, &edge_colour, interior_style );
437 case 3: /* marker degeneration */
443 glPopAttrib(); /* skt: GL_ENABLE_BIT*/
445 draw_edges( d, &edge_colour, interior_style );
446 /*skt: It is not correct to pop attributes here*/
452 /*----------------------------------------------------------------------*/
455 draw_polygon( tel_polygon_data d, Tint front_lighting_model, Tint hflag )
462 tel_texture_coord pvt;
467 pvt = d->vtexturecoord;
469 if( hflag ) pvc = pfc = NULL;
473 glColor3fv( pfc->rgb );
474 if( front_lighting_model != CALL_PHIGS_REFL_NONE )
475 glNormal3fv( d->fnormal.xyz );
477 if( d->reverse_order ) glFrontFace( GL_CW );
479 if (d->num_vertices == 3) glBegin(GL_TRIANGLES);
480 else if(d->num_vertices == 4) glBegin(GL_QUADS);
481 else glBegin(GL_POLYGON);
482 if( front_lighting_model == CALL_PHIGS_REFL_NONE )
486 for( i=0; i<d->num_vertices; i++, ptr++ )
488 glColor3fv( pvc[i].rgb );
489 glVertex3fv( ptr->xyz );
494 for( i=0; i<d->num_vertices; i++, ptr++ )
496 glVertex3fv( ptr->xyz );
504 if (pvt && !ForbidSetTextureMapping)
505 for( i=0; i<d->num_vertices; i++, ptr++ )
507 glNormal3fv( pvn[i].xyz );
508 glTexCoord2fv( pvt[i].xy );
509 glVertex3fv( ptr->xyz );
512 for( i=0; i<d->num_vertices; i++, ptr++ )
514 glNormal3fv( pvn[i].xyz );
515 glVertex3fv( ptr->xyz );
520 for( i=0; i<d->num_vertices; i++, ptr++ )
522 glVertex3fv( ptr->xyz );
527 if( d->reverse_order ) glFrontFace( GL_CCW );
531 /*----------------------------------------------------------------------*/
533 /* JWR - allow varying the size */
537 static int seq_increment = INCREMENT;
539 tel_polygon_data DaTa;
540 static GLUtesselator *tripak = 0;
543 out_bgntmesh( GLenum triangle_type )
549 if( dis->num_alloc < dis->num_of_seq )
551 dis->num_alloc += seq_increment;
555 dis->seq = new SEQ_[dis->num_alloc];
559 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
560 dis->seq = (SEQ_*)realloc( dis->seq, dis->num_alloc*sizeof(SEQ_) );
562 dis->seq = cmn_resizemem<SEQ_>( dis->seq, dis->num_alloc );
566 dis->seq[ dis->num_of_seq - 1 ].ts_num = 0;
567 dis->seq[ dis->num_of_seq - 1 ].ts_alloc = 0;
568 dis->seq[ dis->num_of_seq - 1 ].tmesh_sequence = 0;
570 #ifdef JWR_DEC_TRIFAN_BUG
571 dis->seq[ dis->num_of_seq - 1 ].triangle_type = GL_POLYGON;
574 dis->seq[ dis->num_of_seq - 1 ].triangle_type = triangle_type;
575 glBegin(triangle_type);
579 /*----------------------------------------------------------------------*/
582 out_vert1( void *data )
586 s = &( DaTa->display->seq[ DaTa->display->num_of_seq - 1 ] );
589 if( s->ts_alloc < s->ts_num )
591 s->ts_alloc += seq_increment;
593 if( s->tmesh_sequence == 0 )
595 s->tmesh_sequence = new void*[s->ts_alloc];
599 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
600 s->tmesh_sequence = (void**)realloc( s->tmesh_sequence, s->ts_alloc*sizeof(void*));
602 s->tmesh_sequence = cmn_resizemem<void*>( s->tmesh_sequence, s->ts_alloc);
606 s->tmesh_sequence[ s->ts_num - 1 ] = data;
609 if ( data < (void *)0xffff ) {
612 glVertex3fv( DaTa->vertices[a].xyz );
615 extra_vertex b = (extra_vertex) data;
618 printf("combine1 %e %e %e %d\n",
619 b->vert[0], b->vert[1], b->vert[2], (b->ind));
621 glVertex3fv( b->vert );
626 /*----------------------------------------------------------------------*/
629 out_vert2( void *data )
633 s = &( DaTa->display->seq[ DaTa->display->num_of_seq - 1 ] );
636 if( s->ts_alloc < s->ts_num )
638 s->ts_alloc += seq_increment;
640 if( s->tmesh_sequence == 0 )
642 s->tmesh_sequence = new void*[s->ts_alloc];
646 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
647 s->tmesh_sequence = (void**)( s->tmesh_sequence,
648 s->ts_alloc*sizeof(void*) );
650 s->tmesh_sequence = cmn_resizemem<void*>( s->tmesh_sequence,
655 s->tmesh_sequence[ s->ts_num - 1 ] = data;
657 if ( data < (void *)0xffff ) {
660 glColor3fv( DaTa->vcolours[a].rgb );
661 glVertex3fv( DaTa->vertices[a].xyz );
664 extra_vertex b = (extra_vertex) data;
666 printf("combine2 %e %e %e %d\n",b->vert[0], b->vert[1], b->vert[2], (b->ind));
667 glColor3fv( DaTa->vcolours[(b->ind)].rgb );
668 glVertex3fv( b->vert );
673 /*----------------------------------------------------------------------*/
676 out_vert3( void *data )
680 s = &( DaTa->display->seq[ DaTa->display->num_of_seq - 1 ] );
683 if( s->ts_alloc < s->ts_num )
685 s->ts_alloc += seq_increment;
687 if( s->tmesh_sequence == 0 )
689 s->tmesh_sequence = new void*[s->ts_alloc];
693 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)
694 s->tmesh_sequence = (void**)realloc( s->tmesh_sequence,
695 s->ts_alloc*sizeof(void*) );
697 s->tmesh_sequence = cmn_resizemem<void*>( s->tmesh_sequence,
702 s->tmesh_sequence[ s->ts_num - 1 ] = data;
704 if ( data <= (void *)0xffff ) {
707 glNormal3fv( DaTa->vnormals[a].xyz );
708 glVertex3fv( DaTa->vertices[a].xyz);
711 extra_vertex b = (extra_vertex) data;
713 printf("combine3 %e %e %e %d\n", b->vert[0], b->vert[1], b->vert[2], (b->ind));
714 glNormal3fv( DaTa->vnormals[(b->ind)].xyz );
715 glVertex3fv( b->vert );
720 /*----------------------------------------------------------------------*/
723 mycombine( GLdouble coords[3], int *data, GLfloat w[4], void **dataout)
725 extra_vertex new_vertex;
727 new_vertex = (extra_vertex) malloc(sizeof(EXTRA_VERTEX));
729 new_vertex->vert[0] = ( float )coords[0];
730 new_vertex->vert[1] = ( float )coords[1];
731 new_vertex->vert[2] = ( float )coords[2];
732 new_vertex->ind = *data;
733 *dataout = new_vertex;
735 printf("mycombine3 %e %e %e\n",
740 printf("weights: %f %f %f %f\n",
741 w[0], w[1], w[2], w[3]);
745 /*----------------------------------------------------------------------*/
753 /*----------------------------------------------------------------------*/
756 out_error( GLenum error )
758 printf( "POLYGON : %s\n", (char *) gluErrorString(error) );
761 /*----------------------------------------------------------------------*/
764 bgntriangulate(tel_polygon_data d, void ( APIENTRY * out_ver)() )
768 DaTa->display = new DISPLAY_();
770 tripak = gluNewTess();
772 #if defined(linux) && !defined(NOGLUfuncptr)
773 gluTessCallback( tripak, GLU_TESS_BEGIN, (_GLUfuncptr)(out_bgntmesh) );
774 gluTessCallback( tripak, GLU_TESS_VERTEX, out_ver );
775 gluTessCallback( tripak, GLU_TESS_END, out_endtmesh );
776 gluTessCallback( tripak, GLU_TESS_ERROR, (_GLUfuncptr)(out_error) );
777 gluTessCallback( tripak, GLU_TESS_COMBINE, (_GLUfuncptr)(mycombine) );
779 gluTessCallback( tripak, GLU_TESS_BEGIN, (void (APIENTRY*)())out_bgntmesh );
780 gluTessCallback( tripak, GLU_TESS_VERTEX, (void (APIENTRY*)())out_ver );
781 gluTessCallback( tripak, GLU_TESS_END, (void (APIENTRY*)())out_endtmesh );
782 gluTessCallback( tripak, GLU_TESS_ERROR, (void (APIENTRY*)())out_error );
783 gluTessCallback( tripak, GLU_TESS_COMBINE, (void (APIENTRY*)())mycombine );
787 /*----------------------------------------------------------------------*/
793 gluDeleteTess(tripak);
796 /*----------------------------------------------------------------------*/
799 draw_polygon_concav( tel_polygon_data d, Tint front_lighting_model, Tint hflag )
821 glColor3fv( pfc->rgb );
822 if( front_lighting_model != CALL_PHIGS_REFL_NONE )
823 glNormal3fv( d->fnormal.xyz );
825 if( d->reverse_order ) glFrontFace( GL_CW );
827 if( d->display == 0 )
830 if( front_lighting_model == CALL_PHIGS_REFL_NONE )
834 bgntriangulate(d, (void (APIENTRY*)())out_vert2);
838 bgntriangulate(d, (void (APIENTRY*)())out_vert1);
845 bgntriangulate(d, (void (APIENTRY*)())out_vert3);
849 bgntriangulate(d, (void (APIENTRY*)())out_vert1);
852 gluTessBeginPolygon( tripak, NULL );
853 gluTessBeginContour( tripak);
855 for( i=0; i<d->num_vertices; i++, ptr++ )
857 xyz[0] = ptr->xyz[0];
858 xyz[1] = ptr->xyz[1];
859 xyz[2] = ptr->xyz[2];
861 gluTessVertex( tripak, xyz,(void * ) i );
864 double v[ 3 ] = {ptr -> xyz[ 0 ], ptr -> xyz[ 1 ], ptr -> xyz[ 2 ]};
865 gluTessVertex ( tripak, v, ( void* )i );
869 gluTessEndContour( tripak);
870 gluTessEndPolygon( tripak );
875 if( front_lighting_model == CALL_PHIGS_REFL_NONE )
877 if( pvc ) draw_tmesh( d, 2 );
878 else draw_tmesh( d, 1 );
882 if( pvn ) draw_tmesh( d, 3 );
883 else draw_tmesh( d, 1 );
887 if( d->reverse_order ) glFrontFace( GL_CCW );
890 /*----------------------------------------------------------------------*/
893 draw_tmesh( tel_polygon_data d, Tint v )
901 for( i = 0; i < dis->num_of_seq; i++ )
905 glBegin(s->triangle_type);
910 for( j = 0, k = 0; j < s->ts_num; j++ )
912 if ( s->tmesh_sequence[j] < (void *)0xffff )
913 glVertex3fv( d->vertices[ (long)s->tmesh_sequence[ j ] ].xyz );
915 extra_vertex b = (extra_vertex)s->tmesh_sequence[j];
916 glVertex3fv( b->vert );
924 for( j = 0, k = 0; j < s->ts_num; j++ )
926 if ( s->tmesh_sequence[j] < (void *)0xffff ) {
927 glColor3fv( d->vcolours[ (long) s->tmesh_sequence[ j ] ].rgb );
928 glVertex3fv( d->vertices[ (long) s->tmesh_sequence[ j ] ].xyz );
930 b = (extra_vertex) s->tmesh_sequence[j];
931 glColor3fv( d->vcolours[(b->ind)].rgb);
932 glVertex3fv( b->vert );
939 for( j = 0, k = 0; j < s->ts_num; j++ )
941 if ( s->tmesh_sequence[j] < (void *)0xffff ) {
942 glNormal3fv( d->vnormals[ (long) s->tmesh_sequence[ j ] ].xyz);
943 glVertex3fv( d->vertices[ (long) s->tmesh_sequence[ j ] ].xyz);
945 b = (extra_vertex) s->tmesh_sequence[j];
946 glNormal3fv( d->vnormals[(b->ind)].xyz);
947 glVertex3fv( b->vert );
957 /*----------------------------------------------------------------------*/
960 PolygonDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
962 tel_polygon_data p = (tel_polygon_data)data.pdata;
963 if( p->fcolour ) //cmn_freemem( p->fcolour );
965 if( p->vertices )// cmn_freemem( p->vertices );
966 delete[] p->vertices;
967 if( p->vcolours ) //cmn_freemem( p->vcolours );
968 delete[] p->vcolours;
969 if( p->vnormals ) //cmn_freemem( p->vnormals );
970 delete[] p->vnormals;
971 if (p->vtexturecoord) //cmn_freemem( p->vtexturecoord);
972 delete p->vtexturecoord;
978 for( i = 0; i < p->display->num_of_seq; i++ )
980 if(p->display->seq[i].tmesh_sequence) {
981 for ( j = 0; j < p->display->seq[i].ts_num ; j++ ) {
982 if ( p->display->seq[i].tmesh_sequence[j] >= (void *)0xffff )
983 free(p->display->seq[i].tmesh_sequence[j]);
986 delete[] p->display->seq[i].tmesh_sequence;
988 delete[] p->display->seq;
996 /*----------------------------------------------------------------------*/
999 PolygonPrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
1002 tel_polygon_data p = (tel_polygon_data)data.pdata;
1004 fprintf( stdout, "TelPolygon. Number of points: %d\n", p->num_vertices );
1005 switch( p->shape_flag )
1007 case TEL_SHAPE_UNKNOWN:
1008 fprintf( stdout, "\t\tShape Flag : UNKNOWN\n" );
1011 case TEL_SHAPE_COMPLEX:
1012 fprintf( stdout, "\t\tShape Flag : COMPLEX\n" );
1015 case TEL_SHAPE_CONCAVE:
1016 fprintf( stdout, "\t\tShape Flag : CONCAVE\n" );
1019 case TEL_SHAPE_CONVEX:
1020 fprintf( stdout, "\t\tShape Flag : CONVEX\n" );
1024 switch( p->facet_flag )
1028 fprintf( stdout, "\t\tFacet Flag : COLOUR\n" );
1030 fprintf( stdout, "\t\tFacet Flag : NONE\n" );
1035 fprintf( stdout, "\t\tFacet Flag : COLOURNORMAL\n" );
1037 fprintf( stdout, "\t\tFacet Flag : NORMAL\n" );
1040 switch( p->vertex_flag )
1044 fprintf( stdout, "\t\tVertex Flag : COLOUR\n" );
1046 fprintf( stdout, "\t\tVertex Flag : NONE\n" );
1051 fprintf( stdout, "\t\tVertex Flag : COLOURNORMAL\n" );
1053 fprintf( stdout, "\t\tVertex Flag : NORMAL\n" );
1056 fprintf( stdout, "\t\tFacet Normal : %g %g %g\n", p->fnormal.xyz[0],
1058 p->fnormal.xyz[2] );
1059 fprintf( stdout, "\t\tReverse order : %d\n", p->reverse_order);
1062 fprintf( stdout, "\t\tFacet Colour : %g %g %g\n", p->fcolour->rgb[0],
1064 p->fcolour->rgb[2] );
1066 fprintf( stdout, "\n\t\tFacet Colour not specified\n" );
1070 fprintf( stdout, "\n\t\tVertices : " );
1071 for( i = 0; i < p->num_vertices; i++ )
1072 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
1073 p->vertices[i].xyz[0],
1074 p->vertices[i].xyz[1],
1075 p->vertices[i].xyz[2] );
1078 fprintf( stdout, "\n" );
1081 fprintf( stdout, "\n\t\tVertex Colours : " );
1082 for( i = 0; i < p->num_vertices; i++ )
1083 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
1084 p->vcolours[i].rgb[0],
1085 p->vcolours[i].rgb[1],
1086 p->vcolours[i].rgb[2] );
1089 fprintf( stdout, "\n\t\tVertex Colours not specified\n" );
1093 fprintf( stdout, "\n\t\tVertex Normals : " );
1094 for( i = 0; i < p->num_vertices; i++ )
1095 fprintf( stdout, "\n\t\t v[%d] = %g %g %g", i,
1096 p->vnormals[i].xyz[0],
1097 p->vnormals[i].xyz[1],
1098 p->vnormals[i].xyz[2] );
1101 fprintf( stdout, "\n\t\tVertex Normals not specified\n" );
1103 if (p->vtexturecoord)
1105 fprintf(stdout, "\n\t\tTexture Coordinates : ");
1106 for (i=0; i<p->num_vertices; i++)
1107 fprintf(stdout, "\n\t\t v[%d] = %g %g", i,
1108 p->vtexturecoord[i].xy[0],
1109 p->vtexturecoord[i].xy[1]);
1112 fprintf( stdout, "\n\t\tTexture Coordinates not specified\n");
1114 fprintf( stdout, "\n" );
1119 /*----------------------------------------------------------------------*/
1122 PolygonInquire( TSM_ELEM_DATA data, Tint n, cmn_key *k )
1127 TStatus status = TSuccess;
1130 d = (tel_polygon_data)data.pdata;
1133 size_reqd += sizeof( TEL_COLOUR );
1135 if( d->facet_flag == TEL_FA_NORMAL )
1136 size_reqd += sizeof( TEL_POINT );
1138 size_reqd += ( d->num_vertices * sizeof( TEL_POINT ) );
1141 size_reqd += ( d->num_vertices * sizeof( TEL_COLOUR ) );
1143 if( d->vertex_flag == TEL_VT_NORMAL )
1144 size_reqd += ( d->num_vertices * sizeof( TEL_POINT ) );
1146 for( i = 0; i < n; i++ )
1150 case INQ_GET_SIZE_ID:
1152 k[i]->data.ldata = size_reqd;
1156 case INQ_GET_CONTENT_ID:
1161 c = (tel_inq_content)k[i]->data.pdata;
1162 c->act_size = size_reqd;
1166 w->fillarea3data.num_points = d->num_vertices;
1167 w->fillarea3data.shpflag = d->shape_flag;
1169 if( c->size >= size_reqd )
1171 if( d->facet_flag == TEL_FA_NORMAL )
1175 w->fillarea3data.faflag = TEL_FAFLAG_COLOURNORMAL;
1176 w->fillarea3data.gnormal = (tel_point)(c->buf);
1177 *(w->fillarea3data.gnormal) = d->fnormal;
1178 w->fillarea3data.facet_colour_val =
1179 (tel_colour)(c->buf + sizeof( TEL_POINT ) );
1180 *(w->fillarea3data.facet_colour_val) = *(d->fcolour);
1181 cur_ptr = c->buf + sizeof( TEL_POINT ) +
1182 sizeof( TEL_COLOUR );
1186 w->fillarea3data.faflag = TEL_FAFLAG_NORMAL;
1187 w->fillarea3data.facet_colour_val = 0;
1188 w->fillarea3data.gnormal = (tel_point)(c->buf);
1189 *(w->fillarea3data.gnormal) = d->fnormal;
1190 cur_ptr = c->buf + sizeof( TEL_POINT );
1195 w->fillarea3data.gnormal = 0;
1198 w->fillarea3data.faflag = TEL_FAFLAG_COLOUR;
1199 w->fillarea3data.facet_colour_val = (tel_colour)(c->buf );
1200 *(w->fillarea3data.facet_colour_val) = *(d->fcolour);
1201 cur_ptr = c->buf + sizeof( TEL_COLOUR );
1205 w->fillarea3data.faflag = TEL_FAFLAG_NONE;
1206 w->fillarea3data.facet_colour_val = 0;
1210 w->fillarea3data.points = (tel_point)cur_ptr;
1211 for( j = 0; j < d->num_vertices; j++ )
1213 w->fillarea3data.points[j] = d->vertices[j];
1215 cur_ptr += ( d->num_vertices * sizeof( TEL_POINT ) );
1217 if( d->vertex_flag == TEL_VT_NORMAL )
1221 w->fillarea3data.vrtflag = TEL_VTFLAG_COLOURNORMAL;
1222 w->fillarea3data.vnormals = (tel_point)(cur_ptr);
1223 for( j = 0; j < d->num_vertices; j++ )
1225 w->fillarea3data.vnormals[j] = d->vnormals[i];
1227 cur_ptr += ( d->num_vertices * sizeof( TEL_POINT ) );
1229 w->fillarea3data.colours = (tel_colour)(cur_ptr);
1231 for( j = 0; j < d->num_vertices; j++ )
1233 w->fillarea3data.colours[j] = d->vcolours[i];
1238 w->fillarea3data.vrtflag = TEL_VTFLAG_NORMAL;
1239 w->fillarea3data.colours = 0;
1240 w->fillarea3data.vnormals = (tel_point)(cur_ptr);
1242 for( j = 0; j < d->num_vertices; j++ )
1244 w->fillarea3data.vnormals[j] = d->vnormals[i];
1250 w->fillarea3data.vnormals = 0;
1253 w->fillarea3data.vrtflag = TEL_VTFLAG_COLOUR;
1254 w->fillarea3data.colours = (tel_colour)(cur_ptr);
1255 for( j = 0; j < d->num_vertices; j++ )
1257 w->fillarea3data.colours[j] = d->vcolours[i];
1262 w->fillarea3data.vrtflag = TEL_VTFLAG_NONE;
1263 w->fillarea3data.colours = 0;
1277 /*----------------------------------------------------------------------*/
1280 draw_edges( tel_polygon_data p, tel_colour edge_colour, Tint interior_style )
1282 CMN_KEY k, k1, k2, k3, k4;
1285 Tint edge_type, line_type_preserve;
1286 Tfloat edge_width, line_width_preserve;
1287 GLboolean texture_on;
1289 if (interior_style != TSM_HIDDENLINE)
1292 TsmGetAttri( 1, &k );
1293 if( k.data.ldata == TOff )return;
1299 texture_on = IsTextureEnabled();
1300 if (texture_on) DisableTexture();
1302 k1.id = TelPolylineWidth;
1303 k2.id = TelPolylineType;
1304 k3.id = TelEdgeType;
1305 k4.id = TelEdgeWidth;
1307 TsmGetAttri( 4, &k1, &k2, &k3, &k4 );
1309 line_width_preserve = k1.data.fdata;
1310 line_type_preserve = k2.data.ldata;
1311 edge_type = k3.data.ldata;
1312 edge_width = k4.data.fdata;
1314 if( line_width_preserve != edge_width )
1316 k.id = TelPolylineWidth;
1317 k.data.fdata = edge_width;
1318 TsmSetAttri( 1, &k );
1320 if( line_type_preserve != edge_type )
1322 k.id = TelPolylineType;
1323 k.data.ldata = edge_type;
1324 TsmSetAttri( 1, &k );
1327 glColor3fv( edge_colour->rgb );
1329 glBegin(GL_LINE_LOOP);
1330 for( i=0; i<p->num_vertices; i++, ptr++ )
1332 glVertex3fv( ptr->xyz );
1336 if( line_width_preserve != edge_width )
1338 k.id = TelPolylineWidth;
1339 k.data.fdata = line_width_preserve;
1340 TsmSetAttri( 1, &k );
1342 if( line_type_preserve != edge_type )
1344 k.id = TelPolylineType;
1345 k.data.ldata = line_type_preserve;
1346 TsmSetAttri( 1, &k );
1349 if (texture_on) EnableTexture();
1351 /*----------------------------------------------------------------------*/