Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
2 | // Created by: Sergey ZERCHANINOV | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
5f8b738e | 16 | #include <OpenGl_GlCore11.hxx> |
2166f0fa SK |
17 | |
18 | #include <stddef.h> | |
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
2166f0fa | 21 | |
2166f0fa SK |
22 | #include <InterfaceGraphic_Graphic3d.hxx> /* pour CALL_DEF_STRUCTURE */ |
23 | #include <InterfaceGraphic_Aspect.hxx> /* pour CALL_DEF_VIEW */ | |
24 | #include <InterfaceGraphic_Visual3d.hxx> | |
25 | ||
26 | #include <OpenGl_transform_persistence.hxx> | |
27 | ||
2166f0fa SK |
28 | #include <OpenGl_Workspace.hxx> |
29 | #include <OpenGl_View.hxx> | |
30 | #include <OpenGl_Trihedron.hxx> | |
31 | ||
a174a3c5 | 32 | static const OpenGl_TextParam THE_LABEL_PARAMS = |
33 | { | |
34 | 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM | |
35 | }; | |
2166f0fa | 36 | |
2166f0fa SK |
37 | static const CALL_DEF_CONTEXTLINE myDefaultContextLine = |
38 | { | |
39 | 1, //IsDef | |
40 | 1, //IsSet | |
41 | { 1.F, 1.F, 1.F }, //Color | |
42 | Aspect_TOL_SOLID, //LineType | |
43 | 1.F //Width | |
44 | }; | |
45 | ||
46 | static const CALL_DEF_CONTEXTTEXT myDefaultContextText = | |
47 | { | |
48 | 1, //IsDef | |
49 | 1, //IsSet | |
50 | "Courier", //Font | |
51 | 0.3F, //Space | |
52 | 1.0F, //Expan | |
53 | { 1.F, 1.F, 1.F }, //Color | |
54 | Aspect_TOST_NORMAL, //Style | |
55 | Aspect_TODT_NORMAL, //DisplayType | |
56 | { 1.F, 1.F, 1.F }, //ColorSubTitle | |
57 | 0, //TextZoomable | |
58 | 0.F, //TextAngle | |
eeaaaefb | 59 | Font_FA_Regular //TextFontAspect |
2166f0fa SK |
60 | }; |
61 | ||
62 | /*----------------------------------------------------------------------*/ | |
63 | /* | |
64 | * Variables statiques | |
65 | */ | |
66 | ||
67 | /* Default parameters for ZBUFFER triheron */ | |
68 | static TEL_COLOUR theXColor = {{ 1.F, 0.F, 0.F, 0.6F }}; | |
69 | static TEL_COLOUR theYColor = {{ 0.F, 1.F, 0.F, 0.6F }}; | |
70 | static TEL_COLOUR theZColor = {{ 0.F, 0.F, 1.F, 0.6F }}; | |
71 | static float theRatio = 0.8f; | |
72 | static float theDiameter = 0.05f; | |
73 | static int theNbFacettes = 12; | |
74 | ||
75 | /*----------------------------------------------------------------------*/ | |
76 | ||
77 | /* | |
78 | * affichage d'un triedre non zoomable a partir des index dans les tables | |
79 | * des structures non zoomables. | |
80 | * | |
81 | * Triedre = Objet non Zoomable : | |
82 | * on recalcule ses dimensions et son origine en fonction de la taille | |
83 | * de la fenetre; on positionne selon le choix de l'init; | |
84 | * et on inhibe seulement les translations. | |
85 | * | |
86 | */ | |
87 | ||
88 | //call_triedron_redraw | |
a174a3c5 | 89 | void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 90 | { |
ca3c13d1 | 91 | #if !defined(GL_ES_VERSION_2_0) |
a174a3c5 | 92 | const Standard_Real U = theWorkspace->ActiveView()->Height(); |
93 | const Standard_Real V = theWorkspace->ActiveView()->Width(); | |
2166f0fa SK |
94 | |
95 | /* la taille des axes est 1 proportion (fixee a l'init du triedre) */ | |
bf75be98 | 96 | /* de la dimension la plus petite de la window. */ |
2166f0fa SK |
97 | const GLdouble L = ( U < V ? U : V ) * myScale; |
98 | ||
99 | /* | |
100 | * On inhibe les translations; on conserve les autres transformations. | |
101 | */ | |
102 | ||
103 | /* on lit les matrices de transformation et de projection de la vue */ | |
104 | /* pour annuler les translations (dernieres colonnes des matrices). */ | |
105 | GLdouble modelMatrix[4][4]; | |
106 | glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix ); | |
107 | GLdouble projMatrix[4][4]; | |
108 | glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix ); | |
109 | ||
110 | /* on annule la translation qui peut etre affectee a la vue */ | |
111 | modelMatrix[3][0] = 0.; | |
112 | modelMatrix[3][1] = 0.; | |
113 | modelMatrix[3][2] = 0.; | |
b5ac8292 | 114 | |
115 | projMatrix[0][0] = 2.0 / U; | |
116 | projMatrix[0][1] = 0.0; | |
117 | projMatrix[0][2] = 0.0; | |
118 | projMatrix[0][3] = 0.0; | |
119 | ||
120 | projMatrix[1][0] = 0.0; | |
121 | projMatrix[1][1] = 2.0 / V; | |
122 | projMatrix[1][2] = 0.0; | |
123 | projMatrix[1][3] = 0.0; | |
124 | ||
125 | projMatrix[2][0] = 0.0; | |
126 | projMatrix[2][1] = 0.0; | |
127 | projMatrix[2][2] = -2.0 * 1e-7; | |
128 | projMatrix[2][3] = 0.0; | |
129 | ||
130 | projMatrix[3][0] = 0.0; | |
131 | projMatrix[3][1] = 0.0; | |
132 | projMatrix[3][2] = 0.0; | |
133 | projMatrix[3][3] = 1.0; | |
2166f0fa SK |
134 | |
135 | /* sauvegarde du contexte des matrices avant chargement */ | |
136 | glMatrixMode (GL_MODELVIEW); | |
137 | glPushMatrix (); | |
138 | glLoadMatrixd( (GLdouble *) modelMatrix ); | |
139 | glMatrixMode ( GL_PROJECTION ); | |
140 | glPushMatrix (); | |
141 | glLoadMatrixd( (GLdouble *) projMatrix ); | |
142 | ||
143 | /* | |
144 | * Positionnement de l'origine du triedre selon le choix de l'init | |
145 | */ | |
146 | ||
147 | /* on fait uniquement une translation de l'origine du Triedre */ | |
148 | ||
149 | switch (myPos) | |
150 | { | |
151 | case Aspect_TOTP_LEFT_LOWER : | |
152 | glTranslated( -0.5*U + L , -0.5*V + L , 0. ); | |
153 | break; | |
154 | ||
155 | case Aspect_TOTP_LEFT_UPPER : | |
156 | glTranslated( -0.5*U + L , +0.5*V - L -L/3., 0. ); | |
157 | break; | |
158 | ||
159 | case Aspect_TOTP_RIGHT_LOWER : | |
160 | glTranslated( 0.5*U - L -L/3. , -0.5*V + L , 0. ); | |
161 | break; | |
162 | ||
163 | case Aspect_TOTP_RIGHT_UPPER : | |
164 | glTranslated( 0.5*U - L -L/3. , +0.5*V - L -L/3. , 0. ); | |
165 | break; | |
166 | ||
167 | //case Aspect_TOTP_CENTER : | |
168 | default : | |
169 | break; | |
170 | } | |
171 | ||
bf75be98 | 172 | /* |
173 | * Creation du triedre | |
2166f0fa | 174 | */ |
2166f0fa | 175 | |
bf75be98 | 176 | /* Fotis Sioutis 2007-11-14 15:06 |
177 | I have also seen in previous posts that the view trihedron in V3d_WIREFRAME mode | |
178 | changes colors depending on the state of the view. This behaviour can be easily | |
2166f0fa | 179 | corrected by altering call_triedron_redraw function in OpenGl_triedron.c of TKOpengl. |
bf75be98 | 180 | The only change needed is to erase glDisable(GL_LIGHTING) that is called before the |
2166f0fa | 181 | Axis name drawing and move this function call just before the initial axis drawing. |
bf75be98 | 182 | Below is the code portion with the modification.I don't know if this is considered to |
2166f0fa SK |
183 | be a bug but anyway i believe it might help some of you out there.*/ |
184 | glDisable(GL_LIGHTING); | |
2166f0fa SK |
185 | |
186 | /* Position de l'origine */ | |
187 | const GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 }; | |
188 | ||
189 | /* Position des Axes */ | |
190 | GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 }; | |
191 | GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 }; | |
192 | GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 }; | |
193 | TriedronAxeX[0] = L ; | |
194 | TriedronAxeY[1] = L ; | |
195 | TriedronAxeZ[2] = L ; | |
196 | ||
197 | /* dessin des axes */ | |
198 | glBegin(GL_LINES); | |
199 | glVertex3dv( TriedronOrigin ); | |
200 | glVertex3dv( TriedronAxeX ); | |
201 | ||
202 | glVertex3dv( TriedronOrigin ); | |
203 | glVertex3dv( TriedronAxeY ); | |
204 | ||
205 | glVertex3dv( TriedronOrigin ); | |
206 | glVertex3dv( TriedronAxeZ ); | |
207 | glEnd(); | |
208 | ||
209 | /* fleches au bout des axes (= cones de la couleur demandee) */ | |
210 | const GLdouble l = 0.75*L; /* distance a l'origine */ | |
211 | const GLdouble rayon = L/30. ; /* rayon de la base du cone */ | |
212 | const int NbFacettes = 12; /* le cone sera compose de 12 facettes triangulaires */ | |
213 | const double Angle = 2. * M_PI/ NbFacettes; | |
214 | ||
215 | int ii; | |
216 | GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 }; | |
217 | ||
218 | /* solution FILAIRE des cones au bout des axes : une seule ligne */ | |
219 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | |
220 | /* (la couleur est deja initialisee dans AspectLine) */ | |
221 | /* FIN de la solution FILAIRE CHOISIE pour les cones des axes */ | |
222 | ||
223 | /* fleche en X */ | |
224 | glBegin(GL_TRIANGLE_FAN); | |
225 | glVertex3dv( TriedronAxeX ); | |
226 | TriedronCoord[0] = l; | |
227 | ii = NbFacettes; | |
228 | while (ii >= 0 ) { | |
229 | TriedronCoord[1] = rayon * sin(ii * Angle); | |
230 | TriedronCoord[2] = rayon * cos(ii * Angle); | |
231 | glVertex3dv( TriedronCoord ); | |
232 | ii--; | |
233 | } | |
234 | glEnd(); | |
235 | ||
236 | /* fleche en Y */ | |
237 | glBegin(GL_TRIANGLE_FAN); | |
238 | glVertex3dv( TriedronAxeY ); | |
239 | TriedronCoord[1] = l; | |
240 | ii = NbFacettes; | |
241 | while (ii >= 0 ) { | |
242 | TriedronCoord[0] = rayon * cos(ii * Angle); | |
243 | TriedronCoord[2] = rayon * sin(ii * Angle); | |
244 | glVertex3dv( TriedronCoord ); | |
245 | ii--; | |
246 | } | |
247 | glEnd(); | |
248 | ||
249 | /* fleche en Z */ | |
250 | glBegin(GL_TRIANGLE_FAN); | |
251 | glVertex3dv( TriedronAxeZ ); | |
252 | TriedronCoord[2] = l; | |
253 | ii = NbFacettes; | |
254 | while (ii >= 0 ) { | |
255 | TriedronCoord[0] = rayon * sin(ii * Angle); | |
256 | TriedronCoord[1] = rayon * cos(ii * Angle); | |
257 | glVertex3dv( TriedronCoord ); | |
258 | ii--; | |
259 | } | |
260 | glEnd(); | |
261 | ||
262 | /* dessin de l'origine */ | |
263 | TriedronCoord[2] = 0.0 ; | |
264 | ii = 24 ; | |
265 | const double Angle1 = 2. * M_PI/ ii; | |
266 | glBegin(GL_LINE_LOOP); | |
267 | while (ii >= 0 ) { | |
268 | TriedronCoord[0] = rayon * sin(ii * Angle1); | |
269 | TriedronCoord[1] = rayon * cos(ii * Angle1); | |
270 | glVertex3dv( TriedronCoord ); | |
271 | ii--; | |
bf75be98 | 272 | } |
2166f0fa SK |
273 | glEnd(); |
274 | ||
a174a3c5 | 275 | // draw axes labels |
276 | myLabelX.SetPosition (OpenGl_Vec3(float(L + rayon), 0.0f, float(-rayon))); | |
277 | myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(L + 3.0 * rayon), float(2.0 * rayon))); | |
278 | myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(L + 3.0 * rayon))); | |
279 | myLabelX.Render (theWorkspace); | |
280 | myLabelY.Render (theWorkspace); | |
281 | myLabelZ.Render (theWorkspace); | |
2166f0fa | 282 | |
bf75be98 | 283 | /* |
2166f0fa SK |
284 | * restauration du contexte des matrices |
285 | */ | |
286 | glMatrixMode (GL_PROJECTION); | |
287 | glPopMatrix (); | |
288 | glMatrixMode (GL_MODELVIEW); | |
289 | glPopMatrix (); | |
ca3c13d1 | 290 | #endif |
2166f0fa SK |
291 | } |
292 | ||
293 | ||
294 | /******************************************************* | |
295 | * Draws ZBUFFER trihedron mode | |
296 | *******************************************************/ | |
297 | //call_zbuffer_triedron_redraw | |
a174a3c5 | 298 | void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 299 | { |
ca3c13d1 | 300 | #if !defined(GL_ES_VERSION_2_0) |
a174a3c5 | 301 | const Standard_Real U = theWorkspace->ActiveView()->Height(); |
302 | const Standard_Real V = theWorkspace->ActiveView()->Width(); | |
2166f0fa SK |
303 | |
304 | GLdouble modelMatrix[4][4]; | |
305 | glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix ); | |
306 | GLdouble projMatrix[4][4]; | |
307 | glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix ); | |
308 | ||
309 | /* Check position in the ViewPort */ | |
5f8b738e | 310 | /* PCD 29/09/2008 */ |
2166f0fa SK |
311 | /* Simple code modification recommended by Fotis Sioutis and Peter Dolbey */ |
312 | /* to remove the irritating default behaviour of triedrons using V3d_ZBUFFER */ | |
313 | /* which causes the glyph to jump around the screen when the origin moves offscreen. */ | |
314 | GLboolean isWithinView = GL_FALSE; | |
2166f0fa SK |
315 | |
316 | /* la taille des axes est 1 proportion (fixee a l'init du triedre) */ | |
bf75be98 | 317 | /* de la dimension la plus petite de la window. */ |
2166f0fa SK |
318 | GLdouble L = ( U < V ? U : V ) * myScale; |
319 | ||
320 | if (!isWithinView) | |
321 | { | |
322 | /* Annulate translation matrix */ | |
323 | modelMatrix[3][0] = 0.; | |
324 | modelMatrix[3][1] = 0.; | |
325 | modelMatrix[3][2] = 0.; | |
b5ac8292 | 326 | |
327 | projMatrix[0][0] = 2.0 / U; | |
328 | projMatrix[0][1] = 0.0; | |
329 | projMatrix[0][2] = 0.0; | |
330 | projMatrix[0][3] = 0.0; | |
331 | ||
332 | projMatrix[1][0] = 0.0; | |
333 | projMatrix[1][1] = 2.0 / V; | |
334 | projMatrix[1][2] = 0.0; | |
335 | projMatrix[1][3] = 0.0; | |
336 | ||
337 | projMatrix[2][0] = 0.0; | |
338 | projMatrix[2][1] = 0.0; | |
339 | projMatrix[2][2] = -2.0 * 1e-7; | |
340 | projMatrix[2][3] = 0.0; | |
341 | ||
342 | projMatrix[3][0] = 0.0; | |
343 | projMatrix[3][1] = 0.0; | |
344 | projMatrix[3][2] = 0.0; | |
345 | projMatrix[3][3] = 1.0; | |
2166f0fa SK |
346 | |
347 | /* save matrix */ | |
348 | glMatrixMode (GL_MODELVIEW); | |
349 | glPushMatrix (); | |
350 | //glLoadIdentity (); | |
351 | glLoadMatrixd( (GLdouble *) modelMatrix); | |
352 | glMatrixMode ( GL_PROJECTION ); | |
353 | glPushMatrix (); | |
354 | //glLoadIdentity(); | |
355 | glLoadMatrixd( (GLdouble *) projMatrix); | |
356 | ||
357 | /* | |
358 | * Define position in the view | |
359 | */ | |
360 | switch (myPos) | |
361 | { | |
bf75be98 | 362 | case Aspect_TOTP_LEFT_LOWER : |
2166f0fa SK |
363 | glTranslated( -0.5*U + L , -0.5*V + L , 0. ); |
364 | break; | |
365 | ||
366 | case Aspect_TOTP_LEFT_UPPER : | |
367 | glTranslated( -0.5*U + L , +0.5*V - L -L/3. , 0. ); | |
368 | break; | |
369 | ||
370 | case Aspect_TOTP_RIGHT_LOWER : | |
371 | glTranslated( 0.5*U - L -L/3. , -0.5*V + L , 0. ); | |
372 | break; | |
373 | ||
374 | case Aspect_TOTP_RIGHT_UPPER : | |
375 | glTranslated( 0.5*U - L -L/3. , +0.5*V - L -L/3. , 0. ); | |
376 | break; | |
377 | ||
378 | //case Aspect_TOTP_CENTER : | |
379 | default : | |
380 | break; | |
381 | } | |
382 | L *= myRatio; | |
383 | } | |
384 | ||
a174a3c5 | 385 | const OpenGl_AspectLine *AspectLine = theWorkspace->AspectLine( Standard_True ); |
2166f0fa SK |
386 | const TEL_COLOUR &aLineColor = AspectLine->Color(); |
387 | ||
bf75be98 | 388 | /* |
2166f0fa SK |
389 | * Creation the trihedron |
390 | */ | |
391 | #define CYLINDER_LENGTH 0.75f | |
392 | ||
393 | const GLuint startList = glGenLists(4); | |
394 | GLUquadricObj* aQuadric = gluNewQuadric(); | |
395 | ||
396 | const GLboolean aIsDepthEnabled = glIsEnabled(GL_DEPTH_TEST); | |
397 | ||
2166f0fa | 398 | GLboolean aIsDepthMaskEnabled; |
5f8b738e | 399 | /*PCD 02/07/07 */ |
2166f0fa SK |
400 | /* GL_DEPTH_WRITEMASK is not a valid argument to glIsEnabled, the */ |
401 | /* original code is shown to be broken when run under an OpenGL debugger */ | |
402 | /* like GLIntercept. This is the correct way to retrieve the mask value. */ | |
bf75be98 | 403 | glGetBooleanv(GL_DEPTH_WRITEMASK, &aIsDepthMaskEnabled); |
2166f0fa SK |
404 | |
405 | const GLdouble aCylinderLength = L * CYLINDER_LENGTH; | |
406 | const GLdouble aCylinderDiametr = L * myDiameter; | |
407 | const GLdouble aConeDiametr = aCylinderDiametr * 2.; | |
408 | const GLdouble aConeLength = L * (1 - CYLINDER_LENGTH); | |
409 | /* Correct for owerlapping */ | |
410 | /* aCylinderLength += aConeLength - 1.2*aCylinderDiametr*aConeLength/aConeDiametr;*/ | |
411 | ||
412 | /* Create cylinder for axis */ | |
413 | gluQuadricDrawStyle(aQuadric, GLU_FILL); /* smooth shaded */ | |
414 | gluQuadricNormals(aQuadric, GLU_FLAT); | |
415 | /* Axis */ | |
416 | glNewList(startList, GL_COMPILE); | |
417 | gluCylinder(aQuadric, aCylinderDiametr, aCylinderDiametr, aCylinderLength, myNbFacettes, 1); | |
418 | glEndList(); | |
419 | /* Cone */ | |
420 | glNewList(startList + 1, GL_COMPILE); | |
421 | gluCylinder(aQuadric, aConeDiametr, 0., aConeLength, myNbFacettes, 1); | |
422 | glEndList(); | |
423 | /* Central sphere */ | |
424 | glNewList(startList + 2, GL_COMPILE); | |
425 | gluSphere(aQuadric, aCylinderDiametr * 2., myNbFacettes, myNbFacettes); | |
426 | glEndList(); | |
427 | /* End disk */ | |
428 | gluQuadricOrientation(aQuadric,GLU_INSIDE); /*szv*/ | |
429 | glNewList(startList + 3, GL_COMPILE); | |
430 | gluDisk(aQuadric, aCylinderDiametr, aConeDiametr, myNbFacettes, 1/*szv:2*/); | |
431 | glEndList(); | |
432 | ||
433 | /* Store previous attributes */ | |
434 | glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT); | |
435 | glEnable(GL_LIGHTING); | |
436 | ||
437 | glCullFace(GL_BACK); | |
438 | glEnable(GL_CULL_FACE); | |
439 | ||
5f8b738e | 440 | /*Fotis Sioutis | 2008-01-21 10:55 |
bf75be98 | 441 | In the function call_zbuffer_triedron_redraw of TKOpengl, |
442 | the z buffered trihedron changes colors in case there | |
443 | is an object in the scene that has an explicit material | |
444 | attached to it.In the trihedron display loop, | |
445 | GL_COLOR_MATERIAL is enabled, but only the GL_DIFFUSE | |
2166f0fa | 446 | parameter is utilized in glColorMaterial(...). |
bf75be98 | 447 | This causes the last ambient,specular and emission values |
2166f0fa SK |
448 | used, to stay at the stack and applied to the trihedron |
449 | (which causes the color change). | |
bf75be98 | 450 | A fix is proposed , to change GL_DIFFUSE to |
451 | GL_AMBIENT_AND_DIFFUSE in glColorMaterial call in | |
452 | line 946.The above of course will leave unchanged | |
2166f0fa | 453 | the SPECULAR and EMISSION values. |
bf75be98 | 454 | Another proposal which would fix 100% the problem |
455 | is to use glMaterial instead of glColor on the trihedron | |
2166f0fa SK |
456 | drawing loop. */ |
457 | const GLfloat aNULLColor[] = { 0.f, 0.f, 0.f, 0.f }; /* FS 21/01/08 */ | |
458 | glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, aNULLColor); | |
459 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, aNULLColor); | |
460 | glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, aNULLColor); | |
461 | glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.f); | |
2166f0fa SK |
462 | |
463 | glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); | |
464 | glEnable(GL_COLOR_MATERIAL); | |
465 | ||
466 | if (!aIsDepthEnabled) { | |
467 | glEnable(GL_DEPTH_TEST); | |
2166f0fa | 468 | glClear(GL_DEPTH_BUFFER_BIT); |
2166f0fa | 469 | } |
2166f0fa | 470 | |
2166f0fa SK |
471 | if (!aIsDepthMaskEnabled) { |
472 | /* This is how the depthmask needs to be re-enabled...*/ | |
473 | glDepthMask(GL_TRUE); | |
474 | /* ...and not this stuff below */ | |
475 | } | |
2166f0fa SK |
476 | |
477 | /* Position des Axes */ | |
478 | GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 }; | |
479 | GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 }; | |
2166f0fa SK |
480 | TriedronAxeX[0] = L; |
481 | TriedronAxeY[1] = L; | |
2166f0fa SK |
482 | |
483 | glMatrixMode(GL_MODELVIEW); | |
484 | ||
5f8b738e | 485 | /* PCD 17/06/07 */ |
2166f0fa | 486 | GLint df; |
bf75be98 | 487 | glGetIntegerv (GL_DEPTH_FUNC, &df); |
2166f0fa | 488 | |
2166f0fa SK |
489 | int i; |
490 | for (i = 0; i < 2; i++) /* PCD 11/02/08 Two pass method */ | |
491 | { | |
492 | if (i == 0) /* First pass */ | |
bf75be98 | 493 | { |
494 | glDepthFunc(GL_ALWAYS); | |
2166f0fa SK |
495 | } |
496 | else | |
497 | { | |
bf75be98 | 498 | glDepthFunc(GL_LEQUAL); |
2166f0fa | 499 | } |
2166f0fa SK |
500 | |
501 | glPushMatrix(); | |
502 | glPushMatrix(); | |
503 | glPushMatrix(); | |
504 | ||
505 | glColor3fv(aLineColor.rgb); | |
506 | glCallList(startList+2); | |
507 | ||
508 | // Z axis | |
509 | glColor4fv(myZColor.rgb); | |
510 | glCallList(startList); | |
511 | glTranslated(0, 0, L * CYLINDER_LENGTH); | |
512 | glCallList(startList + 3); | |
513 | glCallList(startList + 1); | |
bf75be98 | 514 | glPopMatrix(); |
2166f0fa SK |
515 | |
516 | // X axis | |
517 | glRotated(90.0, TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2]); | |
518 | glColor4fv(myXColor.rgb); | |
519 | glCallList(startList); | |
520 | glTranslated(0, 0, L * CYLINDER_LENGTH); | |
521 | glCallList(startList + 3); | |
522 | glCallList(startList + 1); | |
bf75be98 | 523 | glPopMatrix(); |
2166f0fa SK |
524 | |
525 | // Y axis | |
526 | glRotated(-90.0, TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]); | |
527 | glColor4fv(myYColor.rgb); | |
528 | glCallList(startList); | |
529 | glTranslated(0, 0, L * CYLINDER_LENGTH); | |
530 | glCallList(startList + 3); | |
531 | glCallList(startList + 1); | |
532 | glPopMatrix(); | |
2166f0fa | 533 | } |
2166f0fa | 534 | |
bf75be98 | 535 | if (!aIsDepthEnabled) |
2166f0fa | 536 | glDisable(GL_DEPTH_TEST); |
2166f0fa | 537 | |
5f8b738e | 538 | if (!aIsDepthMaskEnabled) |
2166f0fa | 539 | glDepthMask(GL_FALSE); |
2166f0fa | 540 | |
2166f0fa SK |
541 | glDisable(GL_CULL_FACE); |
542 | glDisable(GL_COLOR_MATERIAL); | |
543 | ||
544 | gluDeleteQuadric(aQuadric); | |
545 | glColor3fv (aLineColor.rgb); | |
546 | ||
2166f0fa | 547 | /* Always write the text */ |
bf75be98 | 548 | glDepthFunc(GL_ALWAYS); |
2166f0fa SK |
549 | |
550 | glPopAttrib(); | |
551 | ||
552 | /* fleches au bout des axes (= cones de la couleur demandee) */ | |
553 | //const GLdouble l = 0.75*L; /* distance a l'origine */ | |
554 | const GLdouble rayon = L/30. ; /* rayon de la base du cone */ | |
555 | //const double Angle = 2. * M_PI/ myNbFacettes; | |
556 | ||
bf75be98 | 557 | glDeleteLists(startList, 4); |
2166f0fa SK |
558 | |
559 | glDisable(GL_LIGHTING); | |
560 | ||
a174a3c5 | 561 | // draw axes labels |
562 | myLabelX.SetPosition (OpenGl_Vec3(float(L + rayon), 0.0f, float(-rayon))); | |
563 | myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(L + 3.0 * rayon), float(2.0 * rayon))); | |
564 | myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(L + 3.0 * rayon))); | |
565 | myLabelX.Render (theWorkspace); | |
566 | myLabelY.Render (theWorkspace); | |
567 | myLabelZ.Render (theWorkspace); | |
2166f0fa | 568 | |
2166f0fa SK |
569 | /*PCD 17/06/07 */ |
570 | glDepthFunc(df); | |
2166f0fa SK |
571 | |
572 | if (!isWithinView) { /* restore matrix */ | |
573 | glMatrixMode (GL_PROJECTION); | |
574 | glPopMatrix (); | |
575 | glMatrixMode (GL_MODELVIEW); | |
576 | glPopMatrix (); | |
577 | } | |
ca3c13d1 | 578 | #endif |
2166f0fa SK |
579 | } |
580 | ||
581 | ||
582 | /*----------------------------------------------------------------------*/ | |
583 | ||
584 | /*----------------------------------------------------------------------*/ | |
585 | /* | |
bf75be98 | 586 | * Fonctions publiques |
2166f0fa SK |
587 | */ |
588 | ||
589 | ||
590 | /* | |
591 | * initialisation d'un triedre non zoomable dans une vue. | |
592 | * ou modification des valeurs deja initialisees. | |
593 | */ | |
594 | ||
595 | //call_triedron_init | |
a174a3c5 | 596 | OpenGl_Trihedron::OpenGl_Trihedron (const Aspect_TypeOfTriedronPosition thePosition, |
597 | const Quantity_NameOfColor theColor, | |
598 | const Standard_Real theScale, | |
599 | const Standard_Boolean theAsWireframe) | |
600 | : myPos (thePosition), | |
601 | myScale (theScale), | |
602 | myIsWireframe (theAsWireframe), | |
b64d84be | 603 | myLabelX ("X", OpenGl_Vec3(1.0f, 0.0f, 0.0f), THE_LABEL_PARAMS), |
604 | myLabelY ("Y", OpenGl_Vec3(0.0f, 1.0f, 0.0f), THE_LABEL_PARAMS), | |
605 | myLabelZ ("Z", OpenGl_Vec3(0.0f, 0.0f, 1.0f), THE_LABEL_PARAMS) | |
2166f0fa SK |
606 | { |
607 | Standard_Real R,G,B; | |
a174a3c5 | 608 | Quantity_Color aColor (theColor); |
609 | aColor.Values (R, G, B, Quantity_TOC_RGB); | |
2166f0fa | 610 | |
fd4a6963 | 611 | CALL_DEF_CONTEXTLINE aLineAspect = myDefaultContextLine; |
612 | aLineAspect.Color.r = (float)R; | |
613 | aLineAspect.Color.g = (float)G; | |
614 | aLineAspect.Color.b = (float)B; | |
615 | myAspectLine.SetAspect (aLineAspect); | |
616 | ||
617 | CALL_DEF_CONTEXTTEXT aTextAspect = myDefaultContextText; | |
618 | aTextAspect.Color.r = (float)R; | |
619 | aTextAspect.Color.g = (float)G; | |
620 | aTextAspect.Color.b = (float)B; | |
621 | myAspectText.SetAspect (aTextAspect); | |
2166f0fa SK |
622 | |
623 | myXColor = theXColor; | |
624 | myYColor = theYColor; | |
625 | myZColor = theZColor; | |
626 | ||
627 | myRatio = theRatio; | |
628 | myDiameter = theDiameter; | |
629 | myNbFacettes = theNbFacettes; | |
630 | } | |
631 | ||
632 | /*----------------------------------------------------------------------*/ | |
633 | ||
634 | /* | |
635 | * destruction du triedre non zoomable d'une vue. | |
636 | */ | |
637 | ||
638 | //call_triedron_erase | |
a174a3c5 | 639 | OpenGl_Trihedron::~OpenGl_Trihedron() |
640 | { | |
641 | } | |
642 | ||
643 | // ======================================================================= | |
644 | // function : Release | |
645 | // purpose : | |
646 | // ======================================================================= | |
10b9c7df | 647 | void OpenGl_Trihedron::Release (OpenGl_Context* theCtx) |
2166f0fa | 648 | { |
a174a3c5 | 649 | myLabelX.Release (theCtx); |
650 | myLabelY.Release (theCtx); | |
651 | myLabelZ.Release (theCtx); | |
30f0ad28 | 652 | myAspectLine.Release (theCtx); |
653 | myAspectText.Release (theCtx); | |
2166f0fa SK |
654 | } |
655 | ||
656 | /*----------------------------------------------------------------------*/ | |
657 | ||
658 | /* | |
bf75be98 | 659 | * affichage d'un triedre non zoomable dans la wks awsid |
2166f0fa SK |
660 | * |
661 | * Triedre = Objet non Zoomable; | |
bf75be98 | 662 | * on cree cette fonction pour pouvoir travailler par les structures |
2166f0fa SK |
663 | * utilisees par les fonctions Tsm* et TEL_VIEW_REP |
664 | * | |
665 | */ | |
666 | ||
667 | //call_triedron_redraw_from_wsid | |
bf75be98 | 668 | void OpenGl_Trihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 669 | { |
bf75be98 | 670 | const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->SetAspectLine (&myAspectLine); |
671 | const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectText); | |
2166f0fa SK |
672 | |
673 | /* check if GL_LIGHTING should be disabled | |
bf75be98 | 674 | no enabling 'cause it will be done (if necessary: kinda Polygon types ) |
2166f0fa SK |
675 | during redrawing structures |
676 | */ | |
bf75be98 | 677 | if (!theWorkspace->UseGLLight()) |
678 | { | |
ca3c13d1 | 679 | #if !defined(GL_ES_VERSION_2_0) |
bf75be98 | 680 | glDisable (GL_LIGHTING); |
ca3c13d1 | 681 | #endif |
bf75be98 | 682 | } |
2166f0fa | 683 | |
bf75be98 | 684 | const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); |
2166f0fa SK |
685 | |
686 | /* affichage du Triedre Non Zoomable */ | |
30f0ad28 | 687 | theWorkspace->ActiveView()->EndTransformPersistence (theWorkspace->GetGlContext()); |
2166f0fa SK |
688 | |
689 | if (myIsWireframe) | |
bf75be98 | 690 | { |
a174a3c5 | 691 | redraw (theWorkspace); |
bf75be98 | 692 | } |
2166f0fa | 693 | else |
bf75be98 | 694 | { |
a174a3c5 | 695 | redrawZBuffer (theWorkspace); |
bf75be98 | 696 | } |
2166f0fa | 697 | |
bf75be98 | 698 | // restore aspects |
699 | if (!aPrevTexture.IsNull()) | |
700 | { | |
701 | theWorkspace->EnableTexture (aPrevTexture); | |
702 | } | |
2166f0fa | 703 | |
bf75be98 | 704 | theWorkspace->SetAspectText (aPrevAspectText); |
705 | theWorkspace->SetAspectLine (aPrevAspectLine); | |
2166f0fa SK |
706 | } |
707 | ||
708 | /*----------------------------------------------------------------------*/ | |
709 | //call_ztriedron_setup | |
710 | void OpenGl_Trihedron::Setup (const Quantity_NameOfColor XColor, const Quantity_NameOfColor YColor, const Quantity_NameOfColor ZColor, | |
711 | const Standard_Real SizeRatio, const Standard_Real AxisDiametr, const Standard_Integer NbFacettes) | |
712 | { | |
713 | Standard_Real R,G,B; | |
714 | ||
715 | Quantity_Color(XColor).Values(R, G, B, Quantity_TOC_RGB); | |
716 | theXColor.rgb[0] = float (R); | |
717 | theXColor.rgb[1] = float (G); | |
718 | theXColor.rgb[2] = float (B); | |
719 | ||
720 | Quantity_Color(YColor).Values(R, G, B, Quantity_TOC_RGB); | |
721 | theYColor.rgb[0] = float (R); | |
722 | theYColor.rgb[1] = float (G); | |
723 | theYColor.rgb[2] = float (B); | |
724 | ||
725 | Quantity_Color(ZColor).Values(R, G, B, Quantity_TOC_RGB); | |
726 | theZColor.rgb[0] = float (R); | |
727 | theZColor.rgb[1] = float (G); | |
728 | theZColor.rgb[2] = float (B); | |
729 | ||
730 | theRatio = float (SizeRatio); | |
731 | theDiameter = float (AxisDiametr); | |
732 | theNbFacettes = NbFacettes; | |
733 | } |