1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 #ifndef OpenGl_Text_Header
21 #define OpenGl_Text_Header
23 #include <OpenGl_Element.hxx>
25 #include <OpenGl_AspectText.hxx>
26 #include <OpenGl_TextParam.hxx>
27 #include <OpenGl_TextFormatter.hxx>
29 #include <TCollection_ExtendedString.hxx>
30 #include <Graphic3d_Vertex.hxx>
31 #include <Graphic3d_HorizontalTextAlignment.hxx>
32 #include <Graphic3d_VerticalTextAlignment.hxx>
34 class Handle(OpenGl_PrinterContext);
37 class OpenGl_Text : public OpenGl_Element
43 Standard_EXPORT OpenGl_Text (const TCollection_ExtendedString& theText,
44 const OpenGl_Vec3& thePoint,
45 const OpenGl_TextParam& theParams);
47 //! Setup new string and position
48 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
49 const Standard_Utf8Char* theText,
50 const OpenGl_Vec3& thePoint);
52 //! Setup new string and parameters
53 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
54 const Standard_Utf8Char* theText,
55 const OpenGl_Vec3& thePoint,
56 const OpenGl_TextParam& theParams);
58 //! Setup new position
59 Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
61 //! Setup new font size
62 Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
63 const Standard_Integer theFontSize);
65 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
66 Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theContext);
68 public: //! @name methods for compatibility with layers
73 //! Create key for shared resource
74 static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect,
75 const Standard_Integer theHeight);
77 //! Find shared resource for specified font or initialize new one
78 static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
79 const OpenGl_AspectText& theAspect,
80 const Standard_Integer theHeight,
81 const TCollection_AsciiString theKey);
83 //! Compute text width
84 static void StringSize (const Handle(OpenGl_Context)& theCtx,
85 const NCollection_String& theText,
86 const OpenGl_AspectText& theTextAspect,
87 const OpenGl_TextParam& theParams,
88 Standard_ShortReal& theWidth,
89 Standard_ShortReal& theAscent,
90 Standard_ShortReal& theDescent);
92 //! Setup new string and parameters
93 void Init (const Handle(OpenGl_Context)& theCtx,
94 const TCollection_ExtendedString& theText,
95 const OpenGl_Vec2& thePoint,
96 const OpenGl_TextParam& theParams);
99 void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
100 const Handle(OpenGl_Context)& theCtx,
101 const OpenGl_AspectText& theTextAspect) const;
106 Standard_EXPORT virtual ~OpenGl_Text();
108 friend class OpenGl_Trihedron;
109 friend class OpenGl_GraduatedTrihedron;
113 //! Release cached VBO resources
114 void releaseVbos (const Handle(OpenGl_Context)& theCtx);
117 void setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
118 const Handle(OpenGl_Context)& theCtx,
119 const OpenGl_AspectText& theTextAspect,
120 const OpenGl_Vec3 theDVec) const;
122 //! Draw arrays of vertices.
123 void drawText (const Handle(OpenGl_PrinterContext)& thePrintCtx,
124 const Handle(OpenGl_Context)& theCtx,
125 const OpenGl_AspectText& theTextAspect) const;
127 //! Main rendering code
128 void render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
129 const Handle(OpenGl_Context)& theCtx,
130 const OpenGl_AspectText& theTextAspect,
131 const TEL_COLOUR& theColorText,
132 const TEL_COLOUR& theColorSubs) const;
136 mutable Handle(OpenGl_Font) myFont;
137 mutable NCollection_Vector<GLuint> myTextures; //!< textures' IDs
138 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo; //!< VBOs of vertices
139 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo; //!< VBOs of texture coordinates
140 mutable NCollection_Vector<Handle(OpenGl_Vec2Array)> myVertsArray; //!< arrays of vertices (for compatibility mode)
141 mutable NCollection_Vector<Handle(OpenGl_Vec2Array)> myTCrdsArray; //!< arrays of vertices (for compatibility mode)
142 mutable Font_FTFont::Rect myBndBox;
146 mutable GLdouble myProjMatrix[16];
147 mutable GLdouble myModelMatrix[16];
148 mutable GLint myViewport[4];
149 mutable GLdouble myWinX;
150 mutable GLdouble myWinY;
151 mutable GLdouble myWinZ;
152 mutable GLdouble myScaleHeight;
153 mutable GLdouble myExportHeight;
157 OpenGl_TextParam myParams;
158 NCollection_String myString;
164 DEFINE_STANDARD_ALLOC
168 #endif //OpenGl_Text_Header