Debian Codegraph @

libs/opengl/src/gltext.h

raw
1 /* +------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | https://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2026, 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 // Stripped out version of libCVD gl-helpers.h file, ported to OpenGL>=3
11 // 2-BSD License.
12
13 #pragma once
14
15 #include <mrpt/math/TPoint3D.h>
16 #include <mrpt/opengl/TTriangle.h>
17 #include <mrpt/opengl/opengl_fonts.h>
18 #include <mrpt/poses/CPose3D.h>
19
20 #include <iostream>
21 #include <map>
22 #include <string>
23 #include <utility>
24 #include <vector>
25
26 namespace mrpt::opengl::internal
27 {
28 /** @name OpenGL vector 3D fonts
29 @{ */
30
31 /// sets the font to use for future font rendering commands.
32 /// Options are: "sans", "serif", "mono".
33 /// @param fontname string containing font name
34 void glSetFont(const std::string& fontname);
35
36 /// returns the name of the currently active font
37 const std::string& glGetFont();
38
39 /// different style for font rendering
40 using TEXT_STYLE = TOpenGLFontStyle;
41
42 /// renders a string in GL using the current settings.
43 /// Font coordinates are +X along the line and +Y along the up direction of
44 /// glyphs. The origin is at the top baseline at the left of the first
45 /// character. Characters have a maximum size of 1. linefeed is interpreted as a
46 /// new line and the start is offset in -Y direction by @ref spacing .
47 /// Individual characters are separated by @ref kerning + plus their individual
48 /// with.
49 /// @param text string to be rendered, unknown characters are replaced with '?'
50 /// @param style rendering style
51 /// @param spacing distance between individual text lines
52 /// @param kerning distance between characters
53 std::pair<double, double> glDrawText(
54 const std::string& text,
55 std::vector<mrpt::opengl::TTriangle>& tris,
56 std::vector<mrpt::math::TPoint3Df>& lines,
57 TEXT_STYLE style = NICE,
58 double spacing = 1.5,
59 double kerning = 0.1);
60
61 /// Appends to {tris,lines} the entities representing a given text including a
62 /// pose and scale transformation.
63 ///
64 /// It calls glDrawText() and appends its results to the provided buffers.
65 void glDrawTextTransformed(
66 const std::string& text,
67 std::vector<mrpt::opengl::TTriangle>& tris,
68 std::vector<mrpt::math::TPoint3Df>& lines,
69 std::vector<mrpt::img::TColor>& line_colors,
70 const mrpt::poses::CPose3D& text_pose,
71 float text_scale,
72 const mrpt::img::TColor& text_color,
73 TEXT_STYLE style = NICE,
74 double spacing = 1.5,
75 double kerning = 0.1);
76
77 /// returns the size of the bounding box of a text to be rendered, similar to
78 /// @ref glDrawText but without any visual output
79 std::pair<double, double> glGetExtends(
80 const std::string& text, double spacing = 1.5, double kerning = 0.1);
81
82 /** @} */
83
84 } // namespace mrpt::opengl::internal