Main MRPT website > C++ reference for MRPT 1.9.9
CText.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/CText.h>
13 #include <mrpt/utils/CStream.h>
14 #include "opengl_internals.h"
15 
16 using namespace mrpt;
17 using namespace mrpt::opengl;
18 using namespace mrpt::utils;
19 using namespace mrpt::math;
20 using namespace std;
21 
23 
24 /*---------------------------------------------------------------
25  Constructor
26  ---------------------------------------------------------------*/
27 CText::CText(const string& str)
28 {
29  m_str = str;
30 
31  m_fontName = "Arial";
32  m_fontHeight = 10;
33  m_fontWidth = 0;
34 }
35 
36 /*---------------------------------------------------------------
37  Destructor
38  ---------------------------------------------------------------*/
40 /*---------------------------------------------------------------
41  render
42  ---------------------------------------------------------------*/
43 void CText::render() const
44 {
45 #if MRPT_HAS_OPENGL_GLUT
48 
49  glColor4ub(m_color.R, m_color.G, m_color.B, m_color.A);
50  // Set the "cursor" to the XYZ position:
51  glRasterPos3f(0, 0, 0); // m_x,m_y,m_z);
52 
53  // Call the lists for drawing the text:
54  renderTextBitmap(m_str.c_str(), GLUT_BITMAP_TIMES_ROMAN_10);
55 
58 #endif
59 }
60 
61 /*---------------------------------------------------------------
62  Implements the writing to a CStream capability of
63  CSerializable objects
64  ---------------------------------------------------------------*/
65 void CText::writeToStream(mrpt::utils::CStream& out, int* version) const
66 {
67  if (version)
68  *version = 1;
69  else
70  {
71  writeToStreamRender(out);
72  out << m_str;
73  out << m_fontName;
74  out << (uint32_t)m_fontHeight << (uint32_t)m_fontWidth;
75  }
76 }
77 
78 /*---------------------------------------------------------------
79  Implements the reading from a CStream capability of
80  CSerializable objects
81  ---------------------------------------------------------------*/
83 {
84  switch (version)
85  {
86  case 0:
87  case 1:
88  {
89  uint32_t i;
90  readFromStreamRender(in);
91  in >> m_str;
92  if (version >= 1)
93  {
94  in >> m_fontName;
95  in >> i;
96  m_fontHeight = i;
97  in >> i;
98  m_fontWidth = i;
99  }
100  }
101  break;
102  default:
104  };
105 }
106 
108  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
109 {
110  bb_min.x = 0;
111  bb_min.y = 0;
112  bb_min.z = 0;
113 
114  bb_max = bb_min;
115 
116  // Convert to coordinates of my parent:
117  m_pose.composePoint(bb_min, bb_min);
118  m_pose.composePoint(bb_max, bb_max);
119 }
void renderTextBitmap(const char *str, void *fontStyle)
This method is safe for calling from within ::render() methods.
Definition: gl_utils.cpp:255
A 2D text (bitmap rendering): it always "faces the observer" despite it&#39;s at some 3D location...
Definition: CText.h:38
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
Definition: CText.cpp:82
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:43
STL namespace.
#define GL_DEPTH_TEST
Definition: glew.h:401
#define GL_LIGHTING
Definition: glew.h:385
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
void render() const override
Render.
Definition: CText.cpp:43
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
virtual ~CText()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CText.cpp:39
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CText.cpp:65
double x
X,Y,Z coordinates.
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.
GLuint in
Definition: glext.h:7274
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
Lightweight 3D point.
unsigned __int32 uint32_t
Definition: rptypes.h:47
GLAPI void GLAPIENTRY glDisable(GLenum cap)
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:107



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019