MRPT  2.0.3
CText.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
13 
14 namespace mrpt::opengl
15 {
16 /** A 2D text (bitmap rendering): it always "faces the observer" despite it's at
17  * some 3D location.
18  * Use setString and setFont to change the text displayed by this object.
19  *
20  * \note All texts appear with the font GLUT_BITMAP_TIMES_ROMAN_10 for now
21  * (i.e. setFont is ignored)
22  * \sa opengl::COpenGLScene
23  *
24  * <div align="center">
25  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
26  * border-style: solid;">
27  * <tr> <td> mrpt::opengl::CText </td> <td> \image html preview_CText.png
28  * </td> </tr>
29  * </table>
30  * </div>
31  *
32  * \sa CText3D
33  * \ingroup mrpt_opengl_grp
34  */
36 {
38  protected:
39  std::string m_str;
40  std::string m_fontName = "sans";
41  int m_fontHeight = 20, m_fontWidth = 0;
42 
43  void onUpdateBuffers_Text() override;
44 
45  public:
46  /** Sets the text to display */
47  void setString(const std::string& s)
48  {
49  if (m_str == s) return;
50  m_str = s;
52  }
53  /** Return the current text associated to this label */
54  std::string getString() const { return m_str; }
55  /** Sets the font (It has no effect yet!) */
56  void setFont(const std::string& s, int height)
57  {
58  if (m_fontName == s && m_fontHeight == height) return;
59  m_fontName = s;
60  m_fontHeight = height;
62  }
63  std::string getFont() const { return m_fontName; }
64 
65  shader_list_t requiredShaders() const override
66  {
67  return {DefaultShaderID::TEXT};
68  }
69  void render(const RenderContext& rc) const override;
70 
71  /** Evaluates the bounding box of this object (including possible children)
72  * in the coordinate frame of the object parent. */
73  void getBoundingBox(
75  mrpt::math::TPoint3D& bb_max) const override;
76 
77  /** Constructor */
78  CText(const std::string& str = std::string("")) : m_str(str) {}
79 
80  virtual ~CText() override;
81 };
82 
83 } // namespace mrpt::opengl
mrpt::opengl::CRenderizable::notifyChange
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
Definition: CRenderizable.h:315
mrpt::opengl::CText::getFont
std::string getFont() const
Definition: CText.h:63
mrpt::math::TPoint3D_< double >
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:152
mrpt::opengl::CText::m_fontHeight
int m_fontHeight
Definition: CText.h:41
mrpt::opengl::CText::m_str
std::string m_str
Definition: CText.h:39
mrpt::opengl::CText::CText
CText(const std::string &str=std::string(""))
Constructor.
Definition: CText.h:78
CRenderizableShaderText.h
mrpt::opengl::DefaultShaderID::TEXT
static constexpr shader_id_t TEXT
Definition: DefaultShaders.h:26
mrpt::opengl::CText::setString
void setString(const std::string &s)
Sets the text to display.
Definition: CText.h:47
mrpt::opengl::CText::~CText
virtual ~CText() override
mrpt::opengl::CText::m_fontWidth
int m_fontWidth
Definition: CText.h:41
bb_max
const auto bb_max
Definition: CPose3DPDFGrid_unittest.cpp:25
bb_min
const auto bb_min
Definition: CPose3DPDFGrid_unittest.cpp:23
mrpt::opengl::CText::render
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CText.cpp:48
mrpt::opengl::CText::m_fontName
std::string m_fontName
Definition: CText.h:40
mrpt::opengl::CText::onUpdateBuffers_Text
void onUpdateBuffers_Text() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CText.cpp:27
mrpt::opengl::CText::setFont
void setFont(const std::string &s, int height)
Sets the font (It has no effect yet!)
Definition: CText.h:56
mrpt::opengl::CRenderizableShaderText
Renderizable generic renderer for objects using the "text shader".
Definition: CRenderizableShaderText.h:25
mrpt::opengl::CText::getString
std::string getString() const
Return the current text associated to this label.
Definition: CText.h:54
mrpt::opengl::shader_list_t
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
mrpt::opengl::CText::getBoundingBox
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
Definition: CText.cpp:132
mrpt::opengl::CText::requiredShaders
shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Definition: CText.h:65
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
mrpt::opengl::CText
A 2D text (bitmap rendering): it always "faces the observer" despite it's at some 3D location.
Definition: CText.h:35



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 23:51:15 UTC 2020