34 #if MRPT_HAS_OPENGL_GLUT
40 for (itP = objectsToRender.begin(); itP != objectsToRender.end(); ++itP)
67 R.coeff(0, 0),
R.coeff(1, 0),
R.coeff(2, 0), 0,
68 R.coeff(0, 1),
R.coeff(1, 1),
R.coeff(2, 1), 0,
69 R.coeff(0, 2),
R.coeff(1, 2),
R.coeff(2, 2), 0,
96 float eye_distance = raster_pos[3];
100 font = GLUT_BITMAP_TIMES_ROMAN_24;
101 else if (eye_distance < 200)
102 font = GLUT_BITMAP_TIMES_ROMAN_10;
124 str, 1000,
"Exception while rendering a class '%s'\n%s",
125 (*itP)->GetRuntimeClass()->className, e.what());
142 #if MRPT_HAS_OPENGL_GLUT
148 std::cerr <<
"[gl_utils::checkOpenGLError] " << sErr << std::endl;
158 #if MRPT_HAS_OPENGL_GLUT
159 const float ax = p2.
x - p1.
x;
160 const float ay = p2.
y - p1.
y;
161 const float az = p2.
z - p1.
z;
163 const float bx = p3.
x - p1.
x;
164 const float by = p3.
y - p1.
y;
165 const float bz = p3.
z - p1.
z;
182 #if MRPT_HAS_OPENGL_GLUT
183 const float ax = p2.
x - p1.
x;
184 const float ay = p2.
y - p1.
y;
185 const float az = p2.
z - p1.
z;
187 const float bx = p3.
x - p1.
x;
188 const float by = p3.
y - p1.
y;
189 const float bz = p3.
z - p1.
z;
215 #if MRPT_HAS_OPENGL_GLUT
219 ri.
vp_x = win_dims[0];
220 ri.
vp_y = win_dims[1];
227 ri.
proj_matrix = Eigen::Matrix<float, 4, 4, Eigen::ColMajor>(mat_proj);
230 Eigen::Matrix<float, 4, 1> cam_pose_hm = ri.
proj_matrix.inverse().col(3);
231 if (cam_pose_hm[3] != 0)
243 ri.
model_matrix = Eigen::Matrix<float, 4, 4, Eigen::ColMajor>(mat_mod);
257 #if MRPT_HAS_OPENGL_GLUT
258 while (*str) glutBitmapCharacter(fontStyle, *(str++));
267 #if MRPT_HAS_OPENGL_GLUT
272 return GLUT_BITMAP_TIMES_ROMAN_10;
275 return GLUT_BITMAP_TIMES_ROMAN_24;
279 return GLUT_BITMAP_HELVETICA_10;
282 return GLUT_BITMAP_HELVETICA_12;
285 return GLUT_BITMAP_HELVETICA_18;
301 #if MRPT_HAS_OPENGL_GLUT
302 if (str.empty())
return 0;
303 return glutBitmapLength(
316 int screen_x,
int screen_y,
const std::string& str,
float color_r,
319 #if MRPT_HAS_OPENGL_GLUT
323 if (screen_x < 0 || screen_y < 0)
329 if (screen_x < 0) screen_x += win_dims[2];
330 if (screen_y < 0) screen_y += win_dims[3];
351 glViewport((
int)screen_x - 1, (
int)screen_y - 1, 2, 2);
354 fx = screen_x - (int)screen_x;
355 fy = screen_y - (int)screen_y;
369 for (
size_t i = 0; i < str.size(); i++)
370 glutBitmapCharacter(glut_font_sel, str[i]);
385 const float msg_x,
const float msg_y,
const float msg_w,
const float msg_h,
390 const double text_spacing,
const double text_kerning)
392 #if MRPT_HAS_OPENGL_GLUT
393 const int nLines = 1 +
std::count(text.begin(), text.end(),
'\n');
397 const int w = win_dims[2];
398 const int h = win_dims[3];
401 const float vw_w =
w / float(min_wh);
402 const float vw_h = h / float(min_wh);
408 glOrtho(0, vw_w, 0, vw_h, -1, 1);
420 const float msg_x0 = vw_w * msg_x;
421 const float msg_y0 = vw_h * msg_y;
423 const float msg_x1 = vw_w * (msg_x + msg_w);
424 const float msg_y1 = vw_h * (msg_y + msg_h);
426 const float msg_real_w = msg_x1 - msg_x0;
427 const float msg_real_h = msg_y1 - msg_y0;
429 const float msg_cx = .5 * (msg_x0 + msg_x1);
430 const float msg_cy = .5 * (msg_y0 + msg_y1);
442 glColor4ub(border_col.
R, border_col.
G, border_col.
B, border_col.
A);
459 if (txtSize.
x > msg_real_w)
461 const float K = 0.99f * msg_real_w / txtSize.
x;
466 if (txtSize.
y > msg_real_h)
468 const float K = 0.99f * msg_real_h / txtSize.
y;
474 const float text_w = txtSize.
x;
476 (nLines > 1 ? -(nLines - 1) * txtSize.
y /
float(nLines) : txtSize.
y);
477 const float text_x0 = msg_cx - .5f * text_w;
478 const float text_y0 = msg_cy - .5f * text_h;
483 text, text_scale, text_style, text_spacing, text_kerning);
513 #if MRPT_HAS_OPENGL_GLUT
523 typedef unsigned short Index;
528 Index triangleOffset;
541 const Char* findChar(
const char c)
const
543 size_t ind = glyphs.find(
c);
544 if (ind == string::npos)
return nullptr;
545 return characters + ind;
548 float getAdvance(
const char c)
const
550 const Char* ch = findChar(
c);
555 void fill(
const char c)
const
557 const Char* ch = findChar(
c);
558 if (!ch || !ch->numTriangles)
return;
563 triangles + ch->triangleOffset);
567 void outline(
const char c)
const
569 const Char* ch = findChar(
c);
570 if (!ch || !ch->numOutlines)
return;
575 outlines + ch->outlineOffset);
579 void draw(
const char c)
const
581 const Char* ch = findChar(
c);
582 if (!ch || !ch->numTriangles || !ch->numOutlines)
return;
587 triangles + ch->triangleOffset);
590 outlines + ch->outlineOffset);
603 typedef map<string, Font*> FontMap;
612 inline Font* currentFont() {
return fonts[currentFontName]; }
613 string currentFontName;
617 static struct FontData
data;
623 #if MRPT_HAS_OPENGL_GLUT
633 #if MRPT_HAS_OPENGL_GLUT
644 #if MRPT_HAS_OPENGL_GLUT
659 void (Internal::Font::*operation)(
const char c)
const;
667 operation = &Internal::Font::outline;
670 operation = &Internal::Font::draw;
677 glScaled(textScale, textScale, textScale);
680 double max_total = 0;
683 const Internal::Font::Char* space = font->findChar(
' ');
684 const double tab_width = 8 * ((space) ? (space->advance) : 1);
685 for (
size_t i = 0; i < text.length(); ++i)
691 max_total = std::max(max_total, total);
698 const float advance = tab_width - std::fmod(total, tab_width);
703 const Internal::Font::Char* ch = font->findChar(
c);
707 ch = font->findChar(
c);
711 ch = font->findChar(
c);
715 (font->*operation)(
c);
717 double w = ch->advance + kerning;
729 max_total = std::max(total, max_total);
732 textScale * max_total, textScale * (lines + 1) * spacing);
744 const std::string& text,
const double textScale,
double spacing,
747 #if MRPT_HAS_OPENGL_GLUT
749 double max_total = 0;
752 for (
size_t i = 0; i < text.length(); ++i)
757 max_total = std::max(max_total, total);
762 const Internal::Font::Char* ch = font->findChar(
c);
766 ch = font->findChar(
c);
770 ch = font->findChar(
c);
774 total += ch->advance + kerning;
776 max_total = std::max(total, max_total);
778 textScale * max_total, textScale * (lines + 1) * spacing);
The base class of 3D objects that can be directly rendered through OpenGL.
bool isVisible() const
Is the object visible?
double getColorR() const
Color components in the range [0,1].
double getColorB() const
Color components in the range [0,1].
const mrpt::poses::CPose3D & getPoseRef() const
Returns a const ref to the 3D pose of the object as mrpt::poses::CPose3D (which explicitly contains t...
double getColorG() const
Color components in the range [0,1].
float getScaleZ() const
Get the current scaling factor in one axis.
virtual void render() const =0
Implements the rendering of 3D objects in each class derived from CRenderizable.
float getScaleX() const
Get the current scaling factor in one axis.
bool isShowNameEnabled() const
float getScaleY() const
Get the current scaling factor in one axis.
const std::string & getName() const
Returns the name of the object.
double getColorA() const
Color components in the range [0,1].
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
mrpt::math::CArrayDouble< 3 > m_coords
The translation vector [x,y,z] access directly or with x(), y(), z() setter/getter methods.
EIGEN_STRONG_INLINE void fill(const Scalar v)
const Scalar * const_iterator
void * aux_mrptfont2glutfont(const TOpenGLFont font)
GLAPI void GLAPIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
#define GL_UNSIGNED_SHORT
GLAPI void GLAPIENTRY glVertex2f(GLfloat x, GLfloat y)
GLAPI void GLAPIENTRY glMultMatrixd(const GLdouble *m)
GLAPI void GLAPIENTRY glPushMatrix(void)
GLAPI void GLAPIENTRY glLoadIdentity(void)
GLAPI void GLAPIENTRY glTranslated(GLdouble x, GLdouble y, GLdouble z)
GLAPI void GLAPIENTRY glScaled(GLdouble x, GLdouble y, GLdouble z)
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
GLAPI void GLAPIENTRY glEnableClientState(GLenum array)
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
GLAPI void GLAPIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
#define GL_COLOR_BUFFER_BIT
#define GL_PROJECTION_MATRIX
GLAPI GLenum GLAPIENTRY glGetError(void)
GLAPI void GLAPIENTRY glBegin(GLenum mode)
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
#define GL_CURRENT_RASTER_POSITION
GLAPI void GLAPIENTRY glPopMatrix(void)
#define GL_MODELVIEW_MATRIX
#define GL_ONE_MINUS_SRC_ALPHA
GLAPI void GLAPIENTRY glEnd(void)
GLAPI void GLAPIENTRY glPopAttrib(void)
GLAPI void GLAPIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue)
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
GLAPI void GLAPIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
GLAPI void GLAPIENTRY glGetFloatv(GLenum pname, GLfloat *params)
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
GLAPI void GLAPIENTRY glGetIntegerv(GLenum pname, GLint *params)
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
GLAPI void GLAPIENTRY glDisableClientState(GLenum array)
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
GLubyte GLubyte GLubyte GLubyte w
GLsizei GLsizei GLenum GLenum const GLvoid * data
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLuint GLuint GLsizei count
GLsizei const GLchar ** string
TOpenGLFont
Existing fonts for 2D texts in mrpt::opengl methods.
@ MRPT_GLUT_BITMAP_TIMES_ROMAN_24
@ MRPT_GLUT_BITMAP_HELVETICA_18
@ MRPT_GLUT_BITMAP_HELVETICA_12
@ MRPT_GLUT_BITMAP_HELVETICA_10
@ MRPT_GLUT_BITMAP_TIMES_ROMAN_10
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
#define MRPT_PROFILE_FUNC_START
#define THROW_EXCEPTION(msg)
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
This base provides a set of functions for maths stuff.
int textBitmapWidth(const std::string &str, mrpt::opengl::TOpenGLFont font=mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24)
Return the exact width in pixels for a given string, as will be rendered by renderTextBitmap().
void renderSetOfObjects(const mrpt::opengl::CListOpenGLObjects &objs)
For each object in the list:
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
void glSetFont(const std::string &fontname)
sets the font to use for future font rendering commands.
mrpt::utils::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.
void renderMessageBox(const float msg_x, const float msg_y, const float msg_w, const float msg_h, const std::string &text, float text_scale, const mrpt::utils::TColor &back_col=mrpt::utils::TColor(0, 0, 50, 150), const mrpt::utils::TColor &border_col=mrpt::utils::TColor(0, 0, 0, 140), const mrpt::utils::TColor &text_col=mrpt::utils::TColor(255, 255, 255, 220), const float border_width=4.0f, const std::string &text_font=std::string("sans"), mrpt::opengl::TOpenGLFontStyle text_style=mrpt::opengl::FILL, const double text_spacing=1.5, const double text_kerning=0.1)
Draws a message box with a centered (possibly multi-lined) text.
void renderQuadWithNormal(const mrpt::math::TPoint3Df &p1, const mrpt::math::TPoint3Df &p2, const mrpt::math::TPoint3Df &p3, const mrpt::math::TPoint3Df &p4)
Can be used by derived classes to draw a quad with a normal vector computed automatically - to be cal...
void renderTriangleWithNormal(const mrpt::math::TPoint3D &p1, const mrpt::math::TPoint3D &p2, const mrpt::math::TPoint3D &p3)
Can be used by derived classes to draw a triangle with a normal vector computed automatically - to be...
const std::string & glGetFont()
returns the name of the currently active font
void getCurrentRenderingInfo(TRenderInfo &ri)
Gather useful information on the render parameters.
mrpt::utils::TPixelCoordf glGetExtends(const std::string &text, const double textScale, double spacing=1.5, double kerning=0.1)
returns the size of the bounding box of a text to be rendered, similar to glDrawText but without any ...
void renderTextBitmap(const char *str, void *fontStyle)
This method is safe for calling from within ::render() methods.
The namespace for 3D scene representation and rendering.
TOpenGLFontStyle
Different style for vectorized font rendering.
@ NICE
renders glyphs filled with antialiased outlines
@ FILL
renders glyphs as filled polygons
@ OUTLINE
renders glyphs as outlines with GL_LINES
std::deque< CRenderizable::Ptr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double x
X,Y,Z coordinates.
Lightweight 3D point (float version).
Information about the rendering process being issued.
mrpt::math::TPoint3Df camera_position
The 3D location of the camera.
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > proj_matrix
The 4x4 projection matrix.
int vp_x
Rendering viewport geometry (in pixels)
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > model_matrix
The 4x4 model transformation matrix.
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > full_matrix
PROJ * MODEL.
A pair (x,y) of pixel coordinates (subpixel resolution).