0025703: Visualization - Decrease number of samplers used in ray-tracing mode
[occt.git] / src / OpenGl / OpenGl_Trihedron.cxx
CommitLineData
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
c827ea3a 16#include <OpenGl_Trihedron.hxx>
2166f0fa 17
c827ea3a 18#include <OpenGl_GlCore11.hxx>
2166f0fa 19
2166f0fa 20#include <OpenGl_View.hxx>
c827ea3a 21#include <OpenGl_Workspace.hxx>
2166f0fa 22
a174a3c5 23static const OpenGl_TextParam THE_LABEL_PARAMS =
24{
25 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM
26};
2166f0fa 27
2166f0fa
SK
28static const CALL_DEF_CONTEXTLINE myDefaultContextLine =
29{
30 1, //IsDef
31 1, //IsSet
32 { 1.F, 1.F, 1.F }, //Color
33 Aspect_TOL_SOLID, //LineType
34 1.F //Width
35};
36
37static const CALL_DEF_CONTEXTTEXT myDefaultContextText =
38{
39 1, //IsDef
40 1, //IsSet
41 "Courier", //Font
42 0.3F, //Space
43 1.0F, //Expan
44 { 1.F, 1.F, 1.F }, //Color
45 Aspect_TOST_NORMAL, //Style
46 Aspect_TODT_NORMAL, //DisplayType
47 { 1.F, 1.F, 1.F }, //ColorSubTitle
48 0, //TextZoomable
49 0.F, //TextAngle
eeaaaefb 50 Font_FA_Regular //TextFontAspect
2166f0fa
SK
51};
52
2166f0fa
SK
53static TEL_COLOUR theXColor = {{ 1.F, 0.F, 0.F, 0.6F }};
54static TEL_COLOUR theYColor = {{ 0.F, 1.F, 0.F, 0.6F }};
55static TEL_COLOUR theZColor = {{ 0.F, 0.F, 1.F, 0.6F }};
56static float theRatio = 0.8f;
57static float theDiameter = 0.05f;
58static int theNbFacettes = 12;
59
c827ea3a 60// =======================================================================
61// function : redraw
62// purpose :
63// =======================================================================
a174a3c5 64void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa 65{
ca3c13d1 66#if !defined(GL_ES_VERSION_2_0)
a174a3c5 67 const Standard_Real U = theWorkspace->ActiveView()->Height();
68 const Standard_Real V = theWorkspace->ActiveView()->Width();
2166f0fa 69
c827ea3a 70 Handle(OpenGl_Context) aContext = theWorkspace->GetGlContext();
71
2166f0fa 72 /* la taille des axes est 1 proportion (fixee a l'init du triedre) */
bf75be98 73 /* de la dimension la plus petite de la window. */
2166f0fa
SK
74 const GLdouble L = ( U < V ? U : V ) * myScale;
75
76 /*
77 * On inhibe les translations; on conserve les autres transformations.
78 */
79
c827ea3a 80 aContext->WorldViewState.Push();
81 aContext->ProjectionState.Push();
82
2166f0fa
SK
83 /* on lit les matrices de transformation et de projection de la vue */
84 /* pour annuler les translations (dernieres colonnes des matrices). */
c827ea3a 85 OpenGl_Mat4d aModelMatrix;
86 aModelMatrix.Convert (aContext->WorldViewState.Current());
87
88 OpenGl_Mat4d aProjMatrix;
2166f0fa
SK
89
90 /* on annule la translation qui peut etre affectee a la vue */
c827ea3a 91 aModelMatrix.ChangeValue (0, 3) = 0.0;
92 aModelMatrix.ChangeValue (1, 3) = 0.0;
93 aModelMatrix.ChangeValue (2, 3) = 0.0;
94
95 aProjMatrix.ChangeValue (0, 0) = 2.0 / U;
96 aProjMatrix.ChangeValue (1, 0) = 0.0;
97 aProjMatrix.ChangeValue (2, 0) = 0.0;
98 aProjMatrix.ChangeValue (3, 0) = 0.0;
99
100 aProjMatrix.ChangeValue (0, 1) = 0.0;
101 aProjMatrix.ChangeValue (1, 1) = 2.0 / V;
102 aProjMatrix.ChangeValue (2, 1) = 0.0;
103 aProjMatrix.ChangeValue (3, 1) = 0.0;
104
105 aProjMatrix.ChangeValue (0, 2) = 0.0;
106 aProjMatrix.ChangeValue (1, 2) = 0.0;
107 aProjMatrix.ChangeValue (2, 2) = -2.0 * 1e-7;
108 aProjMatrix.ChangeValue (3, 2) = 0.0;
109
110 aProjMatrix.ChangeValue (0, 3) = 0.0;
111 aProjMatrix.ChangeValue (1, 3) = 0.0;
112 aProjMatrix.ChangeValue (2, 3) = 0.0;
113 aProjMatrix.ChangeValue (3, 3) = 1.0;
2166f0fa
SK
114
115 /*
116 * Positionnement de l'origine du triedre selon le choix de l'init
117 */
118
119 /* on fait uniquement une translation de l'origine du Triedre */
120
121 switch (myPos)
122 {
123 case Aspect_TOTP_LEFT_LOWER :
c827ea3a 124 {
125 OpenGl_Utils::Translate (aProjMatrix,
126 -0.5 * U + L, -0.5 * V + L, 0.0);
127 }
128 break;
2166f0fa
SK
129
130 case Aspect_TOTP_LEFT_UPPER :
c827ea3a 131 {
132 OpenGl_Utils::Translate (aProjMatrix,
133 -0.5 * U + L, 0.5 * V - L - L/3.0, 0.0);
134 }
135 break;
2166f0fa
SK
136
137 case Aspect_TOTP_RIGHT_LOWER :
c827ea3a 138 {
139 OpenGl_Utils::Translate (aProjMatrix,
140 0.5 * U - L - L/3.0, -0.5 * V + L, 0.0);
141 }
142 break;
2166f0fa
SK
143
144 case Aspect_TOTP_RIGHT_UPPER :
c827ea3a 145 {
146 OpenGl_Utils::Translate (aProjMatrix,
147 0.5 * U - L - L/3.0, 0.5 * V - L - L/3.0, 0.0);
148 }
149 break;
2166f0fa
SK
150
151 //case Aspect_TOTP_CENTER :
152 default :
153 break;
154 }
155
c827ea3a 156 aContext->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix);
157 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
158 aContext->ApplyProjectionMatrix();
159 aContext->ApplyWorldViewMatrix();
160
bf75be98 161 /*
162 * Creation du triedre
2166f0fa 163 */
2166f0fa 164
bf75be98 165 /* Fotis Sioutis 2007-11-14 15:06
166 I have also seen in previous posts that the view trihedron in V3d_WIREFRAME mode
167 changes colors depending on the state of the view. This behaviour can be easily
2166f0fa 168 corrected by altering call_triedron_redraw function in OpenGl_triedron.c of TKOpengl.
bf75be98 169 The only change needed is to erase glDisable(GL_LIGHTING) that is called before the
2166f0fa 170 Axis name drawing and move this function call just before the initial axis drawing.
bf75be98 171 Below is the code portion with the modification.I don't know if this is considered to
2166f0fa
SK
172 be a bug but anyway i believe it might help some of you out there.*/
173 glDisable(GL_LIGHTING);
2166f0fa
SK
174
175 /* Position de l'origine */
176 const GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 };
177
178 /* Position des Axes */
179 GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
180 GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
181 GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 };
182 TriedronAxeX[0] = L ;
183 TriedronAxeY[1] = L ;
184 TriedronAxeZ[2] = L ;
185
186 /* dessin des axes */
187 glBegin(GL_LINES);
188 glVertex3dv( TriedronOrigin );
189 glVertex3dv( TriedronAxeX );
190
191 glVertex3dv( TriedronOrigin );
192 glVertex3dv( TriedronAxeY );
193
194 glVertex3dv( TriedronOrigin );
195 glVertex3dv( TriedronAxeZ );
196 glEnd();
197
198 /* fleches au bout des axes (= cones de la couleur demandee) */
199 const GLdouble l = 0.75*L; /* distance a l'origine */
200 const GLdouble rayon = L/30. ; /* rayon de la base du cone */
201 const int NbFacettes = 12; /* le cone sera compose de 12 facettes triangulaires */
202 const double Angle = 2. * M_PI/ NbFacettes;
203
204 int ii;
205 GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 };
206
207 /* solution FILAIRE des cones au bout des axes : une seule ligne */
208 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
209 /* (la couleur est deja initialisee dans AspectLine) */
210 /* FIN de la solution FILAIRE CHOISIE pour les cones des axes */
211
212 /* fleche en X */
213 glBegin(GL_TRIANGLE_FAN);
214 glVertex3dv( TriedronAxeX );
215 TriedronCoord[0] = l;
216 ii = NbFacettes;
217 while (ii >= 0 ) {
218 TriedronCoord[1] = rayon * sin(ii * Angle);
219 TriedronCoord[2] = rayon * cos(ii * Angle);
220 glVertex3dv( TriedronCoord );
221 ii--;
222 }
223 glEnd();
224
225 /* fleche en Y */
226 glBegin(GL_TRIANGLE_FAN);
227 glVertex3dv( TriedronAxeY );
228 TriedronCoord[1] = l;
229 ii = NbFacettes;
230 while (ii >= 0 ) {
231 TriedronCoord[0] = rayon * cos(ii * Angle);
232 TriedronCoord[2] = rayon * sin(ii * Angle);
233 glVertex3dv( TriedronCoord );
234 ii--;
235 }
236 glEnd();
237
238 /* fleche en Z */
239 glBegin(GL_TRIANGLE_FAN);
240 glVertex3dv( TriedronAxeZ );
241 TriedronCoord[2] = l;
242 ii = NbFacettes;
243 while (ii >= 0 ) {
244 TriedronCoord[0] = rayon * sin(ii * Angle);
245 TriedronCoord[1] = rayon * cos(ii * Angle);
246 glVertex3dv( TriedronCoord );
247 ii--;
248 }
249 glEnd();
250
251 /* dessin de l'origine */
252 TriedronCoord[2] = 0.0 ;
253 ii = 24 ;
254 const double Angle1 = 2. * M_PI/ ii;
255 glBegin(GL_LINE_LOOP);
256 while (ii >= 0 ) {
257 TriedronCoord[0] = rayon * sin(ii * Angle1);
258 TriedronCoord[1] = rayon * cos(ii * Angle1);
259 glVertex3dv( TriedronCoord );
260 ii--;
bf75be98 261 }
2166f0fa
SK
262 glEnd();
263
a174a3c5 264 // draw axes labels
265 myLabelX.SetPosition (OpenGl_Vec3(float(L + rayon), 0.0f, float(-rayon)));
266 myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(L + 3.0 * rayon), float(2.0 * rayon)));
267 myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(L + 3.0 * rayon)));
268 myLabelX.Render (theWorkspace);
269 myLabelY.Render (theWorkspace);
270 myLabelZ.Render (theWorkspace);
2166f0fa 271
bf75be98 272 /*
2166f0fa
SK
273 * restauration du contexte des matrices
274 */
c827ea3a 275
276 aContext->WorldViewState.Pop();
277 aContext->ProjectionState.Pop();
278 aContext->ApplyProjectionMatrix();
ca3c13d1 279#endif
2166f0fa
SK
280}
281
c827ea3a 282// =======================================================================
283// function : redrawZBuffer
284// purpose :
285// =======================================================================
a174a3c5 286void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa 287{
c827ea3a 288 Handle(OpenGl_Context) aContext = theWorkspace->GetGlContext();
289 const Handle(OpenGl_View)& aView = theWorkspace->ActiveView();
2166f0fa 290
c827ea3a 291 OpenGl_Mat4d aModelMatrix, aProjMatrix;
292 aContext->WorldViewState.Push();
293 aContext->ProjectionState.Push();
294 aModelMatrix.Convert (aContext->WorldViewState.Current());
2166f0fa 295
c827ea3a 296 GLdouble U = 1.0;
297 GLdouble V = 1.0;
298 if (aView->Height() < aView->Width())
2166f0fa 299 {
c827ea3a 300 V = aView->Width() / aView->Height();
301 }
302 else
303 {
304 U = aView->Height() / aView->Width();
2166f0fa
SK
305 }
306
c827ea3a 307 GLdouble aScale = myScale;
2166f0fa 308
c827ea3a 309 // Annulate translation matrix
310 aModelMatrix.ChangeValue (0, 3) = 0.0;
311 aModelMatrix.ChangeValue (1, 3) = 0.0;
312 aModelMatrix.ChangeValue (2, 3) = 0.0;
2166f0fa 313
c827ea3a 314 aProjMatrix.ChangeValue (0, 0) = 2.0 / U;
315 aProjMatrix.ChangeValue (1, 0) = 0.0;
316 aProjMatrix.ChangeValue (2, 0) = 0.0;
317 aProjMatrix.ChangeValue (3, 0) = 0.0;
2166f0fa 318
c827ea3a 319 aProjMatrix.ChangeValue (0, 1) = 0.0;
320 aProjMatrix.ChangeValue (1, 1) = 2.0 / V;
321 aProjMatrix.ChangeValue (2, 1) = 0.0;
322 aProjMatrix.ChangeValue (3, 1) = 0.0;
2166f0fa 323
c827ea3a 324 aProjMatrix.ChangeValue (0, 2) = 0.0;
325 aProjMatrix.ChangeValue (1, 2) = 0.0;
326 aProjMatrix.ChangeValue (2, 2) = -2.0 * 1e-2;
327 aProjMatrix.ChangeValue (3, 2) = 0.0;
2166f0fa 328
c827ea3a 329 aProjMatrix.ChangeValue (0, 3) = 0.0;
330 aProjMatrix.ChangeValue (1, 3) = 0.0;
331 aProjMatrix.ChangeValue (2, 3) = 0.0;
332 aProjMatrix.ChangeValue (3, 3) = 1.0;
2166f0fa 333
c827ea3a 334 // Define position in the view
335 switch (myPos)
2166f0fa 336 {
c827ea3a 337 case Aspect_TOTP_LEFT_LOWER:
338 {
339 OpenGl_Utils::Translate<Standard_Real> (aProjMatrix,
340 -0.5 * U + aScale, -0.5 * V + aScale, 0.0);
341 break;
342 }
343 case Aspect_TOTP_LEFT_UPPER:
bf75be98 344 {
c827ea3a 345 OpenGl_Utils::Translate<Standard_Real> (aProjMatrix,
346 -0.5 * U + aScale, 0.5 * V - aScale - aScale / 3.0, 0.0);
347 break;
348 }
349 case Aspect_TOTP_RIGHT_LOWER:
350 {
351 OpenGl_Utils::Translate<Standard_Real> (aProjMatrix,
352 0.5 * U - aScale - aScale / 3.0, -0.5 * V + aScale, 0.0);
353 break;
2166f0fa 354 }
c827ea3a 355 case Aspect_TOTP_RIGHT_UPPER:
2166f0fa 356 {
c827ea3a 357 OpenGl_Utils::Translate<Standard_Real> (aProjMatrix,
358 0.5 * U - aScale - aScale / 3.0, 0.5 * V - aScale - aScale / 3.0, 0.0);
359 break;
2166f0fa 360 }
c827ea3a 361 //case Aspect_TOTP_CENTER:
362 default:
363 break;
364 }
365 aScale *= myRatio;
2166f0fa 366
c827ea3a 367 aContext->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix);
368 aContext->ApplyProjectionMatrix();
2166f0fa 369
c827ea3a 370 const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True);
371 const TEL_COLOUR& aLineColor = anAspectLine->Color();
2166f0fa 372
c827ea3a 373 // Create the trihedron
374 const Standard_Real THE_CYLINDER_LENGTH = 0.75;
375 const GLdouble aCylinderLength = aScale * THE_CYLINDER_LENGTH;
376 const GLdouble aCylinderDiametr = aScale * myDiameter;
377 const GLdouble aConeDiametr = aCylinderDiametr * 2.0;
378 const GLdouble aConeLength = aScale * (1.0 - THE_CYLINDER_LENGTH);
2166f0fa 379
c827ea3a 380 // Position des Axes
381 GLdouble aTriedronAxeX[3] = { aScale, 0.0, 0.0 };
382 GLdouble aTriedronAxeY[3] = { 0.0, aScale, 0.0 };
383 if (!myDisk.IsDefined())
384 {
385 myDisk.Init (static_cast<GLfloat> (aCylinderDiametr),
386 static_cast<GLfloat> (aConeDiametr),
387 myNbFacettes, 1);
388 }
2166f0fa 389
c827ea3a 390 if (!mySphere.IsDefined())
391 {
392 mySphere.Init (static_cast<GLfloat> (aCylinderDiametr * 2.0), myNbFacettes, myNbFacettes);
2166f0fa 393 }
2166f0fa 394
c827ea3a 395 if (!myCone.IsDefined())
396 {
397 myCone.Init (static_cast<GLfloat> (aConeDiametr), 0.0f, static_cast<GLfloat> (aConeLength), myNbFacettes, 1);
398 }
2166f0fa 399
c827ea3a 400 if (!myCylinder.IsDefined())
401 {
402 myCylinder.Init (static_cast<GLfloat> (aCylinderDiametr),
403 static_cast<GLfloat> (aCylinderDiametr),
404 static_cast<GLfloat> (aCylinderLength),
405 myNbFacettes, 1);
406 }
2166f0fa 407
c827ea3a 408 GLboolean wasDepthMaskEnabled = GL_FALSE;
409 GLint aDepthFuncBack = 0, aCullFaceModeBack = GL_BACK;
410 const GLboolean wasDepthEnabled = aContext->core11fwd->glIsEnabled (GL_DEPTH_TEST);
411 const GLboolean wasCullFaceEnabled = aContext->core11fwd->glIsEnabled (GL_CULL_FACE);
412 aContext->core11fwd->glGetIntegerv (GL_DEPTH_FUNC, &aDepthFuncBack);
413 aContext->core11fwd->glGetIntegerv (GL_CULL_FACE_MODE, &aCullFaceModeBack);
414 aContext->core11fwd->glGetBooleanv (GL_DEPTH_WRITEMASK, &wasDepthMaskEnabled);
415 if (!wasDepthEnabled)
416 {
417 aContext->core11fwd->glEnable (GL_DEPTH_TEST);
418 aContext->core11fwd->glClear (GL_DEPTH_BUFFER_BIT);
419 }
420 if (!wasDepthMaskEnabled)
421 {
422 aContext->core11fwd->glDepthMask (GL_TRUE);
423 }
424 aContext->core11fwd->glCullFace (GL_BACK);
425 if (!wasCullFaceEnabled)
426 {
427 aContext->core11fwd->glEnable (GL_CULL_FACE);
428 }
2166f0fa 429
c827ea3a 430 OpenGl_AspectFace anAspectC;
431 OpenGl_AspectFace anAspectX;
432 OpenGl_AspectFace anAspectY;
433 OpenGl_AspectFace anAspectZ;
434 memcpy (anAspectX.ChangeIntFront().matcol.rgb, myXColor.rgb, sizeof (TEL_COLOUR));
435 memcpy (anAspectY.ChangeIntFront().matcol.rgb, myYColor.rgb, sizeof (TEL_COLOUR));
436 memcpy (anAspectZ.ChangeIntFront().matcol.rgb, myZColor.rgb, sizeof (TEL_COLOUR));
437 memcpy (anAspectC.ChangeIntFront().matcol.rgb, aLineColor.rgb, sizeof (TEL_COLOUR));
438 for (Standard_Integer aPass = 0; aPass < 2; ++aPass)
439 {
440 OpenGl_Mat4d aModelViewX (aModelMatrix);
441 OpenGl_Mat4d aModelViewY (aModelMatrix);
442 OpenGl_Mat4d aModelViewZ (aModelMatrix);
443 aContext->core11fwd->glDepthFunc (aPass == 0 ? GL_ALWAYS : GL_LEQUAL);
2166f0fa 444
c827ea3a 445 const OpenGl_AspectFace* anOldAspect = theWorkspace->SetAspectFace (&anAspectC);
2166f0fa 446
c827ea3a 447 // Origin
448 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
449 aContext->ApplyWorldViewMatrix();
450 mySphere.Render (theWorkspace);
2166f0fa 451
c827ea3a 452 // Z axis
453 theWorkspace->SetAspectFace (&anAspectZ);
454 myCylinder.Render (theWorkspace);
455 OpenGl_Utils::Translate (aModelViewZ, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH);
456 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewZ);
457 aContext->ApplyWorldViewMatrix();
458 myDisk.Render (theWorkspace);
459 myCone.Render (theWorkspace);
2166f0fa 460
c827ea3a 461 // X axis
462 theWorkspace->SetAspectFace (&anAspectX);
463 OpenGl_Utils::Rotate (aModelViewX, 90.0, aTriedronAxeY[0], aTriedronAxeY[1], aTriedronAxeY[2]);
464 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX);
465 aContext->ApplyWorldViewMatrix();
466 myCylinder.Render (theWorkspace);
467 OpenGl_Utils::Translate (aModelViewX, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH);
468 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX);
469 aContext->ApplyWorldViewMatrix();
470 myDisk.Render (theWorkspace);
471 myCone.Render (theWorkspace);
2166f0fa 472
c827ea3a 473 // Y axis
474 theWorkspace->SetAspectFace (&anAspectY);
475 OpenGl_Utils::Rotate (aModelViewY, -90.0, aTriedronAxeX[0], aTriedronAxeX[1], aTriedronAxeX[2]);
476 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY);
477 aContext->ApplyWorldViewMatrix();
478 myCylinder.Render (theWorkspace);
479 OpenGl_Utils::Translate (aModelViewY, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH);
480 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY);
481 aContext->ApplyWorldViewMatrix();
482 myDisk.Render (theWorkspace);
483 myCone.Render (theWorkspace);
484
485 theWorkspace->SetAspectFace (anOldAspect);
486 }
487
488 if (!wasDepthEnabled)
489 {
490 aContext->core11fwd->glDisable (GL_DEPTH_TEST);
491 }
492 if (!wasDepthMaskEnabled)
493 {
494 aContext->core11fwd->glDepthMask (GL_FALSE);
495 }
496 if (!wasCullFaceEnabled)
497 {
498 aContext->core11fwd->glDisable (GL_CULL_FACE);
499 }
500 aContext->core11fwd->glCullFace (aCullFaceModeBack);
501
502 // Always write the text
503 aContext->core11fwd->glDepthFunc (GL_ALWAYS);
2166f0fa 504
a174a3c5 505 // draw axes labels
c827ea3a 506 const GLdouble rayon = aScale / 30.0;
507 myLabelX.SetPosition (OpenGl_Vec3(float(aScale + 2.0 * rayon), 0.0f, float(-rayon)));
508 myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(aScale + 3.0 * rayon), float(2.0 * rayon)));
509 myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(aScale + 3.0 * rayon)));
510 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
511 aContext->ApplyWorldViewMatrix();
a174a3c5 512 myLabelX.Render (theWorkspace);
513 myLabelY.Render (theWorkspace);
514 myLabelZ.Render (theWorkspace);
2166f0fa 515
c827ea3a 516 aContext->core11fwd->glDepthFunc (aDepthFuncBack);
2166f0fa 517
c827ea3a 518 aContext->WorldViewState.Pop();
519 aContext->ProjectionState.Pop();
520 aContext->ApplyProjectionMatrix();
2166f0fa
SK
521}
522
c827ea3a 523// =======================================================================
524// function : OpenGl_Trihedron
525// purpose :
526// =======================================================================
a174a3c5 527OpenGl_Trihedron::OpenGl_Trihedron (const Aspect_TypeOfTriedronPosition thePosition,
528 const Quantity_NameOfColor theColor,
529 const Standard_Real theScale,
530 const Standard_Boolean theAsWireframe)
531: myPos (thePosition),
532 myScale (theScale),
533 myIsWireframe (theAsWireframe),
b64d84be 534 myLabelX ("X", OpenGl_Vec3(1.0f, 0.0f, 0.0f), THE_LABEL_PARAMS),
535 myLabelY ("Y", OpenGl_Vec3(0.0f, 1.0f, 0.0f), THE_LABEL_PARAMS),
536 myLabelZ ("Z", OpenGl_Vec3(0.0f, 0.0f, 1.0f), THE_LABEL_PARAMS)
2166f0fa
SK
537{
538 Standard_Real R,G,B;
a174a3c5 539 Quantity_Color aColor (theColor);
540 aColor.Values (R, G, B, Quantity_TOC_RGB);
2166f0fa 541
fd4a6963 542 CALL_DEF_CONTEXTLINE aLineAspect = myDefaultContextLine;
543 aLineAspect.Color.r = (float)R;
544 aLineAspect.Color.g = (float)G;
545 aLineAspect.Color.b = (float)B;
546 myAspectLine.SetAspect (aLineAspect);
547
548 CALL_DEF_CONTEXTTEXT aTextAspect = myDefaultContextText;
549 aTextAspect.Color.r = (float)R;
550 aTextAspect.Color.g = (float)G;
551 aTextAspect.Color.b = (float)B;
552 myAspectText.SetAspect (aTextAspect);
2166f0fa
SK
553
554 myXColor = theXColor;
555 myYColor = theYColor;
556 myZColor = theZColor;
557
558 myRatio = theRatio;
559 myDiameter = theDiameter;
560 myNbFacettes = theNbFacettes;
561}
562
c827ea3a 563// =======================================================================
564// function : ~OpenGl_Trihedron
565// purpose :
566// =======================================================================
a174a3c5 567OpenGl_Trihedron::~OpenGl_Trihedron()
568{
569}
570
571// =======================================================================
572// function : Release
573// purpose :
574// =======================================================================
10b9c7df 575void OpenGl_Trihedron::Release (OpenGl_Context* theCtx)
2166f0fa 576{
a174a3c5 577 myLabelX.Release (theCtx);
578 myLabelY.Release (theCtx);
579 myLabelZ.Release (theCtx);
30f0ad28 580 myAspectLine.Release (theCtx);
581 myAspectText.Release (theCtx);
c827ea3a 582 myCone .Release (theCtx);
583 myDisk .Release (theCtx);
584 mySphere .Release (theCtx);
585 myCylinder.Release (theCtx);
2166f0fa
SK
586}
587
c827ea3a 588// =======================================================================
589// function : Render
590// purpose :
591// =======================================================================
bf75be98 592void OpenGl_Trihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa 593{
bf75be98 594 const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->SetAspectLine (&myAspectLine);
595 const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectText);
2166f0fa
SK
596
597 /* check if GL_LIGHTING should be disabled
bf75be98 598 no enabling 'cause it will be done (if necessary: kinda Polygon types )
2166f0fa
SK
599 during redrawing structures
600 */
bf75be98 601 if (!theWorkspace->UseGLLight())
602 {
ca3c13d1 603 #if !defined(GL_ES_VERSION_2_0)
bf75be98 604 glDisable (GL_LIGHTING);
ca3c13d1 605 #endif
bf75be98 606 }
2166f0fa 607
bf75be98 608 const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture();
30f0ad28 609 theWorkspace->ActiveView()->EndTransformPersistence (theWorkspace->GetGlContext());
a86ce5a6 610 theWorkspace->GetGlContext()->ApplyModelViewMatrix();
2166f0fa
SK
611
612 if (myIsWireframe)
bf75be98 613 {
a174a3c5 614 redraw (theWorkspace);
bf75be98 615 }
2166f0fa 616 else
bf75be98 617 {
a174a3c5 618 redrawZBuffer (theWorkspace);
bf75be98 619 }
2166f0fa 620
bf75be98 621 // restore aspects
622 if (!aPrevTexture.IsNull())
623 {
624 theWorkspace->EnableTexture (aPrevTexture);
625 }
2166f0fa 626
bf75be98 627 theWorkspace->SetAspectText (aPrevAspectText);
628 theWorkspace->SetAspectLine (aPrevAspectLine);
2166f0fa
SK
629}
630
631/*----------------------------------------------------------------------*/
632//call_ztriedron_setup
633void OpenGl_Trihedron::Setup (const Quantity_NameOfColor XColor, const Quantity_NameOfColor YColor, const Quantity_NameOfColor ZColor,
634 const Standard_Real SizeRatio, const Standard_Real AxisDiametr, const Standard_Integer NbFacettes)
635{
636 Standard_Real R,G,B;
637
638 Quantity_Color(XColor).Values(R, G, B, Quantity_TOC_RGB);
639 theXColor.rgb[0] = float (R);
640 theXColor.rgb[1] = float (G);
641 theXColor.rgb[2] = float (B);
642
643 Quantity_Color(YColor).Values(R, G, B, Quantity_TOC_RGB);
644 theYColor.rgb[0] = float (R);
645 theYColor.rgb[1] = float (G);
646 theYColor.rgb[2] = float (B);
647
648 Quantity_Color(ZColor).Values(R, G, B, Quantity_TOC_RGB);
649 theZColor.rgb[0] = float (R);
650 theZColor.rgb[1] = float (G);
651 theZColor.rgb[2] = float (B);
652
653 theRatio = float (SizeRatio);
654 theDiameter = float (AxisDiametr);
655 theNbFacettes = NbFacettes;
656}