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 #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_TextBuilder.hxx>
25 #include <TCollection_ExtendedString.hxx>
26 #include <Graphic3d_Vertex.hxx>
27 #include <Graphic3d_HorizontalTextAlignment.hxx>
28 #include <Graphic3d_RenderingParams.hxx>
29 #include <Graphic3d_VerticalTextAlignment.hxx>
33 class OpenGl_PrinterContext;
36 class OpenGl_Text : public OpenGl_Element
42 Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText,
43 const OpenGl_Vec3& thePoint,
44 const OpenGl_TextParam& theParams);
46 //! Creates new text in 3D space.
47 Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText,
48 const gp_Ax2& theOrientation,
49 const OpenGl_TextParam& theParams);
51 //! Setup new string and position
52 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
53 const Standard_Utf8Char* theText,
54 const OpenGl_Vec3& thePoint);
56 //! Setup new string and parameters
57 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
58 const Standard_Utf8Char* theText,
59 const OpenGl_Vec3& thePoint,
60 const OpenGl_TextParam& theParams);
62 //! Setup new position
63 Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
65 //! Setup new font size
66 Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
67 const Standard_Integer theFontSize);
69 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
70 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
72 public: //! @name methods for compatibility with layers
75 Standard_EXPORT OpenGl_Text();
77 //! Create key for shared resource
78 Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect,
79 const Standard_Integer theHeight,
80 const unsigned int theResolution);
82 //! Find shared resource for specified font or initialize new one
83 Standard_EXPORT static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
84 const OpenGl_AspectText& theAspect,
85 const Standard_Integer theHeight,
86 const unsigned int theResolution,
87 const TCollection_AsciiString theKey);
89 //! Compute text width
90 Standard_EXPORT static void StringSize (const Handle(OpenGl_Context)& theCtx,
91 const NCollection_String& theText,
92 const OpenGl_AspectText& theTextAspect,
93 const OpenGl_TextParam& theParams,
94 const unsigned int theResolution,
95 Standard_ShortReal& theWidth,
96 Standard_ShortReal& theAscent,
97 Standard_ShortReal& theDescent);
99 //! Setup new string and parameters
100 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
101 const TCollection_ExtendedString& theText,
102 const OpenGl_Vec2& thePoint,
103 const OpenGl_TextParam& theParams);
105 //! Perform rendering
106 Standard_EXPORT void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
107 const Handle(OpenGl_Context)& theCtx,
108 const OpenGl_AspectText& theTextAspect,
109 const unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION) const;
114 Standard_EXPORT virtual ~OpenGl_Text();
116 friend class OpenGl_Trihedron;
117 friend class OpenGl_GraduatedTrihedron;
121 //! Release cached VBO resources
122 void releaseVbos (OpenGl_Context* theCtx);
125 void setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
126 const Handle(OpenGl_Context)& theCtx,
127 const OpenGl_AspectText& theTextAspect,
128 const OpenGl_Vec3 theDVec) const;
130 //! Draw arrays of vertices.
131 void drawText (const Handle(OpenGl_PrinterContext)& thePrintCtx,
132 const Handle(OpenGl_Context)& theCtx,
133 const OpenGl_AspectText& theTextAspect) const;
135 //! Main rendering code
136 void render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
137 const Handle(OpenGl_Context)& theCtx,
138 const OpenGl_AspectText& theTextAspect,
139 const TEL_COLOUR& theColorText,
140 const TEL_COLOUR& theColorSubs,
141 const unsigned int theResolution) const;
145 mutable Handle(OpenGl_Font) myFont;
146 mutable NCollection_Vector<GLuint> myTextures; //!< textures' IDs
147 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo; //!< VBOs of vertices
148 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo; //!< VBOs of texture coordinates
149 mutable Font_Rect myBndBox;
153 mutable OpenGl_Mat4d myProjMatrix;
154 mutable OpenGl_Mat4d myModelMatrix;
155 mutable OpenGl_Mat4d myOrientationMatrix;
156 mutable GLint myViewport[4];
157 mutable GLdouble myWinX;
158 mutable GLdouble myWinY;
159 mutable GLdouble myWinZ;
160 mutable GLdouble myScaleHeight;
161 mutable GLdouble myExportHeight;
165 OpenGl_TextParam myParams;
166 NCollection_String myString;
169 gp_Ax2 myOrientation; //!< Text orientation in 3D space.
170 bool myHasPlane; //!< Check if text have orientation in 3D space.
174 DEFINE_STANDARD_ALLOC
178 #endif //OpenGl_Text_Header