Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-07-13 |
2 | // Created by: Sergey ZERCHANINOV | |
a174a3c5 | 3 | // Copyright (c) 2011-2013 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 | |
2166f0fa SK |
16 | #ifndef OpenGl_Text_Header |
17 | #define OpenGl_Text_Header | |
18 | ||
19 | #include <OpenGl_Element.hxx> | |
20 | ||
a174a3c5 | 21 | #include <OpenGl_AspectText.hxx> |
2166f0fa | 22 | #include <OpenGl_TextParam.hxx> |
317d68c9 | 23 | #include <OpenGl_TextBuilder.hxx> |
2166f0fa SK |
24 | |
25 | #include <TCollection_ExtendedString.hxx> | |
26 | #include <Graphic3d_Vertex.hxx> | |
27 | #include <Graphic3d_HorizontalTextAlignment.hxx> | |
28 | #include <Graphic3d_VerticalTextAlignment.hxx> | |
29 | ||
c04c30b3 | 30 | class OpenGl_PrinterContext; |
a174a3c5 | 31 | |
32 | //! Text rendering | |
2166f0fa SK |
33 | class OpenGl_Text : public OpenGl_Element |
34 | { | |
5e27df78 | 35 | |
36 | public: | |
2166f0fa | 37 | |
a174a3c5 | 38 | //! Main constructor |
b64d84be | 39 | Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText, |
40 | const OpenGl_Vec3& thePoint, | |
41 | const OpenGl_TextParam& theParams); | |
a174a3c5 | 42 | |
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); | |
47 | ||
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); | |
53 | ||
54 | //! Setup new position | |
55 | Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint); | |
56 | ||
57 | //! Setup new font size | |
58 | Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext, | |
59 | const Standard_Integer theFontSize); | |
60 | ||
61 | Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; | |
10b9c7df | 62 | Standard_EXPORT virtual void Release (OpenGl_Context* theContext); |
a174a3c5 | 63 | |
64 | public: //! @name methods for compatibility with layers | |
65 | ||
66 | //! Empty constructor | |
6a240ff8 | 67 | Standard_EXPORT OpenGl_Text(); |
a174a3c5 | 68 | |
69 | //! Create key for shared resource | |
6a240ff8 | 70 | Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect, |
71 | const Standard_Integer theHeight); | |
a174a3c5 | 72 | |
73 | //! Find shared resource for specified font or initialize new one | |
6a240ff8 | 74 | Standard_EXPORT 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); | |
a174a3c5 | 78 | |
79 | //! Compute text width | |
6a240ff8 | 80 | Standard_EXPORT 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); | |
a174a3c5 | 87 | |
88 | //! Setup new string and parameters | |
6a240ff8 | 89 | Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx, |
90 | const TCollection_ExtendedString& theText, | |
91 | const OpenGl_Vec2& thePoint, | |
92 | const OpenGl_TextParam& theParams); | |
a174a3c5 | 93 | |
94 | //! Perform rendering | |
6a240ff8 | 95 | Standard_EXPORT void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx, |
96 | const Handle(OpenGl_Context)& theCtx, | |
97 | const OpenGl_AspectText& theTextAspect) const; | |
a174a3c5 | 98 | |
99 | protected: | |
100 | ||
101 | //! Destructor | |
102 | Standard_EXPORT virtual ~OpenGl_Text(); | |
103 | ||
104 | friend class OpenGl_Trihedron; | |
105 | friend class OpenGl_GraduatedTrihedron; | |
106 | ||
107 | private: | |
108 | ||
109 | //! Release cached VBO resources | |
10b9c7df | 110 | void releaseVbos (OpenGl_Context* theCtx); |
a174a3c5 | 111 | |
112 | //! Setup matrix. | |
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; | |
117 | ||
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; | |
122 | ||
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; | |
129 | ||
130 | protected: | |
2166f0fa | 131 | |
a174a3c5 | 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 | |
a174a3c5 | 136 | mutable Font_FTFont::Rect myBndBox; |
5e27df78 | 137 | |
138 | protected: | |
139 | ||
c827ea3a | 140 | mutable OpenGl_Mat4d myProjMatrix; |
141 | mutable OpenGl_Mat4d myModelMatrix; | |
a174a3c5 | 142 | mutable GLint myViewport[4]; |
143 | mutable GLdouble myWinX; | |
144 | mutable GLdouble myWinY; | |
145 | mutable GLdouble myWinZ; | |
146 | mutable GLdouble myScaleHeight; | |
147 | mutable GLdouble myExportHeight; | |
2166f0fa | 148 | |
5e27df78 | 149 | protected: |
2166f0fa | 150 | |
a174a3c5 | 151 | OpenGl_TextParam myParams; |
152 | NCollection_String myString; | |
153 | OpenGl_Vec3 myPoint; | |
154 | bool myIs2d; | |
2166f0fa | 155 | |
5e27df78 | 156 | public: |
157 | ||
1c35b92f | 158 | DEFINE_STANDARD_ALLOC |
5e27df78 | 159 | |
2166f0fa SK |
160 | }; |
161 | ||
162 | #endif //OpenGl_Text_Header |