OCC22391 Polylines arrays not drawn for mesh with VBO flag enabled
[occt.git] / src / OpenGl / OpenGl_togl_begin_layer_mode.cxx
1 /***********************************************************************
2
3 FONCTION :
4 ----------
5 file OpenGl_togl_begin_layer_mode.c :
6
7 REMARQUES:
8 ----------
9
10 HISTORIQUE DES MODIFICATIONS   :
11 --------------------------------
12 01-12-98 : CAL ; Creation. S4062. Ajout des layers.
13 02.14.100 : JR : Warnings on WNT truncations from double to float
14
15 ************************************************************************/
16
17 /*----------------------------------------------------------------------*/
18 /*
19 * Includes
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #ifdef HAVE_STDLIB_H
26 #include <stdlib.h>
27 #endif
28 #if defined(HAVE_MALLOC_H) || defined(WNT)
29 #include <malloc.h>
30 #endif
31
32 #include <OpenGl_tgl_all.hxx>
33
34 #include <math.h>
35 #include <GL/gl.h>
36 #include <stdio.h>
37
38 #include <InterfaceGraphic_Labels.hxx>
39 #include <InterfaceGraphic_Graphic3d.hxx>
40 #include <InterfaceGraphic_Visual3d.hxx>
41
42 #include <OpenGl_tsm_ws.hxx>
43 #include <OpenGl_txgl.hxx>
44 #include <OpenGl_tgl_tox.hxx>
45 #include <OpenGl_tgl_funcs.hxx>
46 #include <OpenGl_telem_filters.hxx>
47 #include <OpenGl_telem.hxx>
48 #include <OpenGl_telem_util.hxx>
49 #include <OpenGl_telem_view.hxx>
50
51 #include <OpenGl_TextRender.hxx>
52
53 /*OCC6247*/
54 #include <OpenGl_telem_attri.hxx>
55 #include <OpenGl_LightBox.hxx>
56
57 #include <Visual3d_Layer.hxx>
58
59 #include <OpenGl_Extension.hxx>
60
61 /*----------------------------------------------------------------------*/
62 /*
63 * Constantes
64 */
65
66 #define NO_PRINT
67 #define NOTRACE
68 #define NO_DEBUG
69 #define NO_TRACE_MAT
70 #define NO_TRACE_TEXT
71
72 #define IsNotModified 0
73 #define IsModified 1
74
75 /*----------------------------------------------------------------------*/
76 /*
77 * Variables externes
78 */
79
80 extern GLuint linestyleBase;
81 extern GLuint fontBase;
82
83 #if defined(__sun)  || defined (__osf__) || defined (__hp) || defined (__sgi)
84 #else
85 extern PFNGLBLENDEQUATIONEXTPROC glBlendEquationOp;
86 #endif
87 /*----------------------------------------------------------------------*/
88 /*
89 * Prototypes fonctions
90 */
91
92 /*----------------------------------------------------------------------*/
93 /*
94 * Prototypes Private functions
95 */
96
97 /*----------------------------------------------------------------------*/
98 /*
99 * Variables statiques
100 */
101
102 static CALL_DEF_LAYER ACLayer;
103
104 static GLboolean layerOpen      = GL_FALSE;
105 static float     layerHeight    = -1.;
106 static float     layerWidth     = -1.;
107 static int       layerPoints    = 0;
108 static Tchar    *layerFont      = NULL;
109 static int       layerType      = -1;
110 static int       layerFontFlag  = IsModified;
111 static int       layerFontType  = 0;
112 static float     layerRed       = -1.;
113 static float     layerGreen     = -1.;
114 static float     layerBlue      = -1.;
115 static float     layerFontRed   = -1.;
116 static float     layerFontGreen = -1.;
117 static float     layerFontBlue  = -1.;
118
119
120 static OSD_FontAspect FTGLLayerFontAspect = OSD_FA_Regular;
121 static Tint           FTGLLayerFontHeight = 16;
122 static Tint           FTGLLayerFontAscent = 0;
123 static Tint           FTGLLayerFontDescent = 0;
124 static Tint           FTGLLayerFontWidth = 0;
125 static Tfloat         FTGLLayerFontXScale = 1.f;
126 static Tfloat         FTGLLayerFontYScale = 1.f;
127 static Tchar          FTGLLayerFontName[100];
128 static Tint           FTGLLayerFontCurrent = 0;
129
130 /*----------------------------------------------------------------------*/
131 void EXPORT
132 call_togl_layer2d
133 (
134  CALL_DEF_LAYER * alayer
135  )
136 {
137   //call_def_ptrLayer ptrLayer;
138
139 #ifdef PRINT
140   printf ("call_togl_layer2d\n");
141 #endif
142   alayer->ptrLayer = (call_def_ptrLayer) malloc (sizeof (CALL_DEF_PTRLAYER)); 
143   alayer->ptrLayer->listIndex = glGenLists (1);
144   ACLayer = *alayer;
145 }
146
147 /*----------------------------------------------------------------------*/
148 void EXPORT
149 call_togl_removelayer2d
150 (
151  CALL_DEF_LAYER * alayer
152  )
153 {
154   if (alayer->ptrLayer == NULL) return;
155   if (alayer->ptrLayer->listIndex == 0) return;
156 #ifdef PRINT
157   printf ("call_togl_removelayer2d %d\n", ptrLayer->listIndex);
158 #endif
159
160   /*
161   * On detruit la display-list associee au layer.
162   */
163   glDeleteLists (alayer->ptrLayer->listIndex, 1);
164   alayer->ptrLayer->listIndex = 0;
165   ACLayer = *alayer;
166 }
167
168 /*----------------------------------------------------------------------*/
169 void EXPORT
170 call_togl_clear_layer2d (
171                          CALL_DEF_LAYER * aLayer
172                          )
173 {
174   if (aLayer->ptrLayer == NULL) return;
175   if (aLayer->ptrLayer->listIndex == 0) return;
176 #ifdef PRINT
177   printf ("call_togl_clear_layer2d %d\n", ptrLayer->listIndex);
178 #endif
179
180   /*
181   * On clear la display-list associee au layer.
182   */
183   /*
184   * On detruit la display-list associee au layer.
185   */
186   glDeleteLists (aLayer->ptrLayer->listIndex, 1);
187   aLayer->ptrLayer->listIndex = 0;
188   /*
189   * On cree la display-list associee au layer.
190   */
191   aLayer->ptrLayer->listIndex = glGenLists (1);
192   //alayer->ptrLayer = /*(void *) */ptrLayer;
193   ACLayer = *aLayer;
194 }
195
196 /*----------------------------------------------------------------------*/
197 void EXPORT
198 call_togl_redraw_layer2d (
199                           CALL_DEF_VIEW * aview,
200                           CALL_DEF_LAYER * alayer
201                           )
202 {
203   float left, right, bottom, top;
204   float delta, ratio;
205   int attach;
206 #ifdef TRACE_MAT
207   GLdouble modelMatrix[16], projMatrix[16];
208   GLint viewport[4];
209   int i, j;
210 #endif
211   GLsizei dispWidth, dispHeight;
212   GLboolean isl = IsLightOn(); /*OCC6247*/
213
214   if ( aview->DefBitmap.bitmap ) {
215     dispWidth = aview->DefBitmap.width;
216     dispHeight = aview->DefBitmap.height;
217   }
218   else {
219     dispWidth = (GLsizei) alayer->viewport[0];
220     dispHeight = (GLsizei) alayer->viewport[1];
221   }
222
223   if (alayer->ptrLayer == NULL) return;
224   if (alayer->ptrLayer->listIndex == 0) return;
225 #ifdef PRINT
226   printf ("call_togl_redraw_layer2d %d\n", ptrLayer->listIndex);
227   printf ("\twindow size %f %f\n",
228     aview->DefWindow.dx, aview->DefWindow.dy);
229   printf ("\tviewport %f %f\n", (float) dispWidth, (float) dispHeight);
230 #endif
231
232   if(isl) {
233     LightOff(); /*OCC6247*/
234   }
235
236   /*
237   * On positionne la projection
238   */
239   glMatrixMode( GL_MODELVIEW );
240   glPushMatrix ();
241   glLoadIdentity ();
242
243   glMatrixMode (GL_PROJECTION);
244   glPushMatrix ();
245   glLoadIdentity ();
246
247   if (alayer->sizeDependent == 0)
248     glViewport (0, 0, dispWidth, dispHeight);
249
250   left = alayer->ortho[0],
251     right = alayer->ortho[1],
252     bottom = alayer->ortho[2],
253     top = alayer->ortho[3];
254   attach = alayer->attach;
255 #ifdef TRACE
256   printf ("\tattach %d ortho %f %f %f %f %d\n",
257     attach, left, right, bottom, top);
258 #endif
259   if (alayer->sizeDependent == 0)
260     ratio = (float) dispWidth/dispHeight;
261   else
262     ratio = aview->DefWindow.dx/aview->DefWindow.dy;
263   if (ratio >= 1.0) { /* fenetre horizontale */
264     delta = (float )((top - bottom)/2.0);
265     switch (attach) {
266       case 0: /* Aspect_TOC_BOTTOM_LEFT */
267         top = bottom + 2*delta/ratio;
268         break;
269       case 1: /* Aspect_TOC_BOTTOM_RIGHT */
270         top = bottom + 2*delta/ratio;
271         break;
272       case 2: /* Aspect_TOC_TOP_LEFT */
273         bottom = top - 2*delta/ratio;
274         break;
275       case 3: /* Aspect_TOC_TOP_RIGHT */
276         bottom = top - 2*delta/ratio;
277         break;
278     }
279   }
280   else { /* fenetre verticale */
281     delta = (float )((right - left)/2.0);
282     switch (attach) {
283       case 0: /* Aspect_TOC_BOTTOM_LEFT */
284         right = left + 2*delta*ratio;
285         break;
286       case 1: /* Aspect_TOC_BOTTOM_RIGHT */
287         left = right - 2*delta*ratio;
288         break;
289       case 2: /* Aspect_TOC_TOP_LEFT */
290         right = left + 2*delta*ratio;
291         break;
292       case 3: /* Aspect_TOC_TOP_RIGHT */
293         left = right - 2*delta*ratio;
294         break;
295     }
296   }
297 #ifdef TRACE
298   printf ("\tratio %f new ortho %f %f %f %f\n",
299     ratio, left, right, bottom, top);
300 #endif
301   glOrtho (left, right, bottom, top, -1.0, 1.0);
302
303 #ifdef TRACE_MAT
304   glGetIntegerv (GL_VIEWPORT, viewport);
305   glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
306   glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
307   printf ("viewport :\n");
308   printf ("\t");
309   for (i = 0; i < 4; i++)
310     printf ("%d ", viewport[i]);
311   printf ("\n");
312   printf ("modelMatrix :\n");
313   for (i = 0; i < 4; i++) {
314     printf ("\t");
315     for (j = 0; j < 4; j++)
316       printf ("%f ", modelMatrix[i*4+j]);
317     printf ("\n");
318   }
319   printf ("projMatrix :\n");
320   for (i = 0; i < 4; i++) {
321     printf ("\t");
322     for (j = 0; j < 4; j++)
323       printf ("%f ", projMatrix[i*4+j]);
324     printf ("\n");
325   }
326 #endif
327
328   /*
329   * On trace la display-list associee au layer.
330   */
331 #ifdef TRACE
332   if (glIsList (alayer->ptrLayer->listIndex))
333     printf ("\t%d is a list\n", alayer->ptrLayer->listIndex);
334   else
335     printf ("\t%d is not a list\n", alayer->ptrLayer->listIndex);
336 #endif
337   glPushAttrib (
338     GL_LIGHTING_BIT | GL_LINE_BIT | GL_POLYGON_BIT |
339     GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT);
340   glDisable (GL_DEPTH_TEST);
341   glCallList (alayer->ptrLayer->listIndex);
342
343
344   //calling dynamic render of LayerItems
345   if ( alayer->ptrLayer->layerData ) {
346     ACLayer = *alayer;
347     Visual3d_Layer* layer = (Visual3d_Layer*)alayer->ptrLayer->layerData;
348     layer->RenderLayerItems();
349     ACLayer.ptrLayer = NULL;
350   }
351
352
353   glPopAttrib ();
354
355   /*
356   * On retire la projection
357   */
358   glMatrixMode (GL_PROJECTION);
359   glPopMatrix ();
360
361   glMatrixMode( GL_MODELVIEW );
362   glPopMatrix ();
363
364   /*
365   * Restauration du Viewport en cas de modification
366   */
367   if (alayer->sizeDependent == 0) 
368     glViewport (0, 0,
369     (GLsizei) aview->DefWindow.dx,
370     (GLsizei) aview->DefWindow.dy);
371
372   glFlush ();
373
374   if(isl) {
375     LightOn(); /*OCC6247*/
376   }
377
378 }
379
380 /*----------------------------------------------------------------------*/
381 void EXPORT
382 call_togl_begin_layer2d
383 (
384  CALL_DEF_LAYER * alayer
385  )
386 {
387   call_def_ptrLayer ptrLayer;
388
389   ACLayer = *alayer;
390
391   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
392   if (ptrLayer == NULL) return;
393   if (ptrLayer->listIndex == 0) return;
394 #ifdef PRINT
395   printf ("call_togl_begin_layer2d %d\n", ptrLayer->listIndex);
396 #endif
397
398   //abd
399   glEnable(GL_TEXTURE_2D);
400   GLboolean stat = glIsEnabled( GL_TEXTURE_2D );
401
402   glNewList (ptrLayer->listIndex, GL_COMPILE);
403   layerOpen = GL_TRUE;
404 }
405
406 /*----------------------------------------------------------------------*/
407 void EXPORT
408 call_togl_end_layer2d
409 (
410  )
411 {
412   call_def_ptrLayer ptrLayer;
413
414   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
415   if (ptrLayer == NULL) return;
416   if (ptrLayer->listIndex == 0) return;
417 #ifdef PRINT
418   printf ("call_togl_end_layer2d %d\n", ptrLayer->listIndex);
419 #endif
420
421   /*
422   * On ferme la display-list associee au layer.
423   */
424   if (layerOpen) 
425     glEndList ();
426   layerOpen = GL_FALSE;
427
428   ACLayer.ptrLayer = NULL;
429 }
430
431 /*----------------------------------------------------------------------*/
432 void EXPORT
433 call_togl_begin_polyline2d (
434                             )
435 {
436   call_def_ptrLayer ptrLayer;
437
438   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
439   if (ptrLayer == NULL) return;
440   if (ptrLayer->listIndex == 0) return;
441 #ifdef PRINT
442   printf ("call_togl_begin_polyline2d %d\n", ptrLayer->listIndex);
443 #endif
444
445   layerPoints = 0;
446   glBegin (GL_LINE_STRIP);
447 }
448
449 /*----------------------------------------------------------------------*/
450 void EXPORT
451 call_togl_end_polyline2d (
452                           )
453 {
454   call_def_ptrLayer ptrLayer;
455
456   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
457   if (ptrLayer == NULL) return;
458   if (ptrLayer->listIndex == 0) return;
459 #ifdef PRINT
460   printf ("call_togl_end_polyline2d %d\n", ptrLayer->listIndex);
461 #endif
462
463   glEnd ();
464 }
465
466 /*----------------------------------------------------------------------*/
467 void EXPORT
468 call_togl_begin_polygon2d (
469                            )
470 {
471   call_def_ptrLayer ptrLayer;
472
473   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
474   if (ptrLayer == NULL) return;
475   if (ptrLayer->listIndex == 0) return;
476 #ifdef PRINT
477   printf ("call_togl_begin_polygon2d %d\n", ptrLayer->listIndex);
478 #endif
479
480   layerPoints = 0;
481   glBegin (GL_POLYGON);
482 }
483
484 /*----------------------------------------------------------------------*/
485 void EXPORT
486 call_togl_end_polygon2d (
487                          )
488 {
489   call_def_ptrLayer ptrLayer;
490
491   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
492   if (ptrLayer == NULL) return;
493   if (ptrLayer->listIndex == 0) return;
494 #ifdef PRINT
495   printf ("call_togl_end_polygon2d %d\n", ptrLayer->listIndex);
496 #endif
497
498   glEnd ();
499 }
500
501 /*----------------------------------------------------------------------*/
502 void EXPORT
503 call_togl_edge2d (
504                   float x,
505                   float y
506                   )
507 {
508   call_def_ptrLayer ptrLayer;
509
510   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
511   if (ptrLayer == NULL) return;
512   if (ptrLayer->listIndex == 0) return;
513 #ifdef PRINT
514   printf ("call_togl_edge2d %d\n", ptrLayer->listIndex);
515   printf ("\tcoord %f %f\n", x, y);
516 #endif
517
518   layerPoints ++;
519   glVertex3f (x, y, 0.);
520 }
521
522 /*----------------------------------------------------------------------*/
523 void EXPORT
524 call_togl_draw2d
525 (
526  float x,
527  float y
528  )
529 {
530   call_def_ptrLayer ptrLayer;
531
532   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
533   if (ptrLayer == NULL) return;
534   if (ptrLayer->listIndex == 0) return;
535 #ifdef PRINT
536   printf ("call_togl_draw2d %d\n", ptrLayer->listIndex);
537   printf ("\tcoord %f %f\n", x, y);
538 #endif
539
540   layerPoints ++;
541   glVertex3f (x, y, 0.);
542 }
543
544 /*----------------------------------------------------------------------*/
545 void EXPORT
546 call_togl_move2d
547 (
548  float x,
549  float y
550  )
551 {
552   call_def_ptrLayer ptrLayer;
553
554   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
555   if (ptrLayer == NULL) return;
556   if (ptrLayer->listIndex == 0) return;
557 #ifdef PRINT
558   printf ("call_togl_move2d %d\n", ptrLayer->listIndex);
559   printf ("\tcoord %f %f\n", x, y);
560 #endif
561
562   if (layerPoints != 0) {
563     call_togl_end_polyline2d ();
564     call_togl_begin_polyline2d ();
565   }
566
567   layerPoints ++;
568   glVertex3f (x, y, 0.);
569 }
570
571 /*----------------------------------------------------------------------*/
572 void EXPORT
573 call_togl_rectangle2d
574 (
575  float x,
576  float y,
577  float w,
578  float h
579  )
580 {
581   call_def_ptrLayer ptrLayer;
582
583   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
584   if (ptrLayer == NULL) return;
585   if (ptrLayer->listIndex == 0) return;
586 #ifdef PRINT
587   printf ("call_togl_rectangle2d %d\n", ptrLayer->listIndex);
588   printf ("\trectangle %f %f %f %f\n", x, y, w, h);
589 #endif
590
591   glRectf (x, y, x + w, y + h);
592 }
593
594 /*----------------------------------------------------------------------*/
595 void EXPORT
596 call_togl_text2d ( char *s,
597                   float x,
598                   float y,
599                   float height )
600 {
601   call_def_ptrLayer ptrLayer;
602 #ifndef WNT
603   Tint dispWidth, dispHeight;
604 #endif
605   GLdouble objx1, objy1, objz1;
606
607   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
608   if (ptrLayer == NULL) return;
609   if (ptrLayer->listIndex == 0) return;
610 #ifdef TRACE_TEXT
611   printf ("call_togl_text2d %d\n", ptrLayer->listIndex);
612   printf ("\ttext %s %f %f %f\n", s, x, y, height);
613 #endif
614
615   OpenGl_TextRender* textRender=OpenGl_TextRender::instance();
616
617   FTGLLayerFontCurrent = textRender->FindFont( FTGLLayerFontName,
618                                                FTGLLayerFontAspect,
619                                                FTGLLayerFontHeight,
620                                                FTGLLayerFontXScale,
621                                                FTGLLayerFontYScale );
622
623   objx1 = x,
624   objy1 = y,
625   objz1 = 0.0;
626
627   /*
628   * On traite les differents types d'affichage de texte
629   */
630   switch (layerFontType) {
631   case 0 : /* Aspect_TODT_Normal */
632 #ifdef DEBUG
633     printf ("---------------------\n");
634     printf ("texte normal %f %f\n", objx1, objy1);
635 #endif
636
637     textRender->RenderText(s , fontBase, 1, (float )objx1, (float )objy1, 0.f );
638
639     break;
640   case 1 : /* Aspect_TODT_SubTitle */
641 #ifdef OK
642 #ifdef DEBUG
643     printf ("---------------------\n");
644     printf ("texte subtitle %f %f\n", objx1, objy1);
645 #endif
646     glGetIntegerv (GL_VIEWPORT, viewport);
647     glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
648     glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
649 #ifdef TRACE_MAT
650     printf ("viewport :\n");
651     printf ("\t");
652     for (i = 0; i < 4; i++)
653       printf ("%d ", viewport[i]);
654     printf ("\n");
655     printf ("modelMatrix :\n");
656     for (i = 0; i < 4; i++) {
657       printf ("\t");
658       for (j = 0; j < 4; j++)
659         printf ("%f ", modelMatrix[i*4+j]);
660       printf ("\n");
661     }
662     printf ("projMatrix :\n");
663     for (i = 0; i < 4; i++) {
664       printf ("\t");
665       for (j = 0; j < 4; j++)
666         printf ("%f ", projMatrix[i*4+j]);
667       printf ("\n");
668     }
669 #endif
670     /*
671     * dimensionString("Methode cadre", &sWidth, &sAscent, &sDescent);
672     */
673     sWidth = 2.;
674     sAscent = .2;
675     sDescent = .2;
676
677     objx2 = objx1; objy2 = objy1; objz2 = objz1;
678     objx3 = objx1; objy3 = objy1; objz3 = objz1;
679     objx4 = objx1; objy4 = objy1; objz4 = objz1;
680     objx5 = objx1; objy5 = objy1; objz5 = objz1;
681
682     status = gluProject (objx1, objy1, objz1,
683                          modelMatrix, projMatrix, viewport,
684                          &winx1, &winy1, &winz1);
685
686     winx2 = winx1;
687     winy2 = winy1-sDescent;
688     winz2 = winz1+0.00001;
689     status = gluUnProject (winx2, winy2, winz2,
690                            modelMatrix, projMatrix, viewport,
691                            &objx2, &objy2, &objz2);
692
693     winx2 = winx1 + sWidth;
694     winy2 = winy1-sDescent;
695     winz2 = winz1+0.00001; /* il vaut mieux F+B / 1000000 ? */
696     status = gluUnProject (winx2, winy2, winz2,
697                            modelMatrix, projMatrix, viewport,
698                            &objx3, &objy3, &objz3);
699
700     winx2 = winx1 + sWidth;
701     winy2 = winy1 + sAscent;
702     winz2 = winz1+0.00001;
703     status = gluUnProject (winx2, winy2, winz2,
704                            modelMatrix, projMatrix, viewport,
705                            &objx4, &objy4, &objz4);
706
707     winx2 = winx1;
708     winy2 = winy1+ sAscent;
709     winz2 = winz1+0.00001;
710     status = gluUnProject (winx2, winy2, winz2,
711                            modelMatrix, projMatrix, viewport,
712                            &objx5, &objy5, &objz5);
713
714     glColor3f (layerFontRed, layerFontGreen, layerFontBlue);
715     glBegin(GL_POLYGON);
716     glVertex3d(objx2, objy2, objz2);
717     glVertex3d(objx3, objy3, objz3);
718     glVertex3d(objx4, objy4, objz4);
719     glVertex3d(objx5, objy5, objz5);
720     glEnd();
721     glColor3f (layerRed, layerGreen, layerBlue);
722 #endif /* OK */
723
724
725     textRender->RenderText(s, fontBase, 1, (float )objx1, (float )objy1, 0.f); 
726
727     break;
728   case 2 : /* Aspect_TODT_Dekale */
729 #ifdef OK
730 #ifdef DEBUG
731     printf ("---------------------\n");
732     printf ("texte dekale %f %f\n", objx1, objy1);
733 #endif
734     glGetIntegerv (GL_VIEWPORT, viewport);
735     glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
736     glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
737 #ifdef DEBUG
738     printf ("viewport :\n");
739     printf ("\t");
740     for (i = 0; i < 4; i++)
741       printf ("%d ", viewport[i]);
742     printf ("\n");
743     printf ("modelMatrix :\n");
744     for (i = 0; i < 4; i++) {
745       printf ("\t");
746       for (j = 0; j < 4; j++)
747         printf ("%f ", modelMatrix[i*4+j]);
748       printf ("\n");
749     }
750     printf ("projMatrix :\n");
751     for (i = 0; i < 4; i++) {
752       printf ("\t");
753       for (j = 0; j < 4; j++)
754         printf ("%f ", projMatrix[i*4+j]);
755       printf ("\n");
756     }
757 #endif
758     status = gluProject (objx1, objy1, objz1,
759       modelMatrix, projMatrix, viewport,
760       &winx1, &winy1, &winz1);
761 #ifdef DEBUG
762     printf ("status %s\n", (status == GL_FALSE ? "ko" : "ok"));
763 #endif
764     winx2 = winx1+1;
765     winy2 = winy1+1;
766     winz2 = winz1+0.00001;
767     status = gluUnProject (winx2, winy2, winz2,
768       modelMatrix, projMatrix, viewport,
769       &objx2, &objy2, &objz2);
770 #ifdef DEBUG
771     printf ("status %s\n", (status == GL_FALSE ? "ko" : "ok"));
772 #endif
773     glColor3f (layerFontRed, layerFontGreen, layerFontBlue);
774
775
776     OpenGl_TextRender* textRender=OpenGl_TextRender::instance();
777     textRender->RenderText(s, fontBase, 1, objx2, objy2, 0.f);
778
779
780     winx2 = winx1-1;
781     winy2 = winy1-1;
782     winz2 = winz1+0.00001;
783     status = gluUnProject (winx2, winy2, winz2,
784       modelMatrix, projMatrix, viewport,
785       &objx2, &objy2, &objz2);
786 #ifdef DEBUG
787     printf ("status %s\n", (status == GL_FALSE ? "ko" : "ok"));
788 #endif
789
790     textRender->RenderText(s, fontBase, 1, objx2, objy2, 0.f);
791
792
793     winx2 = winx1-1;
794     winy2 = winy1+1;
795     winz2 = winz1+0.00001;
796     status = gluUnProject (winx2, winy2, winz2,
797       modelMatrix, projMatrix, viewport,
798       &objx2, &objy2, &objz2);
799 #ifdef DEBUG
800     printf ("status %s\n", (status == GL_FALSE ? "ko" : "ok"));
801 #endif
802
803
804     textRender->RenderText(s, fontBase, 1, objx2, objy2, 0.f);
805
806     winx2 = winx1+1;
807     winy2 = winy1-1;
808     winz2 = winz1+0.00001;
809     status = gluUnProject (winx2, winy2, winz2,
810       modelMatrix, projMatrix, viewport,
811       &objx2, &objy2, &objz2);
812 #ifdef DEBUG
813     printf ("status %s\n", (status == GL_FALSE ? "ko" : "ok"));
814 #endif
815
816     textRender->RenderText(s, fontBase, 1, objx2, objy2, 0.f);
817
818     glColor3f (layerRed, layerGreen, layerBlue);
819 #endif /* OK */
820
821     textRender->RenderText(s, fontBase, 1, (float )objx1, (float )objy1, 0.f);
822
823 #ifdef DEBUG
824     printf ("---------------------\n");
825 #endif
826     break;
827   case 3 : /* Aspect_TODT_Blend */
828 #ifdef OK
829 #ifndef WNT
830 #ifndef __sun
831     if ( (PFNGLBLENDEQUATIONEXTPROC)glBlendEquationOp == (PFNGLBLENDEQUATIONEXTPROC)INVALID_EXT_FUNCTION_PTR )
832     {
833       if(QueryExtension("GL_EXT_blend_logic_op"))   
834         glBlendEquationOp = (PFNGLBLENDEQUATIONEXTPROC)glXGetProcAddress((GLubyte*)"glBlendEquationOp");
835       else
836         glBlendEquationOp = NULL;
837     }
838
839     if ( glBlendEquationOp )
840 #endif //__sun
841     {
842       glEnable(GL_BLEND);
843 #ifndef __sun
844       glBlendEquationOp(GL_LOGIC_OP);
845 #else
846       glBlendEquation(GL_LOGIC_OP);
847 #endif //__sun
848       glLogicOp(GL_XOR); 
849       glColor3f (layerRed, layerGreen, layerBlue);
850       glRasterPos2f (objx1, objy1);             
851       glDisable (GL_BLEND);
852     }
853 #else
854     glColor3f (layerRed, layerGreen, layerBlue);
855
856     textRender->RenderText(s, fontBase, 1, (float )objx1, (float )objy1, 0.f);
857
858
859 #endif //WNT
860
861 #else /* OK */
862 #ifdef DEBUG
863     printf ("---------------------\n");
864     printf ("texte blend %f %f\n", objx1, objy1);
865 #endif
866
867     textRender->RenderText(s, fontBase, 1, (float )objx1, (float )objy1, 0.f);
868
869 #ifdef DEBUG
870     printf ("---------------------\n");
871 #endif
872 #endif /* OK */
873     break;
874   }
875 }
876
877 void EXPORT
878 call_togl_textsize2d
879 (
880  char *s,
881  float height,
882  float *width,
883  float *ascent,
884  float *descent
885  )
886 {
887   call_def_ptrLayer ptrLayer;
888 #ifndef WNT
889   Tint dispWidth, dispHeight;
890 #endif
891
892
893   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
894   if (ptrLayer == NULL) return;
895   if (ptrLayer->listIndex == 0) return;
896
897
898   if ( FTGLLayerFontHeight != height || layerFontFlag == IsModified || FTGLLayerFontCurrent == 0 ) {
899     layerFontFlag = IsNotModified;
900     FTGLLayerFontHeight = height;  
901     OpenGl_TextRender*  textRender =  OpenGl_TextRender::instance();
902     FTGLLayerFontCurrent = textRender -> FindFont(FTGLLayerFontName, FTGLLayerFontAspect, FTGLLayerFontHeight);
903     textRender -> StringSize(s, &FTGLLayerFontWidth, &FTGLLayerFontAscent, &FTGLLayerFontDescent);
904   }
905
906   
907   *width = (float) FTGLLayerFontWidth;
908   *ascent = (float) FTGLLayerFontAscent;
909   *descent = (float) FTGLLayerFontDescent;
910
911 }
912
913 /*----------------------------------------------------------------------*/
914 void EXPORT
915 call_togl_set_color
916 (
917  float r,
918  float g,
919  float b
920  )
921 {
922   call_def_ptrLayer ptrLayer;
923
924   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
925   if (ptrLayer == NULL) return;
926   if (ptrLayer->listIndex == 0) return;
927 #ifdef PRINT
928   printf ("call_togl_set_color %d\n", ptrLayer->listIndex);
929   printf ("\tcolor %f %f %f\n", r, g, b);
930 #endif
931
932   layerRed = r,
933     layerGreen = g,
934     layerBlue = b;
935   glColor3f (r, g, b);
936 }
937
938 /*----------------------------------------------------------------------*/
939 void EXPORT
940 call_togl_set_transparency
941 (
942  float a
943  )
944 {
945   call_def_ptrLayer ptrLayer;
946
947   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
948   if (ptrLayer == NULL) return;
949   if (ptrLayer->listIndex == 0) return;
950 #ifdef PRINT
951   printf ("call_togl_set_transparency %d\n", ptrLayer->listIndex);
952   printf ("\ttransparency %f\n", a);
953 #endif
954
955   glEnable (GL_BLEND);
956   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
957   glColor4f (layerRed, layerGreen, layerBlue, a);
958 }
959
960 /*----------------------------------------------------------------------*/
961 void EXPORT
962 call_togl_unset_transparency
963 (
964  )
965 {
966   call_def_ptrLayer ptrLayer;
967
968   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
969   if (ptrLayer == NULL) return;
970   if (ptrLayer->listIndex == 0) return;
971 #ifdef PRINT
972   printf ("call_togl_set_untransparency %d\n", ptrLayer->listIndex);
973 #endif
974
975   glDisable (GL_BLEND);
976 }
977
978 /*----------------------------------------------------------------------*/
979 void EXPORT
980 call_togl_set_line_attributes
981 (
982  long type,
983  float width
984  )
985 {
986   call_def_ptrLayer ptrLayer;
987
988   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
989   if (ptrLayer == NULL) return;
990   if (ptrLayer->listIndex == 0) return;
991 #ifdef PRINT
992   printf ("call_togl_set_line_attributes %d\n", ptrLayer->listIndex);
993   printf ("\ttype, width %d %f\n", type, width);
994 #endif
995   if (layerType != type) {
996     layerType = type;
997     if (layerType == 0) { /* TOL_SOLID */
998       glDisable (GL_LINE_STIPPLE);
999     }
1000     else {
1001       if (layerType) {
1002         glCallList (linestyleBase+layerType);
1003         glEnable (GL_LINE_STIPPLE);
1004       }
1005     }
1006   }
1007   if (layerWidth != width) {
1008     layerWidth = width;
1009     glLineWidth ((GLfloat) layerWidth);
1010   }
1011 }
1012
1013 /*----------------------------------------------------------------------*/
1014 void EXPORT
1015 call_togl_set_text_attributes
1016 (
1017  Tchar* font,
1018  long type,
1019  float r,
1020  float g,
1021  float b
1022  )
1023 {
1024   call_def_ptrLayer ptrLayer;
1025
1026   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
1027   if (ptrLayer == NULL) return;
1028   if (ptrLayer->listIndex == 0) return;
1029 #ifdef PRINT
1030   printf ("call_togl_set_text_attributes %d\n", ptrLayer->listIndex);
1031   printf ("\tfont %s type %ld\n", font, type);
1032   printf ("\tcolor %f %f %f\n", r, g, b);
1033 #endif
1034
1035   if ( strcmp( (char*)FTGLLayerFontName, (char*)font ) != 0 ) {
1036     FTGLLayerFontName[0] = '\0';
1037     strcat( (char*)FTGLLayerFontName, (char*)font );
1038     FTGLLayerFontAspect = OSD_FA_Regular;
1039
1040     OpenGl_TextRender*  textRender =  OpenGl_TextRender::instance();
1041     FTGLLayerFontCurrent = textRender -> FindFont(FTGLLayerFontName, FTGLLayerFontAspect, FTGLLayerFontHeight);
1042
1043     layerFontType = type;
1044     layerFontRed = r;
1045     layerFontGreen = g;
1046     layerFontBlue = b;         
1047     layerFontFlag = IsModified; 
1048   }
1049   else 
1050     return;                                   
1051 }
1052
1053 void call_togl_set_text_attributes( Tchar* font,
1054                                     Tint height,
1055                                     OSD_FontAspect aspect,
1056                                     float r,
1057                                     float g,
1058                                     float b )
1059 {
1060   call_def_ptrLayer ptrLayer;
1061
1062   ptrLayer = (call_def_ptrLayer) ACLayer.ptrLayer;
1063   if (ptrLayer == NULL) return;
1064   if (ptrLayer->listIndex == 0) return;
1065
1066 #ifdef PRINT
1067   printf ("call_togl_set_text_attributes %d\n", ptrLayer->listIndex);
1068   printf ("\tfont %s type \n", font);
1069   printf ("\tcolor %f %f %f\n", r, g, b);
1070 #endif
1071   /*
1072   * On gere le type de font (ASCII !)
1073   */
1074   if ( strcmp( (char*)FTGLLayerFontName, (char*)font ) != 0 &&
1075        FTGLLayerFontAspect == aspect && 
1076        FTGLLayerFontHeight == height
1077       ) 
1078   {
1079     FTGLLayerFontName[0] = '\0';
1080     strcat( (char*)FTGLLayerFontName, (char*)font );
1081     FTGLLayerFontHeight = height;
1082     FTGLLayerFontAspect = aspect;
1083     layerFontFlag = IsModified;
1084     FTGLLayerFontXScale = FTGLLayerFontYScale = 1.f;
1085     OpenGl_TextRender*  textRender =  OpenGl_TextRender::instance();
1086     FTGLLayerFontCurrent = textRender -> FindFont(FTGLLayerFontName, FTGLLayerFontAspect, FTGLLayerFontHeight);
1087    
1088     layerFontRed = r;
1089     layerFontGreen = g;
1090     layerFontBlue = b;
1091   }
1092
1093 }
1094