1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OpenGl_AspectText.hxx>
17 #include <OpenGl_GlCore11.hxx>
18 #include <OpenGl_GraphicDriver.hxx>
19 #include <OpenGl_ShaderManager.hxx>
20 #include <OpenGl_ShaderProgram.hxx>
21 #include <OpenGl_ShaderStates.hxx>
22 #include <OpenGl_Text.hxx>
23 #include <OpenGl_Workspace.hxx>
24 #include <OpenGl_View.hxx>
26 #include <Font_FontMgr.hxx>
27 #include <Graphic3d_TransformUtils.hxx>
28 #include <TCollection_HAsciiString.hxx>
36 static const GLdouble THE_IDENTITY_MATRIX[16] =
45 static char const* TheFamily[] = {"Helvetica", "Courier", "Times"};
46 static char const* TheItalic[] = {"Oblique", "Oblique", "Italic"};
47 static char const* TheBase[] = {"", "", "-Roman"};
49 //! Convert font name used for rendering to some "good" font names
50 //! that produce good vector text.
51 static void getGL2PSFontName (const char* theSrcFont,
54 if (strstr (theSrcFont, "Symbol"))
56 sprintf (thePsFont, "%s", "Symbol");
59 else if (strstr (theSrcFont, "ZapfDingbats"))
61 sprintf (thePsFont, "%s", "WingDings");
67 bool isItalic = false;
68 if (strstr (theSrcFont, "Courier"))
72 else if (strstr (theSrcFont, "Times"))
77 if (strstr (theSrcFont, "Bold"))
81 if (strstr (theSrcFont, "Italic")
82 || strstr (theSrcFont, "Oblique"))
91 sprintf (thePsFont, "%s-Bold%s", TheFamily[aFontId], TheItalic[aFontId]);
95 sprintf (thePsFont, "%s-Bold", TheFamily[aFontId]);
100 sprintf (thePsFont, "%s-%s", TheFamily[aFontId], TheItalic[aFontId]);
104 sprintf (thePsFont, "%s%s", TheFamily[aFontId], TheBase[aFontId]);
108 static void exportText (const NCollection_String& theText,
109 const Standard_Boolean theIs2d,
110 const OpenGl_AspectText& theAspect,
111 const Standard_Integer theHeight)
115 getGL2PSFontName (theAspect.FontName().ToCString(), aPsFont);
117 #if !defined(GL_ES_VERSION_2_0)
120 glRasterPos2f (0.0f, 0.0f);
124 glRasterPos3f (0.0f, 0.0f, 0.0f);
128 glBitmap (1, 1, 0, 0, 0, 0, &aZero);
131 // Standard GL2PS's alignment isn't used, because it doesn't work correctly
132 // for all formats, therefore alignment is calculated manually relative
133 // to the bottom-left corner, which corresponds to the GL2PS_TEXT_BL value
134 gl2psTextOpt (theText.ToCString(), aPsFont, (GLshort)theHeight, GL2PS_TEXT_BL, theAspect.Angle());
140 // =======================================================================
141 // function : OpenGl_Text
143 // =======================================================================
144 OpenGl_Text::OpenGl_Text()
148 myScaleHeight (1.0f),
149 myPoint (0.0f, 0.0f, 0.0f),
153 myParams.Height = 10;
154 myParams.HAlign = Graphic3d_HTA_LEFT;
155 myParams.VAlign = Graphic3d_VTA_BOTTOM;
158 // =======================================================================
159 // function : OpenGl_Text
161 // =======================================================================
162 OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText,
163 const OpenGl_Vec3& thePoint,
164 const OpenGl_TextParam& theParams)
168 myScaleHeight (1.0f),
169 myExportHeight (1.0f),
170 myParams (theParams),
179 // =======================================================================
180 // function : OpenGl_Text
182 // =======================================================================
183 OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText,
184 const gp_Ax2& theOrientation,
185 const OpenGl_TextParam& theParams)
190 myExportHeight (1.0),
191 myParams (theParams),
194 myOrientation (theOrientation),
197 const gp_Pnt& aPoint = theOrientation.Location();
198 myPoint = OpenGl_Vec3 (static_cast<Standard_ShortReal> (aPoint.X()),
199 static_cast<Standard_ShortReal> (aPoint.Y()),
200 static_cast<Standard_ShortReal> (aPoint.Z()));
203 // =======================================================================
204 // function : SetPosition
206 // =======================================================================
207 void OpenGl_Text::SetPosition (const OpenGl_Vec3& thePoint)
212 // =======================================================================
213 // function : SetFontSize
215 // =======================================================================
216 void OpenGl_Text::SetFontSize (const Handle(OpenGl_Context)& theCtx,
217 const Standard_Integer theFontSize)
219 if (myParams.Height != theFontSize)
221 Release (theCtx.operator->());
223 myParams.Height = theFontSize;
226 // =======================================================================
229 // =======================================================================
230 void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx,
231 const Standard_Utf8Char* theText,
232 const OpenGl_Vec3& thePoint)
234 releaseVbos (theCtx.operator->());
237 myString.FromUnicode (theText);
240 // =======================================================================
243 // =======================================================================
244 void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx,
245 const Standard_Utf8Char* theText,
246 const OpenGl_Vec3& thePoint,
247 const OpenGl_TextParam& theParams)
249 if (myParams.Height != theParams.Height)
251 Release (theCtx.operator->());
255 releaseVbos (theCtx.operator->());
258 myParams = theParams;
260 myString.FromUnicode (theText);
263 // =======================================================================
266 // =======================================================================
267 void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx,
268 const TCollection_ExtendedString& theText,
269 const OpenGl_Vec2& thePoint,
270 const OpenGl_TextParam& theParams)
272 if (myParams.Height != theParams.Height)
274 Release (theCtx.operator->());
278 releaseVbos (theCtx.operator->());
281 myParams = theParams;
282 myPoint.xy() = thePoint;
284 myString.FromUnicode ((Standard_Utf16Char* )theText.ToExtString());
287 // =======================================================================
288 // function : ~OpenGl_Text
290 // =======================================================================
291 OpenGl_Text::~OpenGl_Text()
296 // =======================================================================
297 // function : releaseVbos
299 // =======================================================================
300 void OpenGl_Text::releaseVbos (OpenGl_Context* theCtx)
302 for (Standard_Integer anIter = 0; anIter < myVertsVbo.Length(); ++anIter)
304 Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.ChangeValue (anIter);
305 Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.ChangeValue (anIter);
309 theCtx->DelayedRelease (aVerts);
310 theCtx->DelayedRelease (aTCrds);
320 // =======================================================================
321 // function : Release
323 // =======================================================================
324 void OpenGl_Text::Release (OpenGl_Context* theCtx)
326 releaseVbos (theCtx);
327 if (!myFont.IsNull())
329 Handle(OpenGl_Context) aCtx = theCtx;
330 const TCollection_AsciiString aKey = myFont->ResourceKey();
333 aCtx->ReleaseResource (aKey, Standard_True);
337 // =======================================================================
338 // function : StringSize
340 // =======================================================================
341 void OpenGl_Text::StringSize (const Handle(OpenGl_Context)& theCtx,
342 const NCollection_String& theText,
343 const OpenGl_AspectText& theTextAspect,
344 const OpenGl_TextParam& theParams,
345 const unsigned int theResolution,
346 Standard_ShortReal& theWidth,
347 Standard_ShortReal& theAscent,
348 Standard_ShortReal& theDescent)
353 const TCollection_AsciiString aFontKey = FontKey (theTextAspect, theParams.Height, theResolution);
354 Handle(OpenGl_Font) aFont = FindFont (theCtx, theTextAspect, theParams.Height, theResolution, aFontKey);
355 if (aFont.IsNull() || !aFont->IsValid())
360 theAscent = aFont->Ascender();
361 theDescent = aFont->Descender();
363 GLfloat aWidth = 0.0f;
364 for (NCollection_Utf8Iter anIter = theText.Iterator(); *anIter != 0;)
366 const Standard_Utf32Char aCharThis = *anIter;
367 const Standard_Utf32Char aCharNext = *++anIter;
369 if (aCharThis == '\x0D' // CR (carriage return)
370 || aCharThis == '\a' // BEL (alarm)
371 || aCharThis == '\f' // FF (form feed) NP (new page)
372 || aCharThis == '\b' // BS (backspace)
373 || aCharThis == '\v') // VT (vertical tab)
375 continue; // skip unsupported carriage control codes
377 else if (aCharThis == '\x0A') // LF (line feed, new line)
379 theWidth = Max (theWidth, aWidth);
383 else if (aCharThis == ' ')
385 aWidth += aFont->AdvanceX (aCharThis, aCharNext);
388 else if (aCharThis == '\t')
390 aWidth += aFont->AdvanceX (' ', aCharNext) * 8.0f;
394 aWidth += aFont->AdvanceX (aCharThis, aCharNext);
396 theWidth = Max (theWidth, aWidth);
398 Handle(OpenGl_Context) aCtx = theCtx;
400 aCtx->ReleaseResource (aFontKey, Standard_True);
403 // =======================================================================
406 // =======================================================================
407 void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
409 const OpenGl_AspectText* aTextAspect = theWorkspace->AspectText (Standard_True);
410 const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture();
411 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
413 // Bind custom shader program or generate default version
414 if (aCtx->core20fwd != NULL)
416 aCtx->ShaderManager()->BindProgram (
417 aTextAspect, aTextAspect->ShaderProgramRes (aCtx));
420 myOrientationMatrix = theWorkspace->View()->Camera()->OrientationMatrix();
421 myProjMatrix.Convert (aCtx->ProjectionState.Current());
423 // use highlight color or colors from aspect
424 if (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT)
426 render (theWorkspace->PrinterContext(),
429 *theWorkspace->HighlightColor,
430 *theWorkspace->HighlightColor,
431 theWorkspace->View()->RenderingParams().Resolution);
435 render (theWorkspace->PrinterContext(),
438 aTextAspect->Color(),
439 aTextAspect->SubtitleColor(),
440 theWorkspace->View()->RenderingParams().Resolution);
443 aCtx->BindProgram (NULL);
446 if (!aPrevTexture.IsNull())
448 theWorkspace->EnableTexture (aPrevTexture);
451 // restore Z buffer settings
452 if (theWorkspace->UseZBuffer())
454 glEnable (GL_DEPTH_TEST);
458 // =======================================================================
461 // =======================================================================
462 void OpenGl_Text::Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
463 const Handle(OpenGl_Context)& theCtx,
464 const OpenGl_AspectText& theTextAspect,
465 const unsigned int theResolution) const
467 render (thePrintCtx, theCtx, theTextAspect, theTextAspect.Color(), theTextAspect.SubtitleColor(), theResolution);
470 // =======================================================================
471 // function : setupMatrix
473 // =======================================================================
474 void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
475 const Handle(OpenGl_Context)& theCtx,
476 const OpenGl_AspectText& theTextAspect,
477 const OpenGl_Vec3 theDVec) const
479 OpenGl_Mat4d aModViewMat;
480 OpenGl_Mat4d aProjectMat;
484 aProjectMat = myProjMatrix * myOrientationMatrix;
488 aProjectMat = myProjMatrix;
493 Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, myPoint.x() + theDVec.x(), myPoint.y() + theDVec.y(), 0.f);
494 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, 1.f, -1.f, 1.f);
495 Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Angle(), 0.f, 0.f, 1.f);
499 // align coordinates to the nearest integer
500 // to avoid extra interpolation issues
501 GLdouble anObjX, anObjY, anObjZ;
502 Graphic3d_TransformUtils::UnProject<Standard_Real> (std::floor (myWinX + theDVec.x()),
503 std::floor (myWinY + theDVec.y()),
504 myWinZ + theDVec.z(),
505 OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
506 OpenGl_Mat4d::Map (aProjectMat),
514 const gp_Dir& aVectorDir = myOrientation.XDirection();
515 const gp_Dir& aVectorUp = myOrientation.Direction();
516 const gp_Dir& aVectorRight = myOrientation.YDirection();
518 aModViewMat.SetColumn (3, OpenGl_Vec3d (anObjX, anObjY, anObjZ));
519 aModViewMat.SetColumn (2, OpenGl_Vec3d (aVectorUp.X(), aVectorUp.Y(), aVectorUp.Z()));
520 aModViewMat.SetColumn (1, OpenGl_Vec3d (aVectorRight.X(), aVectorRight.Y(), aVectorRight.Z()));
521 aModViewMat.SetColumn (0, OpenGl_Vec3d (aVectorDir.X(), aVectorDir.Y(), aVectorDir.Z()));
525 Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
526 Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0);
529 if (!theTextAspect.IsZoomable())
532 // if the context has assigned printer context, use it's parameters
533 if (!thePrintCtx.IsNull())
535 // get printing scaling in x and y dimensions
536 GLfloat aTextScalex = 1.0f, aTextScaley = 1.0f;
537 thePrintCtx->GetScale (aTextScalex, aTextScaley);
539 // text should be scaled in all directions with same
540 // factor to save its proportions, so use height (y) scaling
541 // as it is better for keeping text/3d graphics proportions
542 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, aTextScaley, aTextScaley, aTextScaley);
545 Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight);
549 theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat);
550 theCtx->ApplyWorldViewMatrix();
554 theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjectMat);
555 theCtx->ApplyProjectionMatrix();
558 if (!theCtx->ActiveProgram().IsNull())
560 // Upload updated state to shader program
561 theCtx->ShaderManager()->PushState (theCtx->ActiveProgram());
565 // =======================================================================
566 // function : drawText
568 // =======================================================================
570 void OpenGl_Text::drawText (const Handle(OpenGl_PrinterContext)& ,
571 const Handle(OpenGl_Context)& theCtx,
573 const OpenGl_AspectText& theTextAspect) const
575 const OpenGl_AspectText& ) const
579 if (theCtx->IsFeedback())
581 // position of the text and alignment is calculated by transformation matrix
582 exportText (myString, myIs2d, theTextAspect, (Standard_Integer )myExportHeight);
587 if (myVertsVbo.Length() != myTextures.Length()
588 || myTextures.IsEmpty())
593 for (Standard_Integer anIter = 0; anIter < myTextures.Length(); ++anIter)
595 const GLuint aTexId = myTextures.Value (anIter);
596 glBindTexture (GL_TEXTURE_2D, aTexId);
598 const Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.Value (anIter);
599 const Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.Value (anIter);
600 aVerts->BindAttribute (theCtx, Graphic3d_TOA_POS);
601 aTCrds->BindAttribute (theCtx, Graphic3d_TOA_UV);
603 glDrawArrays (GL_TRIANGLES, 0, GLsizei(aVerts->GetElemsNb()));
605 aTCrds->UnbindAttribute (theCtx, Graphic3d_TOA_UV);
606 aVerts->UnbindAttribute (theCtx, Graphic3d_TOA_POS);
608 glBindTexture (GL_TEXTURE_2D, 0);
611 // =======================================================================
612 // function : FontKey
614 // =======================================================================
615 TCollection_AsciiString OpenGl_Text::FontKey (const OpenGl_AspectText& theAspect,
616 const Standard_Integer theHeight,
617 const unsigned int theResolution)
619 const Font_FontAspect anAspect = (theAspect.FontAspect() != Font_FA_Undefined) ? theAspect.FontAspect() : Font_FA_Regular;
620 return theAspect.FontName()
621 + TCollection_AsciiString(":") + Standard_Integer(anAspect)
622 + TCollection_AsciiString(":") + Standard_Integer(theResolution)
623 + TCollection_AsciiString(":") + theHeight;
626 // =======================================================================
627 // function : FindFont
629 // =======================================================================
630 Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
631 const OpenGl_AspectText& theAspect,
632 const Standard_Integer theHeight,
633 const unsigned int theResolution,
634 const TCollection_AsciiString theKey)
636 Handle(OpenGl_Font) aFont;
639 return aFont; // invalid parameters
642 if (!theCtx->GetResource (theKey, aFont))
644 Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance();
645 const Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (theAspect.FontName());
646 const Font_FontAspect anAspect = (theAspect.FontAspect() != Font_FA_Undefined) ? theAspect.FontAspect() : Font_FA_Regular;
647 Handle(Font_SystemFont) aRequestedFont = aFontMgr->FindFont (aFontName, anAspect, theHeight);
648 Handle(Font_FTFont) aFontFt;
649 if (!aRequestedFont.IsNull())
651 aFontFt = new Font_FTFont (NULL);
653 if (aFontFt->Init (aRequestedFont->FontPath()->ToCString(), theHeight, theResolution))
655 aFont = new OpenGl_Font (aFontFt, theKey);
656 if (!aFont->Init (theCtx))
658 TCollection_ExtendedString aMsg;
660 aMsg += theAspect.FontName();
661 aMsg += "' - initialization of GL resources has failed!";
662 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
664 aFont->Release (theCtx.operator->());
665 aFont = new OpenGl_Font (aFontFt, theKey);
670 TCollection_ExtendedString aMsg;
672 aMsg += theAspect.FontName();
673 aMsg += "' is broken or has incompatible format! File path: ";
674 aMsg += aRequestedFont->FontPath()->ToCString();
675 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
677 aFont = new OpenGl_Font (aFontFt, theKey);
682 TCollection_ExtendedString aMsg;
684 aMsg += theAspect.FontName();
685 aMsg += "' is not found in the system!";
686 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
687 aFont = new OpenGl_Font (aFontFt, theKey);
690 theCtx->ShareResource (theKey, aFont);
695 // =======================================================================
698 // =======================================================================
699 void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
700 const Handle(OpenGl_Context)& theCtx,
701 const OpenGl_AspectText& theTextAspect,
702 const TEL_COLOUR& theColorText,
703 const TEL_COLOUR& theColorSubs,
704 const unsigned int theResolution) const
706 if (myString.IsEmpty())
711 // Note that using difference resolution in different Views in same Viewer
712 // will lead to performance regression (for example, text will be recreated every time).
713 const TCollection_AsciiString aFontKey = FontKey (theTextAspect, myParams.Height, theResolution);
715 && !myFont->ResourceKey().IsEqual (aFontKey))
718 const_cast<OpenGl_Text* > (this)->Release (theCtx.operator->());
723 myFont = FindFont (theCtx, theTextAspect, myParams.Height, theResolution, aFontKey);
725 if (!myFont->WasInitialized())
730 if (myTextures.IsEmpty())
732 Font_TextFormatter aFormatter;
733 aFormatter.SetupAlignment (myParams.HAlign, myParams.VAlign);
736 aFormatter.Append (myString, *myFont->FTFont());
739 OpenGl_TextBuilder aBuilder;
740 aBuilder.Perform (aFormatter,
742 *myFont.operator->(),
747 aFormatter.BndBox (myBndBox);
750 if (myTextures.IsEmpty())
755 myExportHeight = 1.0f;
756 myScaleHeight = 1.0f;
758 theCtx->WorldViewState.Push();
760 myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current());
764 glGetIntegerv (GL_VIEWPORT, myViewport);
766 Graphic3d_TransformUtils::Project<Standard_Real> (myPoint.x(),
776 // compute scale factor for constant text height
778 Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX,
781 OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
789 const GLdouble h = (GLdouble )myFont->FTFont()->PointSize();
790 Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX,
793 OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
800 myScaleHeight = (y2 - y1) / h;
801 if (theTextAspect.IsZoomable())
803 myExportHeight = (float )h;
806 myExportHeight = (float )myFont->FTFont()->PointSize() / myExportHeight;
808 #if !defined(GL_ES_VERSION_2_0)
809 if (theCtx->core11 != NULL)
811 glDisable (GL_LIGHTING);
817 || theTextAspect.StyleType() == Aspect_TOST_ANNOTATION)
819 glDisable (GL_DEPTH_TEST);
822 if (theCtx->core15fwd != NULL)
824 theCtx->core15fwd->glActiveTexture (GL_TEXTURE0);
826 #if !defined(GL_ES_VERSION_2_0)
827 // activate texture unit
828 GLint aTexEnvParam = GL_REPLACE;
829 if (theCtx->core11 != NULL)
832 glAlphaFunc (GL_GEQUAL, 0.285f);
833 glEnable (GL_ALPHA_TEST);
835 glDisable (GL_TEXTURE_1D);
836 glEnable (GL_TEXTURE_2D);
837 glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam);
838 if (aTexEnvParam != GL_REPLACE)
840 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
847 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
850 switch (theTextAspect.DisplayType())
852 case Aspect_TODT_BLEND:
854 #if !defined(GL_ES_VERSION_2_0)
855 glEnable (GL_COLOR_LOGIC_OP);
860 case Aspect_TODT_SUBTITLE:
862 #if !defined(GL_ES_VERSION_2_0)
863 if (theCtx->core11 != NULL)
865 theCtx->core11->glColor3fv (theColorSubs.rgb);
866 setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f));
868 glBindTexture (GL_TEXTURE_2D, 0);
870 glVertex2f (myBndBox.Left, myBndBox.Top);
871 glVertex2f (myBndBox.Right, myBndBox.Top);
872 glVertex2f (myBndBox.Right, myBndBox.Bottom);
873 glVertex2f (myBndBox.Left, myBndBox.Bottom);
879 case Aspect_TODT_DEKALE:
881 theCtx->SetColor4fv (*(const OpenGl_Vec4* )theColorSubs.rgb);
882 setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.00001f));
883 drawText (thePrintCtx, theCtx, theTextAspect);
884 setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, -1.0f, 0.00001f));
885 drawText (thePrintCtx, theCtx, theTextAspect);
886 setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, +1.0f, 0.00001f));
887 drawText (thePrintCtx, theCtx, theTextAspect);
888 setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.00001f));
889 drawText (thePrintCtx, theCtx, theTextAspect);
892 case Aspect_TODT_DIMENSION:
893 case Aspect_TODT_NORMAL:
900 theCtx->SetColor4fv (*(const OpenGl_Vec4* )theColorText.rgb);
901 setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
902 drawText (thePrintCtx, theCtx, theTextAspect);
906 theCtx->ProjectionState.SetCurrent<Standard_Real> (myProjMatrix);
907 theCtx->ApplyProjectionMatrix();
910 #if !defined(GL_ES_VERSION_2_0)
911 if (theCtx->core11 != NULL)
913 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, aTexEnvParam);
917 if (theTextAspect.DisplayType() == Aspect_TODT_DIMENSION)
919 setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f));
921 glDisable (GL_BLEND);
924 glDisable (GL_DEPTH_TEST);
926 #if !defined(GL_ES_VERSION_2_0)
927 if (theCtx->core11 != NULL)
929 glDisable (GL_TEXTURE_2D);
930 glDisable (GL_ALPHA_TEST);
933 glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
935 glClear (GL_STENCIL_BUFFER_BIT);
936 glEnable (GL_STENCIL_TEST);
937 glStencilFunc (GL_ALWAYS, 1, 0xFF);
938 glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE);
940 #if !defined(GL_ES_VERSION_2_0)
941 if (theCtx->core11 != NULL)
944 glVertex2f (myBndBox.Left, myBndBox.Top);
945 glVertex2f (myBndBox.Right, myBndBox.Top);
946 glVertex2f (myBndBox.Right, myBndBox.Bottom);
947 glVertex2f (myBndBox.Left, myBndBox.Bottom);
952 glStencilFunc (GL_ALWAYS, 0, 0xFF);
954 glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
957 // reset OpenGL state
958 glDisable (GL_BLEND);
959 glDisable (GL_STENCIL_TEST);
960 #if !defined(GL_ES_VERSION_2_0)
961 if (theCtx->core11 != NULL)
963 glDisable (GL_ALPHA_TEST);
965 glDisable (GL_COLOR_LOGIC_OP);
968 // model view matrix was modified
969 theCtx->WorldViewState.Pop();
970 theCtx->ApplyModelViewMatrix();