0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[occt.git] / src / OpenGl / OpenGl_Text.hxx
CommitLineData
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
bf5f0ca2 21#include <OpenGl_Aspects.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>
4b1c8733 28#include <Graphic3d_RenderingParams.hxx>
2166f0fa
SK
29#include <Graphic3d_VerticalTextAlignment.hxx>
30
ce01ec26 31#include <gp_Ax2.hxx>
32
a174a3c5 33//! Text rendering
2166f0fa
SK
34class OpenGl_Text : public OpenGl_Element
35{
5e27df78 36
37public:
2166f0fa 38
a174a3c5 39 //! Main constructor
b64d84be 40 Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText,
41 const OpenGl_Vec3& thePoint,
42 const OpenGl_TextParam& theParams);
a174a3c5 43
ce01ec26 44 //! Creates new text in 3D space.
45 Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText,
46 const gp_Ax2& theOrientation,
3f1eb0ab 47 const OpenGl_TextParam& theParams,
48 const bool theHasOwnAnchor = true);
ce01ec26 49
5e30547b 50 //! Destructor
51 Standard_EXPORT virtual ~OpenGl_Text();
52
a174a3c5 53 //! Setup new string and position
54 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
55 const Standard_Utf8Char* theText,
56 const OpenGl_Vec3& thePoint);
57
58 //! Setup new string and parameters
59 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
60 const Standard_Utf8Char* theText,
61 const OpenGl_Vec3& thePoint,
62 const OpenGl_TextParam& theParams);
63
64 //! Setup new position
65 Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
66
67 //! Setup new font size
68 Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
69 const Standard_Integer theFontSize);
70
71 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
10b9c7df 72 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
a174a3c5 73
5e30547b 74 //! Return defined text.
75 const NCollection_String& Text() const { return myString; }
76
77 //! Return text formatting parameters.
78 const OpenGl_TextParam& FormatParams() const { return myParams; }
79
a174a3c5 80public: //! @name methods for compatibility with layers
81
82 //! Empty constructor
6a240ff8 83 Standard_EXPORT OpenGl_Text();
a174a3c5 84
85 //! Create key for shared resource
bf5f0ca2 86 Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_Aspects& theAspect,
87 Standard_Integer theHeight,
88 unsigned int theResolution);
a174a3c5 89
90 //! Find shared resource for specified font or initialize new one
6a240ff8 91 Standard_EXPORT static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 92 const OpenGl_Aspects& theAspect,
93 Standard_Integer theHeight,
94 unsigned int theResolution,
95 const TCollection_AsciiString& theKey);
a174a3c5 96
97 //! Compute text width
6a240ff8 98 Standard_EXPORT static void StringSize (const Handle(OpenGl_Context)& theCtx,
99 const NCollection_String& theText,
bf5f0ca2 100 const OpenGl_Aspects& theTextAspect,
6a240ff8 101 const OpenGl_TextParam& theParams,
4b1c8733 102 const unsigned int theResolution,
6a240ff8 103 Standard_ShortReal& theWidth,
104 Standard_ShortReal& theAscent,
105 Standard_ShortReal& theDescent);
a174a3c5 106
107 //! Setup new string and parameters
6a240ff8 108 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
109 const TCollection_ExtendedString& theText,
110 const OpenGl_Vec2& thePoint,
111 const OpenGl_TextParam& theParams);
a174a3c5 112
113 //! Perform rendering
60273f77 114 Standard_EXPORT void Render (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 115 const OpenGl_Aspects& theTextAspect,
116 unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION) const;
a174a3c5 117
118protected:
119
a174a3c5 120 friend class OpenGl_Trihedron;
121 friend class OpenGl_GraduatedTrihedron;
122
a174a3c5 123 //! Release cached VBO resources
15669413 124 Standard_EXPORT void releaseVbos (OpenGl_Context* theCtx);
125
126private:
a174a3c5 127
128 //! Setup matrix.
60273f77 129 void setupMatrix (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 130 const OpenGl_Aspects& theTextAspect,
131 const OpenGl_Vec3& theDVec) const;
a174a3c5 132
133 //! Draw arrays of vertices.
60273f77 134 void drawText (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 135 const OpenGl_Aspects& theTextAspect) const;
a174a3c5 136
6fe58c66 137 //! Draw rectangle from bounding text box.
138 void drawRect (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 139 const OpenGl_Aspects& theTextAspect,
140 const OpenGl_Vec4& theColorSubs) const;
6fe58c66 141
a174a3c5 142 //! Main rendering code
60273f77 143 void render (const Handle(OpenGl_Context)& theCtx,
bf5f0ca2 144 const OpenGl_Aspects& theTextAspect,
145 const OpenGl_Vec4& theColorText,
146 const OpenGl_Vec4& theColorSubs,
147 unsigned int theResolution) const;
a174a3c5 148
149protected:
2166f0fa 150
a174a3c5 151 mutable Handle(OpenGl_Font) myFont;
152 mutable NCollection_Vector<GLuint> myTextures; //!< textures' IDs
153 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo; //!< VBOs of vertices
154 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo; //!< VBOs of texture coordinates
6fe58c66 155 mutable Handle(OpenGl_VertexBuffer) myBndVertsVbo;//!< VBOs of vertices for bounding box
d2eddacc 156 mutable Font_Rect myBndBox;
5e27df78 157
158protected:
159
c827ea3a 160 mutable OpenGl_Mat4d myProjMatrix;
161 mutable OpenGl_Mat4d myModelMatrix;
ce01ec26 162 mutable OpenGl_Mat4d myOrientationMatrix;
a174a3c5 163 mutable GLdouble myWinX;
164 mutable GLdouble myWinY;
165 mutable GLdouble myWinZ;
166 mutable GLdouble myScaleHeight;
167 mutable GLdouble myExportHeight;
2166f0fa 168
5e27df78 169protected:
2166f0fa 170
a174a3c5 171 OpenGl_TextParam myParams;
172 NCollection_String myString;
173 OpenGl_Vec3 myPoint;
174 bool myIs2d;
ce01ec26 175 gp_Ax2 myOrientation; //!< Text orientation in 3D space.
176 bool myHasPlane; //!< Check if text have orientation in 3D space.
3f1eb0ab 177 bool myHasAnchorPoint; //!< Shows if it has own attach point
2166f0fa 178
5e27df78 179public:
180
1c35b92f 181 DEFINE_STANDARD_ALLOC
5e27df78 182
2166f0fa
SK
183};
184
185#endif //OpenGl_Text_Header