1 /***********************************************************************
5 File OpenGl_telem_util :
12 HISTORIQUE DES MODIFICATIONS :
13 --------------------------------
14 xx-xx-xx : xxx ; Creation.
15 07-02-96 : FMN ; - Ajout trace
16 - Suppression code inutile
17 08-03-96 : FMN ; - Ajout include manquant
18 01-04-96 : CAL ; Integration MINSK portage WNT
19 15-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH
20 22-04-96 : FMN ; Ajout TelReadImage TelDrawImage
21 10-05-96 : CAL ; Ajout d'un nouveau delta dans les copies
22 de pixels (voir CALL_DEF_DELTA)
23 25-06-96 : FMN ; Suppression utilisation de glScissor.
24 02-07-96 : FMN ; Suppression WSWSHeight et WSWSWidth
25 Suppression glViewport inutile.
26 18-07-96 : FMN ; Suppression TelFlush inutile.
27 08-07-96 : FMN ; Suppression de OPENGL_DEBUG inutile avec la nouvelle
29 24-10-96 : CAL ; Portage WNT
30 23-01-97 : CAL ; Suppression de TelClearViews dans TelCopyBuffers
31 30-01-97 : FMN ; Ajout commentaires + WNT.
32 12-02-97 : FMN ; Suppression TelEnquireFacilities()
33 22-04-97 : FMN ; Ajout affichage du cadre pour la copie de buffer
34 30-06-97 : FMN ; Suppression OpenGl_telem_light.h
35 18-07-97 : FMN ; Utilisation de la toolkit sur les lights
36 07-10-97 : FMN ; Simplification WNT + correction Transient
37 05-12-97 : FMN ; PRO11168: Suppression TglActiveWs pour project/unproject
38 23-12-97 : FMN ; Suppression TelSetFrontFaceAttri et TelSetBackFaceAttri
39 30-12-97 : FMN ; CTS18312: Correction back material
40 04-05-98 : CAL ; Contournement bug SGI octane bavure de pixels (PRO12899)
41 30-09-98 : CAL ; Optimisation pour eviter de charger inutilement
42 les matrices de la vue.
43 19-10-98 : FMN ; Suppression de glPixelTransferi dans TelEnable() car cela
44 rentre en conflit avec l'utilisation d'une image de fond.
45 02.14.100 : JR : Warnings on WNT truncations from double to float
46 08-03-01 : GG ; BUC60823 Avoid crash in the normal computation method
47 when a face has confused or aligned points.
49 ************************************************************************/
51 #define IMP190100 /*GG To avoid too many REDRAW in immediat mode,
52 // Add TelMakeFrontAndBackBufCurrent() function
56 /*----------------------------------------------------------------------*/
66 # include <X11/Xlib.h>
79 #include <InterfaceGraphic_Graphic3d.hxx>
80 #include <InterfaceGraphic_Visual3d.hxx>
82 #include <OpenGl_tgl_all.hxx>
83 #include <OpenGl_tsm.hxx>
84 #include <OpenGl_tsm_ws.hxx>
85 #include <OpenGl_telem.hxx>
86 #include <OpenGl_telem_attri.hxx>
87 #include <OpenGl_telem_util.hxx>
88 #include <OpenGl_telem_view.hxx>
89 #include <OpenGl_tgl_tox.hxx>
90 #include <OpenGl_tgl_subrvis.hxx>
91 #include <OpenGl_txgl.hxx>
92 #include <OpenGl_LightBox.hxx>
93 #include <OpenGl_Memory.hxx>
95 /*----------------------------------------------------------------------*/
101 #define CALL_DEF_DELTA 10
102 #define NO_COPYBUFFER
104 /*----------------------------------------------------------------------*/
106 * Variables statiques
109 static Tint call_back_buffer_restored = TOff;
114 * Wrappers and utilities used to select between pixmap and gl double buffering
117 /* Cache some pixmap info for pixmap double buffering */
119 static Display *window_display; /* the display in use */
120 static Window window_id; /* the window to copy the pixmap to */
121 static Pixmap pixmap_id; /* the pixmap id */
122 static GLXPixmap glx_pixmap; /* the glx pixmap */
124 window_width, /* window width and height for XCopyArea */
128 static GC window_gc; /* GC for XCopyArea */
130 static GLXContext glx_context; /* GL Context */
132 static int usePixmapDB = 0; /* True if doing pixmap double buffering */
134 /*----------------------------------------------------------------------*/
136 void TelSetPixmapDBParams(Display *dpy,
138 int width, int height, int depth, GC gc,
144 window_display = dpy;
146 window_width = width;
147 window_height = height;
148 window_depth = depth;
153 glx_pixmap = glxpixmap;
158 GLXPixmap TelGetGLXPixmap()
163 void TelSetPixmapDB(int flag)
168 int TelTestPixmapDB()
173 void TelDrawBuffer(GLenum buf)
176 glDrawBuffer(GL_FRONT);
183 /*----------------------------------------------------------------------*/
185 void TelMakeFrontBufCurrent(Tint WsId)
190 glXMakeCurrent(window_display,window_id, glx_context);
191 glDrawBuffer(GL_FRONT);
196 glDrawBuffer(GL_FRONT);
200 void TelMakeBackBufCurrent(Tint WsId)
205 glXMakeCurrent(window_display,glx_pixmap, glx_context);
206 glDrawBuffer(GL_BACK);
211 glDrawBuffer(GL_BACK);
216 void TelMakeFrontAndBackBufCurrent(Tint WsId)
221 glXMakeCurrent(window_display,window_id, glx_context);
222 glDrawBuffer(GL_FRONT_AND_BACK);
227 glDrawBuffer(GL_FRONT_AND_BACK);
232 /*----------------------------------------------------------------------*/
234 TelRemdupnames(Tint *ls, Tint num )
236 register Tint *ap, *bp, n;
254 /*----------------------------------------------------------------------*/
256 #define GPRECIS 0.000001
257 Tint TelGetPolygonNormal(tel_point pnts, Tint* indexs, Tint npnt, Tfloat *norm ) {
260 norm[0] = norm[1] = norm[2] = 0.;
262 Tfloat a[3], b[3], c[3];
265 i0 = 0; if( indexs ) i0 = indexs[0];
266 for( i=1 ; i<npnt ; i++ ) {
267 ii = i; if( indexs ) ii = indexs[i];
268 vecsub( a, pnts[ii].xyz, pnts[i0].xyz );
269 if( vecmg2(a) > GPRECIS ) break;
272 for( j=i+1 ; j<npnt ; j++ ) {
273 jj = j; if( indexs ) jj = indexs[j];
274 vecsub( b, pnts[jj].xyz, pnts[i0].xyz );
275 vecsub( c, pnts[jj].xyz, pnts[ii].xyz );
276 if( (vecmg2(b) > GPRECIS) && (vecmg2(c) > GPRECIS) ) break;
280 veccrs( norm, a, b );
281 d = vecnrmd( norm, d );
282 status = (d > 0.) ? 1 : 0;
288 printf(" *** OpenGl_TelGetPolygonNormal.has found confused or aligned points\n");
294 Tint TelGetNormal(Tfloat *data1, Tfloat *data2, Tfloat *data3, Tfloat *norm ) {
298 norm[0] = norm[1] = norm[2] = 0.;
299 vecsub( a, data2, data1 );
300 vecsub( b, data3, data2 );
301 if( (vecmg2(a) > GPRECIS) && (vecmg2(b) > GPRECIS) ) {
303 veccrs( norm, a, b );
304 d = vecnrmd( norm, d );
305 status = (d > 0.) ? 1 : 0;
309 printf(" *** OpenGl_TelGetNormal.has found confused or aligned points\n");
316 TelGetNormal(Tfloat *data1, Tfloat *data2, Tfloat *data3, Tfloat *norm ) {
319 vecsub( a, data2, data1 );
320 vecsub( b, data3, data2 );
321 veccrs( norm, a, b );
325 /*----------------------------------------------------------------------*/
327 TelIsBackFace(Tmatrix3 n, Tfloat *nrm )
334 TelTranpt3( r, m, n );
339 /*----------------------------------------------------------------------*/
341 TelTransposemat3 (Tmatrix3 a)
347 /* transposition de la sous-matrice dim x dim */
348 for (row = 0; row < dim; row++)
349 for (col = 0; col < dim; col++)
350 res[row][col] = a[col][row];
352 /* copie du resultat */
358 /*----------------------------------------------------------------------*/
360 TelMultiplymat3 (Tmatrix3 c, Tmatrix3 a, Tmatrix3 b)
366 /* on multiplie d'abord les 2 matrices dim x dim */
367 for (row = 0; row < dim; row++) {
368 for (col = 0; col < dim; col++) {
369 Tfloat sum = ( float )0.0;
370 for (i = 0; i < dim; i++)
371 sum += a[row][i] * b[i][col];
376 /* on copie ensuite le resultat */
382 /*----------------------------------------------------------------------*/
384 TelTranpt3(Tfloat tpt[4], Tfloat pt[4], Tmatrix3 mat )
389 for( i = 0; i < 4; i++ )
391 for( j = 0, sum = ( float )0.0; j < 4; j++ )
393 sum += pt[j] * mat[j][i];
400 /*----------------------------------------------------------------------*/
402 TelInitWS(Tint ws, Tint w, Tint h, Tfloat bgcolr, Tfloat bgcolg, Tfloat bgcolb )
406 TsmGetWSAttri( ws, WSDbuff, &data );
408 glMatrixMode(GL_MODELVIEW);
409 glViewport( 0, 0, w, h);
413 * Contournement bug SGI sur Octane (PRO12899)
414 * Bavures de pixels lors de la copie de vue 3d
416 glDisable (GL_SCISSOR_TEST);
419 printf("OPENGL: TelInitWS: glClearColor %d \n", ws);
421 if( data.ldata == TOn )
424 if (TelTestPixmapDB())
426 glDrawBuffer(GL_FRONT);
427 glClearColor(bgcolr, bgcolg, bgcolb, 1.0);
428 glClear(GL_COLOR_BUFFER_BIT);
432 /* QTOCC_PATCH by PCD: the frame buffer should not be cleared here
433 to avoid flicker. It is cleared properly in TelClearViews()
434 called by call_func_redraw_all_structs_begin() */
435 glDrawBuffer(GL_BACK);
438 /* QTOCC_PATCH by PCD: the frame buffer should not be cleared here
439 to avoid flicker. It is cleared properly in TelClearViews()
440 called by call_func_redraw_all_structs_begin() */
441 glDrawBuffer(GL_BACK);
446 glClearColor(bgcolr, bgcolg, bgcolb, ( float )1.0);
447 glClear(GL_COLOR_BUFFER_BIT);
454 /*----------------------------------------------------------------------*/
455 void TelSwapBuffers ( Tint ws ) {
461 if (TelTestPixmapDB())
464 XCopyArea(call_thedisplay, pixmap_id, window_id,
466 window_width, window_height, 0, 0);
470 TsmGetWSAttri( ws, WSWindow, &data );
471 glXSwapBuffers ( call_thedisplay, data.ldata );
476 SwapBuffers ( wglGetCurrentDC () );
481 TelSetBackBufferRestored (TOff);
484 printf("OPENGL: TelSwapBuffers: glXSwapBuffers %d \n", ws);
489 } /* end TelSwapBuffers */
491 /*----------------------------------------------------------------------*/
493 TelBackBufferRestored ()
495 return call_back_buffer_restored;
498 /*----------------------------------------------------------------------*/
500 TelSetBackBufferRestored (Tint flag)
503 printf("OPENGL: TelSetBackBufferRestored(%d): \n",flag);
505 call_back_buffer_restored = flag;
508 /*----------------------------------------------------------------------*/
510 TelCopyBuffers(Tint ws, GLenum from, GLenum to,
511 Tfloat xm, Tfloat ym, Tfloat zm, Tfloat XM, Tfloat YM, Tfloat ZM, Tint flag)
517 printf("OPENGL: TelCopyBuffers: \n");
520 if (to == GL_BACK) TelSetBackBufferRestored (TOff);
523 if (TelTestPixmapDB())
526 printf("OPENGL: TelSwapBuffers: glFlush \n");
529 XCopyArea(window_display, pixmap_id, window_id,
531 window_width, window_height, 0, 0);
536 TsmGetWSAttri (ws, WSWidth, &key);
538 TsmGetWSAttri (ws, WSHeight, &key);
541 glMatrixMode (GL_PROJECTION);
544 gluOrtho2D ((GLdouble) 0., (GLdouble) w, 0., (GLdouble) h);
545 glMatrixMode (GL_MODELVIEW);
553 * calcul de la projection de la boite
554 * et copie du rectangle projete
557 GLsizei width, height;
558 Tfloat xmr, ymr, XMR, YMR;
561 * Projection de la boite englobante
563 if ((TelProjectionRaster (ws, xm, ym, zm, &xr[0], &yr[0]) == TSuccess)
564 && (TelProjectionRaster (ws, xm, YM, zm, &xr[1], &yr[1]) == TSuccess)
565 && (TelProjectionRaster (ws, XM, YM, zm, &xr[2], &yr[2]) == TSuccess)
566 && (TelProjectionRaster (ws, XM, ym, zm, &xr[3], &yr[3]) == TSuccess)
567 && (TelProjectionRaster (ws, xm, ym, ZM, &xr[4], &yr[4]) == TSuccess)
568 && (TelProjectionRaster (ws, xm, YM, ZM, &xr[5], &yr[5]) == TSuccess)
569 && (TelProjectionRaster (ws, XM, YM, ZM, &xr[6], &yr[6]) == TSuccess)
570 && (TelProjectionRaster (ws, XM, ym, ZM, &xr[7], &yr[7]) == TSuccess))
572 xmr = ymr = (float ) shortreallast ();
573 XMR = YMR = (float ) shortrealfirst ();
575 * Recherche du rectangle projete
577 for (i=0; i<8; i++) {
578 if (xmr > xr[i]) xmr = xr[i];
579 if (ymr > yr[i]) ymr = yr[i];
580 if (XMR < xr[i]) XMR = xr[i];
581 if (YMR < yr[i]) YMR = yr[i];
583 /* pour eviter les bavures de pixels ! */
588 * Ajout CAL : 10/05/96
589 * Si les MinMax viennent d'un ensemble de markers
590 * on ne tient pas compte du scale factor de ceux-ci
591 * dans les valeurs de MinMax. En effet, ce facteur
592 * est dans l'espace pixel et les MinMax dans l'espace
593 * du modele. Donc ajout d'un delta de pixels
594 * en esperant que les applis n'utilisent pas des
595 * markers tres gros !
597 xmr -= CALL_DEF_DELTA; ymr -= CALL_DEF_DELTA;
598 XMR += CALL_DEF_DELTA; YMR += CALL_DEF_DELTA;
601 * Le rectangle projete peut-etre clippe
603 width = (GLsizei) (XMR-xmr+1);
604 height = (GLsizei) (YMR-ymr+1);
606 printf ("avant clipping\n");
607 printf ("xm, ym, zm : %f, %f, %f\n", xm, ym, zm);
608 printf ("XM, YM, ZM : %f, %f, %f\n", XM, YM, ZM);
609 printf ("taille fenetre : %d, %d\n", w, h);
610 printf ("xmr, ymr by GLU : %f, %f\n", xmr, ymr);
611 printf ("YMR, YMR by GLU : %f, %f\n", XMR, YMR);
612 printf ("copie x, y, dx, dy : %d, %d, %d, %d\n\n",
613 (int) xmr, (int) ymr, (int) width, (int) height);
616 * (xmr,ymr) coin inferieur gauche
617 * (XMR,YMR) coin superieur droit
619 /* cas ou 1 coin est en dehors de la fenetre */
620 if (xmr < 0) { width = (GLsizei) (XMR+1); xmr = 0; }
621 if (ymr < 0) { height = (GLsizei) (YMR+1); ymr = 0; }
622 if (XMR > w) { width = (GLsizei) (w-xmr+1); }
623 if (YMR > h) { height = (GLsizei) (h-ymr+1); }
625 /* cas ou les 2 coins sont en dehors de la fenetre */
626 if (XMR < 0) { xmr = 0; width = height = 1; }
627 if (YMR < 0) { ymr = 0; width = height = 1; }
628 if (xmr > w) { xmr = 0; width = height = 1; }
629 if (ymr > h) { ymr = 0; width = height = 1; }
631 printf ("apres clipping\n");
632 printf ("xmr, ymr by GLU : %f, %f\n", xmr, ymr);
633 printf ("YMR, YMR by GLU : %f, %f\n", XMR, YMR);
634 printf ("copie x, y, dx, dy : %d, %d, %d, %d\n\n",
635 (int) xmr, (int) ymr, (int) width, (int) height);
639 /* copie partielle */
640 glRasterPos2i ((GLint) xmr, (GLint) ymr);
641 glCopyPixels ((GLint) xmr, (GLint) ymr, width, height, GL_COLOR);
647 /* TelClearViews (ws); */
650 glRasterPos2i (0, 0);
651 glCopyPixels (0, 0, w+1, h+1, GL_COLOR);
658 /* TelClearViews (ws); */
661 glRasterPos2i (0, 0);
662 glCopyPixels (0, 0, w+1, h+1, GL_COLOR);
667 glMatrixMode (GL_PROJECTION);
669 glMatrixMode (GL_MODELVIEW);
672 glDrawBuffer (GL_BACK);
676 /*----------------------------------------------------------------------*/
678 TelReadImage(Tint ws, GLenum from, Tint posx, Tint posy, Tint width, Tint height, unsigned int *image)
684 printf("OPENGL: TelReadImage: %d %d %d %d \n", posx, posy, width, height);
689 TsmGetWSAttri (ws, WSWidth, &key);
691 TsmGetWSAttri (ws, WSHeight, &key);
694 glMatrixMode (GL_PROJECTION);
696 gluOrtho2D ((GLdouble) 0., (GLdouble) w, 0., (GLdouble) h);
697 glMatrixMode (GL_MODELVIEW);
702 glRasterPos2i (posx, posy);
704 glReadPixels (posx, posy, width, height, GL_RGBA, GL_UNSIGNED_BYTE, image);
707 glReadBuffer(GL_BACK);
713 /*----------------------------------------------------------------------*/
715 TelDrawImage(Tint ws, GLenum to, Tint posx, Tint posy, Tint width, Tint height, unsigned int *image)
721 printf("OPENGL: TelDrawImage: %d %d %d %d \n", posx, posy, width, height);
726 TsmGetWSAttri (ws, WSWidth, &key);
728 TsmGetWSAttri (ws, WSHeight, &key);
731 glMatrixMode (GL_PROJECTION);
733 gluOrtho2D ((GLdouble) 0., (GLdouble) w, 0., (GLdouble) h);
734 glMatrixMode (GL_MODELVIEW);
739 glRasterPos2i (posx, posy);
741 glDrawPixels (width, height, GL_RGBA, GL_UNSIGNED_BYTE, image);
744 glDrawBuffer(GL_BACK);
749 /*----------------------------------------------------------------------*/
751 TelReadDepths(Tint ws, Tint posx, Tint posy, Tint width, Tint height, float *depths)
757 printf("OPENGL: TelReadDepths: %d %d %d %d \n", posx, posy, width, height);
760 if ( TsmGetWSAttri (ws, WSWindow, &key) != TSuccess ) return;
762 if (depths != NULL && TxglWinset (call_thedisplay, (WINDOW) key.ldata) == TSuccess)
764 TsmGetWSAttri (ws, WSWidth, &key);
766 TsmGetWSAttri (ws, WSHeight, &key);
769 glMatrixMode (GL_PROJECTION);
771 gluOrtho2D ((GLdouble) 0., (GLdouble) w, 0., (GLdouble) h);
772 glMatrixMode (GL_MODELVIEW);
775 glRasterPos2i (posx, posy);
777 glReadPixels (posx, posy, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, depths);
784 /*----------------------------------------------------------------------*/
788 /*glPixelTransferi (GL_MAP_COLOR, GL_TRUE);*/
790 /* GL_DITHER on/off pour le trace */
792 glEnable (GL_DITHER);
794 glDisable (GL_DITHER);
799 /*----------------------------------------------------------------------*/
803 glDisable (GL_DITHER);
804 glPixelTransferi (GL_MAP_COLOR, GL_FALSE);
807 * Disable stuff that's likely to slow down glDrawPixels.
808 * (Omit as much of this as possible, when you know in advance
809 * that the OpenGL state will already be set correctly.)
811 glDisable(GL_ALPHA_TEST);
813 glDisable(GL_DEPTH_TEST);
817 glDisable(GL_LOGIC_OP);
818 glDisable(GL_STENCIL_TEST);
819 glDisable(GL_TEXTURE_1D);
820 glDisable(GL_TEXTURE_2D);
821 glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
822 glPixelTransferi(GL_RED_SCALE, 1);
823 glPixelTransferi(GL_RED_BIAS, 0);
824 glPixelTransferi(GL_GREEN_SCALE, 1);
825 glPixelTransferi(GL_GREEN_BIAS, 0);
826 glPixelTransferi(GL_BLUE_SCALE, 1);
827 glPixelTransferi(GL_BLUE_BIAS, 0);
828 glPixelTransferi(GL_ALPHA_SCALE, 1);
829 glPixelTransferi(GL_ALPHA_BIAS, 0);
832 * Disable extensions that could slow down glDrawPixels.
833 * (Actually, you should check for the presence of the proper
834 * extension before making these calls. I've omitted that
835 * code for simplicity.)
838 #ifdef GL_EXT_convolution
839 glDisable(GL_CONVOLUTION_1D_EXT);
840 glDisable(GL_CONVOLUTION_2D_EXT);
841 glDisable(GL_SEPARABLE_2D_EXT);
844 #ifdef GL_EXT_histogram
845 glDisable(GL_HISTOGRAM_EXT);
846 glDisable(GL_MINMAX_EXT);
849 #ifdef GL_EXT_texture3D
850 glDisable(GL_TEXTURE_3D_EXT);
856 /*----------------------------------------------------------------------*/
858 TelProjectionRaster(Tint ws, Tfloat x, Tfloat y, Tfloat z, Tfloat *xr, Tfloat *yr)
862 Tint vid; /* View index */
863 TEL_VIEW_REP vrep; /* View definition */
868 GLdouble objx, objy, objz;
869 GLdouble modelMatrix[16], projMatrix[16];
871 GLdouble winx, winy, winz;
875 if (TelGetViewRepresentation (ws, vid, &vrep) != TSuccess)
878 TsmGetWSAttri (ws, WSWidth, &key);
880 TsmGetWSAttri (ws, WSHeight, &key);
883 objx = ( GLdouble )x; objy = ( GLdouble )y; objz = ( GLdouble )z;
885 for (k = 0, i = 0; i < 4; i++)
886 for (j = 0; j < 4; j++, k++)
887 modelMatrix[k] = ( GLdouble )vrep.orientation_matrix[i][j];
889 for (k = 0, i = 0; i < 4; i++)
890 for (j = 0; j < 4; j++, k++)
891 projMatrix[k] = ( GLdouble )vrep.mapping_matrix[i][j];
899 * glGetIntegerv (GL_VIEWPORT, viewport);
900 * glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
901 * glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
904 status = gluProject (objx, objy, objz,
905 modelMatrix, projMatrix, viewport,
906 &winx, &winy, &winz);
908 if (status == GL_TRUE) {
909 *xr = ( Tfloat )winx;
910 *yr = ( Tfloat )winy;
921 /*----------------------------------------------------------------------*/
923 TelUnProjectionRaster(Tint ws, Tint xr, Tint yr, Tfloat *x, Tfloat *y, Tfloat *z)
927 Tint vid; /* View index */
928 TEL_VIEW_REP vrep; /* View definition */
931 GLdouble objx, objy, objz;
932 GLdouble modelMatrix[16], projMatrix[16];
934 GLdouble winx, winy, winz;
939 if (TelGetViewRepresentation (ws, vid, &vrep) != TSuccess)
942 TsmGetWSAttri (ws, WSWidth, &key);
944 TsmGetWSAttri (ws, WSHeight, &key);
947 winx = ( GLdouble )xr; winy = ( GLdouble )yr; winz = ( GLdouble )0.0;
949 for (k = 0, i = 0; i < 4; i++)
950 for (j = 0; j < 4; j++, k++)
951 modelMatrix[k] = ( GLdouble )vrep.orientation_matrix[i][j];
953 for (k = 0, i = 0; i < 4; i++)
954 for (j = 0; j < 4; j++, k++)
955 projMatrix[k] = ( GLdouble )vrep.mapping_matrix[i][j];
963 * glGetIntegerv (GL_VIEWPORT, viewport);
964 * glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
965 * glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
968 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
969 &objx, &objy, &objz);
971 if (status == GL_TRUE) {
987 /*----------------------------------------------------------------------*/
989 TelUnProjectionRasterWithRay(Tint ws, Tint xr, Tint yr, Tfloat *x, Tfloat *y, Tfloat *z,
990 Tfloat *dx, Tfloat *dy, Tfloat *dz)
994 Tint vid; /* View index */
995 TEL_VIEW_REP vrep; /* View definition */
998 GLdouble objx, objy, objz;
999 GLdouble objx1, objy1, objz1;
1000 GLdouble modelMatrix[16], projMatrix[16];
1002 GLdouble winx, winy, winz;
1007 if (TelGetViewRepresentation (ws, vid, &vrep) != TSuccess)
1010 TsmGetWSAttri (ws, WSWidth, &key);
1012 TsmGetWSAttri (ws, WSHeight, &key);
1015 winx = ( GLdouble )xr; winy = ( GLdouble )yr; winz = ( GLdouble )0.0;
1017 for (k = 0, i = 0; i < 4; i++)
1018 for (j = 0; j < 4; j++, k++)
1019 modelMatrix[k] = ( GLdouble )vrep.orientation_matrix[i][j];
1021 for (k = 0, i = 0; i < 4; i++)
1022 for (j = 0; j < 4; j++, k++)
1023 projMatrix[k] = ( GLdouble )vrep.mapping_matrix[i][j];
1031 * glGetIntegerv (GL_VIEWPORT, viewport);
1032 * glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
1033 * glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
1036 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
1037 &objx, &objy, &objz);
1039 if (status == GL_TRUE) {
1040 *x = ( Tfloat )objx;
1041 *y = ( Tfloat )objy;
1042 *z = ( Tfloat )objz;
1044 winz = ( GLdouble ) -10.0;
1045 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
1046 &objx1, &objy1, &objz1);
1048 if (status == GL_TRUE) {
1049 *dx = ( Tfloat )(objx-objx1);
1050 *dy = ( Tfloat )(objy-objy1);
1051 *dz = ( Tfloat )(objz-objz1);
1075 /*----------------------------------------------------------------------*/
1082 printf("OPENGL: TelFlush: glFinish \n");
1089 printf("OPENGL: TelFlush: glFlush \n");
1096 /*----------------------------------------------------------------------*/
1098 TelIsBackFacePerspective(Tmatrix3 n, Tfloat *p1, Tfloat *p2, Tfloat *p3 )
1100 Tfloat r1[4], r2[4], r3[4], m[4], norm[4];
1103 m[3] = ( float )1.0;
1104 TelTranpt3( r1, m, n );
1110 m[3] = ( float )1.0;
1111 TelTranpt3( r2, m, n );
1117 m[3] = ( float )1.0;
1118 TelTranpt3( r3, m, n );
1122 TelGetNormal( r1, r2, r3, norm );
1124 return norm[2] < 0.0;
1127 /*----------------------------------------------------------------------*/