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
8 // under the terms of the GNU Lesser General Public 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 #ifndef OpenGl_Text_Header
17 #define OpenGl_Text_Header
19 #include <OpenGl_Element.hxx>
21 #include <OpenGl_AspectText.hxx>
22 #include <OpenGl_TextParam.hxx>
23 #include <OpenGl_TextFormatter.hxx>
25 #include <TCollection_ExtendedString.hxx>
26 #include <Graphic3d_Vertex.hxx>
27 #include <Graphic3d_HorizontalTextAlignment.hxx>
28 #include <Graphic3d_VerticalTextAlignment.hxx>
30 class Handle(OpenGl_PrinterContext);
33 class OpenGl_Text : public OpenGl_Element
39 Standard_EXPORT OpenGl_Text (const TCollection_ExtendedString& theText,
40 const OpenGl_Vec3& thePoint,
41 const OpenGl_TextParam& theParams);
43 //! Setup new string and position
44 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
45 const Standard_Utf8Char* theText,
46 const OpenGl_Vec3& thePoint);
48 //! Setup new string and parameters
49 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
50 const Standard_Utf8Char* theText,
51 const OpenGl_Vec3& thePoint,
52 const OpenGl_TextParam& theParams);
54 //! Setup new position
55 Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
57 //! Setup new font size
58 Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
59 const Standard_Integer theFontSize);
61 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
62 Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theContext);
64 public: //! @name methods for compatibility with layers
69 //! Create key for shared resource
70 static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect,
71 const Standard_Integer theHeight);
73 //! Find shared resource for specified font or initialize new one
74 static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
75 const OpenGl_AspectText& theAspect,
76 const Standard_Integer theHeight,
77 const TCollection_AsciiString theKey);
79 //! Compute text width
80 static void StringSize (const Handle(OpenGl_Context)& theCtx,
81 const NCollection_String& theText,
82 const OpenGl_AspectText& theTextAspect,
83 const OpenGl_TextParam& theParams,
84 Standard_ShortReal& theWidth,
85 Standard_ShortReal& theAscent,
86 Standard_ShortReal& theDescent);
88 //! Setup new string and parameters
89 void Init (const Handle(OpenGl_Context)& theCtx,
90 const TCollection_ExtendedString& theText,
91 const OpenGl_Vec2& thePoint,
92 const OpenGl_TextParam& theParams);
95 void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
96 const Handle(OpenGl_Context)& theCtx,
97 const OpenGl_AspectText& theTextAspect) const;
102 Standard_EXPORT virtual ~OpenGl_Text();
104 friend class OpenGl_Trihedron;
105 friend class OpenGl_GraduatedTrihedron;
109 //! Release cached VBO resources
110 void releaseVbos (const Handle(OpenGl_Context)& theCtx);
113 void setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
114 const Handle(OpenGl_Context)& theCtx,
115 const OpenGl_AspectText& theTextAspect,
116 const OpenGl_Vec3 theDVec) const;
118 //! Draw arrays of vertices.
119 void drawText (const Handle(OpenGl_PrinterContext)& thePrintCtx,
120 const Handle(OpenGl_Context)& theCtx,
121 const OpenGl_AspectText& theTextAspect) const;
123 //! Main rendering code
124 void render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
125 const Handle(OpenGl_Context)& theCtx,
126 const OpenGl_AspectText& theTextAspect,
127 const TEL_COLOUR& theColorText,
128 const TEL_COLOUR& theColorSubs) const;
132 mutable Handle(OpenGl_Font) myFont;
133 mutable NCollection_Vector<GLuint> myTextures; //!< textures' IDs
134 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo; //!< VBOs of vertices
135 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo; //!< VBOs of texture coordinates
136 mutable NCollection_Vector<Handle(OpenGl_Vec2Array)> myVertsArray; //!< arrays of vertices (for compatibility mode)
137 mutable NCollection_Vector<Handle(OpenGl_Vec2Array)> myTCrdsArray; //!< arrays of vertices (for compatibility mode)
138 mutable Font_FTFont::Rect myBndBox;
142 mutable GLdouble myProjMatrix[16];
143 mutable GLdouble myModelMatrix[16];
144 mutable GLint myViewport[4];
145 mutable GLdouble myWinX;
146 mutable GLdouble myWinY;
147 mutable GLdouble myWinZ;
148 mutable GLdouble myScaleHeight;
149 mutable GLdouble myExportHeight;
153 OpenGl_TextParam myParams;
154 NCollection_String myString;
160 DEFINE_STANDARD_ALLOC
164 #endif //OpenGl_Text_Header