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