MRPT  1.9.9
CText3D.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, 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 #include "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/CText3D.h>
13 #include <mrpt/opengl/gl_utils.h>
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 
20 using namespace std;
21 
23 
24 /*---------------------------------------------------------------
25  Constructor
26  ---------------------------------------------------------------*/
28  const std::string& str, const std::string& fontName, const double scale,
29  const mrpt::opengl::TOpenGLFontStyle text_style, const double text_spacing,
30  const double text_kerning)
31  : m_str(str),
32  m_fontName(fontName),
33  m_text_style(text_style),
34  m_text_spacing(text_spacing),
35  m_text_kerning(text_kerning)
36 {
37  this->setScale(scale);
38 }
39 
40 /*---------------------------------------------------------------
41  Destructor
42  ---------------------------------------------------------------*/
43 CText3D::~CText3D() = default;
44 /*---------------------------------------------------------------
45  render
46  ---------------------------------------------------------------*/
47 void CText3D::render_dl() const
48 {
49 #if MRPT_HAS_OPENGL_GLUT
50  glColor4ub(m_color.R, m_color.G, m_color.B, m_color.A);
51 
54  m_str,
55  1.0, // Scale
56  m_text_style, m_text_spacing, m_text_kerning);
57 
58 #endif
59 }
60 
61 uint8_t CText3D::serializeGetVersion() const { return 0; }
63 {
64  writeToStreamRender(out);
65  out << m_str << m_fontName << (uint32_t)m_text_style << m_text_spacing
66  << m_text_kerning;
67 }
68 
70 {
71  switch (version)
72  {
73  case 0:
74  {
75  readFromStreamRender(in);
76 
77  uint32_t i;
78  in >> m_str >> m_fontName >> i >> m_text_spacing >> m_text_kerning;
79 
80  m_text_style = TOpenGLFontStyle(i);
81  }
82  break;
83  default:
85  };
87 }
88 
91 {
92  bb_min.x = 0;
93  bb_min.y = 0;
94  bb_min.z = 0;
95 
96  bb_max.x = m_str.size() * m_scale_x;
97  bb_max.y = 1;
98  bb_max.z = 0;
99 
100  // Convert to coordinates of my parent:
101  m_pose.composePoint(bb_min, bb_min);
102  m_pose.composePoint(bb_max, bb_max);
103 }
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:6604
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CText3D.cpp:61
~CText3D() override
Private, virtual destructor: only can be deleted from smart pointers.
STL namespace.
mrpt::img::TPixelCoordf glDrawText(const std::string &text, const double textScale, enum TOpenGLFontStyle style=NICE, double spacing=1.5, double kerning=0.1)
renders a string in GL using the current settings.
Definition: gl_utils.cpp:545
void glSetFont(const std::string &fontname)
sets the font to use for future font rendering commands.
Definition: gl_utils.cpp:527
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
TOpenGLFontStyle
Different style for vectorized font rendering.
Definition: opengl_fonts.h:33
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CText3D.cpp:62
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
GLuint in
Definition: glext.h:7391
A 3D text (rendered with OpenGL primitives), with selectable font face and drawing style...
Definition: CText3D.h:42
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
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: CText3D.cpp:89
const auto bb_min
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CText3D.cpp:69
Lightweight 3D point.
Definition: TPoint3D.h:90
void render_dl() const override
Render.
Definition: CText3D.cpp:47



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: abb8b1a1e Fri Oct 18 14:19:12 2019 +0200 at vie oct 18 14:20:13 CEST 2019