MRPT  1.9.9
gl_utils.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/gl_utils.h> // Include these before windows.h!!
13 #include <mrpt/system/os.h>
14 #include <Eigen/Dense>
15 #include <map>
16 #include "opengl_internals.h"
17 
18 #if MRPT_HAS_OPENGL_GLUT
19 #include <cvd/gl_helpers.h>
20 #endif
21 
22 using namespace std;
23 using namespace mrpt;
24 using namespace mrpt::math;
25 using namespace mrpt::poses;
26 using namespace mrpt::system;
27 using namespace mrpt::opengl;
28 
29 /** For each object in the list:
30  * - checks visibility of each object
31  * - prepare the GL_MODELVIEW matrix according to its coordinates
32  * - call its ::render()
33  * - shows its name (if enabled).
34  */
36 {
37 #if MRPT_HAS_OPENGL_GLUT
38  MRPT_PROFILE_FUNC_START // Just the non-try/catch part of MRPT_START
39 
40  CListOpenGLObjects::const_iterator itP;
41  try
42  {
43  for (itP = objectsToRender.begin(); itP != objectsToRender.end(); ++itP)
44  {
45  if (!*itP) continue;
46  const CRenderizable* it =
47  itP->get(); // Use plain pointers, faster than smart pointers:
48  if (!it->isVisible()) continue;
49 
50  // 3D coordinates transformation:
52  glPushMatrix();
53 
54  glPushAttrib(GL_CURRENT_BIT); // drawing color, etc
55  glPushAttrib(GL_LIGHTING_BIT); // lighting
56  // gl_utils::checkOpenGLError();
57 
58  // It's more efficient to prepare the 4x4 matrix ourselves and load
59  // it directly into opengl stack:
60  // A homogeneous transformation matrix, in this order:
61  //
62  // 0 4 8 12
63  // 1 5 9 13
64  // 2 6 10 14
65  // 3 7 11 15
66  //
67  const CPose3D& pos = it->getPoseRef();
68  const CMatrixDouble33& R = pos.getRotationMatrix();
69  const GLdouble m[16] = {
70  R.coeff(0, 0), R.coeff(1, 0), R.coeff(2, 0), 0,
71  R.coeff(0, 1), R.coeff(1, 1), R.coeff(2, 1), 0,
72  R.coeff(0, 2), R.coeff(1, 2), R.coeff(2, 2), 0,
73  pos.m_coords[0], pos.m_coords[1], pos.m_coords[2], 1};
74  glMultMatrixd(m); // Multiply so it's composed with the previous,
75  // current MODELVIEW matrix
76 
77  // Do scaling after the other transformations!
78  if (it->getScaleX() != 1 || it->getScaleY() != 1 ||
79  it->getScaleZ() != 1)
80  glScalef(it->getScaleX(), it->getScaleY(), it->getScaleZ());
81 
82  // Set color:
83  glColor4f(
84  it->getColorR(), it->getColorG(), it->getColorB(),
85  it->getColorA());
86 
87  it->render();
89 
90  if (it->isShowNameEnabled())
91  {
93  glColor3f(
94  1.f, 1.f, 1.f); // Must be called BEFORE glRasterPos3f
95  glRasterPos3f(0.0f, 0.0f, 0.0f);
96 
97  GLfloat raster_pos[4];
99  float eye_distance = raster_pos[3];
100 
101  void* font = nullptr;
102  if (eye_distance < 2)
103  font = GLUT_BITMAP_TIMES_ROMAN_24;
104  else if (eye_distance < 200)
105  font = GLUT_BITMAP_TIMES_ROMAN_10;
106 
107  if (font)
109  it->getName().c_str(), font);
110 
112  }
113 
114  glPopAttrib();
115  glPopAttrib();
116  // gl_utils::checkOpenGLError();
117 
118  glPopMatrix();
120 
121  } // end foreach object
122  }
123  catch (exception& e)
124  {
125  char str[1000];
126  os::sprintf(
127  str, 1000, "Exception while rendering a class '%s'\n%s",
128  (*itP)->GetRuntimeClass()->className, e.what());
129  THROW_EXCEPTION(str);
130  }
131  catch (...)
132  {
133  THROW_EXCEPTION("Runtime error!");
134  }
135 #else
136  MRPT_UNUSED_PARAM(objectsToRender);
137 #endif
138 }
139 
140 void gl_utils::TRenderInfo::projectPoint(
141  float x, float y, float z, float& proj_x, float& proj_y,
142  float& proj_z_depth) const
143 {
145  full_matrix.asEigen() *
147  proj_x = proj[3] ? proj[0] / proj[3] : 0;
148  proj_y = proj[3] ? proj[1] / proj[3] : 0;
149  proj_z_depth = proj[2];
150 }
151 
152 /*---------------------------------------------------------------
153  checkOpenGLError
154  ---------------------------------------------------------------*/
156 {
157 #if MRPT_HAS_OPENGL_GLUT
158  int openglErr;
159  if ((openglErr = glGetError()) != GL_NO_ERROR)
160  {
161  const std::string sErr = std::string("OpenGL error: ") +
162  std::string((char*)gluErrorString(openglErr));
163  std::cerr << "[gl_utils::checkOpenGLError] " << sErr << std::endl;
164  // THROW_EXCEPTION(sErr);
165  }
166 #endif
167 }
168 
170  const mrpt::math::TPoint3D& p1, const mrpt::math::TPoint3D& p2,
171  const mrpt::math::TPoint3D& p3)
172 {
173 #if MRPT_HAS_OPENGL_GLUT
174  const float ax = p2.x - p1.x;
175  const float ay = p2.y - p1.y;
176  const float az = p2.z - p1.z;
177 
178  const float bx = p3.x - p1.x;
179  const float by = p3.y - p1.y;
180  const float bz = p3.z - p1.z;
181 
182  glNormal3f(ay * bz - az * by, -ax * bz + az * bx, ax * by - ay * bx);
183 
184  glVertex3f(p1.x, p1.y, p1.z);
185  glVertex3f(p2.x, p2.y, p2.z);
186  glVertex3f(p3.x, p3.y, p3.z);
187 #else
188  MRPT_UNUSED_PARAM(p1);
189  MRPT_UNUSED_PARAM(p2);
190  MRPT_UNUSED_PARAM(p3);
191 #endif
192 }
194  const mrpt::math::TPoint3Df& p1, const mrpt::math::TPoint3Df& p2,
195  const mrpt::math::TPoint3Df& p3)
196 {
197 #if MRPT_HAS_OPENGL_GLUT
198  const float ax = p2.x - p1.x;
199  const float ay = p2.y - p1.y;
200  const float az = p2.z - p1.z;
201 
202  const float bx = p3.x - p1.x;
203  const float by = p3.y - p1.y;
204  const float bz = p3.z - p1.z;
205 
206  glNormal3f(ay * bz - az * by, -ax * bz + az * bx, ax * by - ay * bx);
207 
208  glVertex3f(p1.x, p1.y, p1.z);
209  glVertex3f(p2.x, p2.y, p2.z);
210  glVertex3f(p3.x, p3.y, p3.z);
211 #else
212  MRPT_UNUSED_PARAM(p1);
213  MRPT_UNUSED_PARAM(p2);
214  MRPT_UNUSED_PARAM(p3);
215 #endif
216 }
218  const mrpt::math::TPoint3Df& p1, const mrpt::math::TPoint3Df& p2,
219  const mrpt::math::TPoint3Df& p3, const mrpt::math::TPoint3Df& p4)
220 {
221  renderTriangleWithNormal(p1, p2, p3);
222  renderTriangleWithNormal(p3, p4, p1);
223 }
224 
225 /** Gather useful information on the render parameters.
226  * It can be called from within the render() method of derived classes.
227  */
229 {
230 #if MRPT_HAS_OPENGL_GLUT
231  // Viewport geometry:
232  GLint win_dims[4];
233  glGetIntegerv(GL_VIEWPORT, win_dims);
234  ri.vp_x = win_dims[0];
235  ri.vp_y = win_dims[1];
236  ri.vp_width = win_dims[2];
237  ri.vp_height = win_dims[3];
238 
239  // Get the inverse camera position:
240  GLfloat mat_proj[16];
242  // ColMajor -> RowMajor:
244 
245  // Extract the camera position:
246  const auto HMinv = ri.proj_matrix.inverse();
247  const auto cam_pose_hm = HMinv.col(3).eval();
248  if (cam_pose_hm[3] != 0)
249  {
250  ri.camera_position.x = cam_pose_hm[0] / cam_pose_hm[3];
251  ri.camera_position.y = cam_pose_hm[1] / cam_pose_hm[3];
252  ri.camera_position.z = cam_pose_hm[2] / cam_pose_hm[3];
253  }
254  else
256 
257  // Get the model transformation:
258  GLfloat mat_mod[16];
261 
262  // PROJ * MODEL
263  ri.full_matrix = ri.proj_matrix * ri.model_matrix;
264 #else
265  MRPT_UNUSED_PARAM(ri);
266 #endif
267 }
268 
269 /*---------------------------------------------------------------
270  renderTextBitmap
271  ---------------------------------------------------------------*/
272 void gl_utils::renderTextBitmap(const char* str, void* fontStyle)
273 {
274 #if MRPT_HAS_OPENGL_GLUT
275  while (*str) glutBitmapCharacter(fontStyle, *(str++));
276 #else
277  MRPT_UNUSED_PARAM(str);
278  MRPT_UNUSED_PARAM(fontStyle);
279 #endif
280 }
281 
283 {
284 #if MRPT_HAS_OPENGL_GLUT
285  switch (font)
286  {
287  default:
289  return GLUT_BITMAP_TIMES_ROMAN_10;
290  break;
292  return GLUT_BITMAP_TIMES_ROMAN_24;
293  break;
294 
296  return GLUT_BITMAP_HELVETICA_10;
297  break;
299  return GLUT_BITMAP_HELVETICA_12;
300  break;
302  return GLUT_BITMAP_HELVETICA_18;
303  break;
304  }
305 #else
306  MRPT_UNUSED_PARAM(font);
307  return nullptr;
308 #endif
309 }
310 
311 /** Return the exact width in pixels for a given string, as will be rendered by
312  * renderTextBitmap().
313  * \sa renderTextBitmap
314  */
316  const std::string& str, mrpt::opengl::TOpenGLFont font)
317 {
318 #if MRPT_HAS_OPENGL_GLUT
319  if (str.empty()) return 0;
320  return glutBitmapLength(
321  aux_mrptfont2glutfont(font), (const unsigned char*)str.c_str());
322 #else
323  MRPT_UNUSED_PARAM(str);
324  MRPT_UNUSED_PARAM(font);
325  return 10;
326 #endif
327 }
328 
329 /*---------------------------------------------------------------
330  renderTextBitmap
331  ---------------------------------------------------------------*/
333  int screen_x, int screen_y, const std::string& str, float color_r,
334  float color_g, float color_b, TOpenGLFont font)
335 {
336 #if MRPT_HAS_OPENGL_GLUT
338 
339  // If (x,y) are negative, wrap to the opposite side:
340  if (screen_x < 0 || screen_y < 0)
341  {
342  // Size of the viewport:
343  GLint win_dims[4]; // [2]:width ,[3]:height
344  glGetIntegerv(GL_VIEWPORT, win_dims);
345 
346  if (screen_x < 0) screen_x += win_dims[2];
347  if (screen_y < 0) screen_y += win_dims[3];
348  }
349 
350  // Draw text:
351  glColor3f(color_r, color_g, color_b);
352 
353  // From: http://www.mesa3d.org/brianp/sig97/gotchas.htm
354  GLfloat fx, fy;
355 
356  /* Push current matrix mode and viewport attributes */
358 
359  /* Setup projection parameters */
361  glPushMatrix();
362  glLoadIdentity();
364  glPushMatrix();
365  glLoadIdentity();
366 
367  // glDepthRange( z, z );
368  glViewport((int)screen_x - 1, (int)screen_y - 1, 2, 2);
369 
370  /* set the raster (window) position */
371  fx = screen_x - (int)screen_x;
372  fy = screen_y - (int)screen_y;
373  // glRasterPos4f( fx, fy, 0.0, w );
374  glRasterPos3f(fx, fy, 0.0);
375 
376  /* restore matrices, viewport and matrix mode */
377  glPopMatrix();
379  glPopMatrix();
380 
381  glPopAttrib();
382 
383  // Select font:
384  void* glut_font_sel = aux_mrptfont2glutfont(font);
385 
386  for (char i : str) glutBitmapCharacter(glut_font_sel, i);
387 
389 #else
390  MRPT_UNUSED_PARAM(screen_x);
391  MRPT_UNUSED_PARAM(screen_y);
392  MRPT_UNUSED_PARAM(str);
393  MRPT_UNUSED_PARAM(color_r);
394  MRPT_UNUSED_PARAM(color_g);
395  MRPT_UNUSED_PARAM(color_b);
396  MRPT_UNUSED_PARAM(font);
397 #endif
398 }
399 
401  const float msg_x, const float msg_y, const float msg_w, const float msg_h,
402  const std::string& text, float text_scale,
403  const mrpt::img::TColor& back_col, const mrpt::img::TColor& border_col,
404  const mrpt::img::TColor& text_col, const float border_width,
405  const std::string& text_font, mrpt::opengl::TOpenGLFontStyle text_style,
406  const double text_spacing, const double text_kerning)
407 {
408 #if MRPT_HAS_OPENGL_GLUT
409  const int nLines = 1 + std::count(text.begin(), text.end(), '\n');
410 
411  GLint win_dims[4];
412  glGetIntegerv(GL_VIEWPORT, win_dims);
413  const int w = win_dims[2];
414  const int h = win_dims[3];
415 
416  const int min_wh = std::min(w, h);
417  const float vw_w = w / float(min_wh);
418  const float vw_h = h / float(min_wh);
419 
421  glPushMatrix();
422 
423  glLoadIdentity();
424  glOrtho(0, vw_w, 0, vw_h, -1, 1);
425 
427  glPushMatrix();
428 
429  glLoadIdentity();
430 
434 
435  // The center of the message box:
436  const float msg_x0 = vw_w * msg_x;
437  const float msg_y0 = vw_h * msg_y;
438 
439  const float msg_x1 = vw_w * (msg_x + msg_w);
440  const float msg_y1 = vw_h * (msg_y + msg_h);
441 
442  const float msg_real_w = msg_x1 - msg_x0;
443  const float msg_real_h = msg_y1 - msg_y0;
444 
445  const float msg_cx = .5 * (msg_x0 + msg_x1);
446  const float msg_cy = .5 * (msg_y0 + msg_y1);
447 
448  // Background:
449  glColor4ub(back_col.R, back_col.G, back_col.B, back_col.A);
451  glVertex2f(msg_x0, msg_y0);
452  glVertex2f(msg_x1, msg_y0);
453  glVertex2f(msg_x1, msg_y1);
454  glVertex2f(msg_x0, msg_y1);
455  glEnd();
456 
457  // Border:
458  glColor4ub(border_col.R, border_col.G, border_col.B, border_col.A);
459  glLineWidth(border_width);
460  glDisable(GL_LIGHTING); // Disable lights when drawing lines
462  glVertex2f(msg_x0, msg_y0);
463  glVertex2f(msg_x1, msg_y0);
464  glVertex2f(msg_x1, msg_y1);
465  glVertex2f(msg_x0, msg_y1);
466  glEnd();
467  glEnable(GL_LIGHTING); // Disable lights when drawing lines
468 
469  // Draw text (centered):
470  gl_utils::glSetFont(text_font);
471  mrpt::img::TPixelCoordf txtSize =
472  gl_utils::glGetExtends(text, text_scale, text_spacing, text_kerning);
473 
474  // Adjust text size if it doesn't fit into the box:
475  if (txtSize.x > msg_real_w)
476  {
477  const float K = 0.99f * msg_real_w / txtSize.x;
478  text_scale *= K;
479  txtSize.x *= K;
480  txtSize.y *= K;
481  }
482  if (txtSize.y > msg_real_h)
483  {
484  const float K = 0.99f * msg_real_h / txtSize.y;
485  text_scale *= K;
486  txtSize.x *= K;
487  txtSize.y *= K;
488  }
489 
490  const float text_w = txtSize.x;
491  const float text_h =
492  (nLines > 1 ? -(nLines - 1) * txtSize.y / float(nLines) : txtSize.y);
493  const float text_x0 = msg_cx - .5f * text_w;
494  const float text_y0 = msg_cy - .5f * text_h;
495 
496  glTranslatef(text_x0, text_y0, 0);
497  glColor4ub(text_col.R, text_col.G, text_col.B, text_col.A);
499  text, text_scale, text_style, text_spacing, text_kerning);
500 
501  // Restore gl flags:
504 
505  glPopMatrix();
506 
508  glPopMatrix();
509 #else
510  MRPT_UNUSED_PARAM(msg_x);
511  MRPT_UNUSED_PARAM(msg_y);
512  MRPT_UNUSED_PARAM(msg_w);
513  MRPT_UNUSED_PARAM(msg_h);
514  MRPT_UNUSED_PARAM(text);
515  MRPT_UNUSED_PARAM(text_scale);
516  MRPT_UNUSED_PARAM(back_col);
517  MRPT_UNUSED_PARAM(border_col);
518  MRPT_UNUSED_PARAM(text_col);
519  MRPT_UNUSED_PARAM(border_width);
520  MRPT_UNUSED_PARAM(text_font);
521  MRPT_UNUSED_PARAM(text_style);
522  MRPT_UNUSED_PARAM(text_spacing);
523  MRPT_UNUSED_PARAM(text_kerning);
524 #endif
525 }
526 
527 void gl_utils::glSetFont(const std::string& fontname)
528 {
529 #if MRPT_HAS_OPENGL_GLUT
530  CVD::glSetFont(fontname);
531 #else
532  MRPT_UNUSED_PARAM(fontname);
533 #endif
534 }
535 
537 {
538 #if MRPT_HAS_OPENGL_GLUT
539  return CVD::glGetFont();
540 #else
541  THROW_EXCEPTION("MRPT built without OpenGL");
542 #endif
543 }
544 
546  const std::string& text, const double textScale,
547  enum TOpenGLFontStyle style, double spacing, double kerning)
548 {
549 #if MRPT_HAS_OPENGL_GLUT
550  glPushMatrix();
552  glScaled(textScale, textScale, textScale);
553  auto ret = CVD::glDrawText(
554  text, static_cast<CVD::TEXT_STYLE>(style), spacing, kerning);
555  glPopMatrix();
556  return ret;
557 #else
558  MRPT_UNUSED_PARAM(text);
559  MRPT_UNUSED_PARAM(textScale);
560  MRPT_UNUSED_PARAM(style);
561  MRPT_UNUSED_PARAM(spacing);
562  MRPT_UNUSED_PARAM(kerning);
563  THROW_EXCEPTION("MRPT built without OpenGL");
564 #endif
565 }
566 
568  const std::string& text, const double textScale, double spacing,
569  double kerning)
570 {
571 #if MRPT_HAS_OPENGL_GLUT
572  mrpt::img::TPixelCoordf ret(CVD::glGetExtends(text, spacing, kerning));
573  ret.x *= textScale;
574  ret.y *= textScale;
575  return ret;
576 #else
577  MRPT_UNUSED_PARAM(text);
578  MRPT_UNUSED_PARAM(textScale);
579  MRPT_UNUSED_PARAM(spacing);
580  MRPT_UNUSED_PARAM(kerning);
581  THROW_EXCEPTION("MRPT built without OpenGL");
582 #endif
583 }
584 // =============== END OF CODE FROM "libcvd -> gltext.cpp" ===============
void renderTextBitmap(const char *str, void *fontStyle)
This method is safe for calling from within ::render() methods.
Definition: gl_utils.cpp:272
double getColorA() const
Color components in the range [0,1].
GLuint GLuint GLsizei count
Definition: glext.h:3532
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...
Definition: gl_utils.cpp:169
GLAPI void GLAPIENTRY glGetFloatv(GLenum pname, GLfloat *params)
GLdouble GLdouble z
Definition: glext.h:3879
#define min(a, b)
double x
X,Y,Z coordinates.
Definition: TPoint3D.h:83
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
float getScaleX() const
Get the current scaling factor in one axis.
double GLdouble
Definition: glew.h:220
GLbyte GLbyte bz
Definition: glext.h:6193
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
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...
Definition: gl_utils.cpp:217
mrpt::math::CMatrixFixed< float, 4, 4 > full_matrix
PROJ * MODEL.
Definition: gl_utils.h:40
mrpt::math::CVectorFixedDouble< 3 > m_coords
The translation vector [x,y,z] access directly or with x(), y(), z() setter/getter methods...
Definition: CPose3D.h:96
#define GL_LIGHTING_BIT
Definition: glew.h:258
const std::string & glGetFont()
returns the name of the currently active font
Definition: gl_utils.cpp:536
GLAPI void GLAPIENTRY glScaled(GLdouble x, GLdouble y, GLdouble z)
#define GL_MODELVIEW
Definition: glew.h:611
std::deque< CRenderizable::Ptr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
GLAPI void GLAPIENTRY glPopMatrix(void)
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:40
mrpt::math::CMatrixFixed< float, 4, 4 > proj_matrix
The 4x4 projection matrix.
Definition: gl_utils.h:36
#define GL_VIEWPORT_BIT
Definition: glew.h:263
A pair (x,y) of pixel coordinates (subpixel resolution).
Definition: TPixelCoord.h:18
STL namespace.
uint8_t B
Definition: TColor.h:46
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
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:288
uint8_t G
Definition: TColor.h:46
#define GL_DEPTH_TEST
Definition: glew.h:402
GLAPI void GLAPIENTRY glPopAttrib(void)
#define GL_LIGHTING
Definition: glew.h:386
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
void glSetFont(const std::string &fontname)
sets the font to use for future font rendering commands.
Definition: gl_utils.cpp:527
GLAPI void GLAPIENTRY glLoadIdentity(void)
#define GL_CURRENT_RASTER_POSITION
Definition: glew.h:361
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4199
float GLfloat
Definition: glew.h:218
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
#define MRPT_PROFILE_FUNC_START
Definition: exceptions.h:234
This base provides a set of functions for maths stuff.
Derived inverse() const
Returns the inverse of a general matrix using LU.
TOpenGLFont
Existing fonts for 2D texts in mrpt::opengl methods.
Definition: opengl_fonts.h:22
Lightweight 3D point (float version).
Definition: TPoint3D.h:21
bool isVisible() const
Is the object visible?
Definition: CRenderizable.h:68
TOpenGLFontStyle
Different style for vectorized font rendering.
Definition: opengl_fonts.h:33
mrpt::img::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 ...
Definition: gl_utils.cpp:567
Information about the rendering process being issued.
Definition: gl_utils.h:31
#define GL_MODELVIEW_MATRIX
Definition: glew.h:422
#define GL_PROJECTION
Definition: glew.h:612
GLAPI void GLAPIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue)
const std::string & getName() const
Returns the name of the object.
Definition: CRenderizable.h:67
GLAPI void GLAPIENTRY glBegin(GLenum mode)
#define GL_BLEND
Definition: glew.h:433
int vp_x
Rendering viewport geometry (in pixels)
Definition: gl_utils.h:34
GLsizei const GLchar ** string
Definition: glext.h:4116
#define GL_LINE_LOOP
Definition: glew.h:275
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
uint8_t R
Definition: TColor.h:46
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
#define GL_SRC_ALPHA
Definition: glew.h:287
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define GL_NO_ERROR
Definition: glew.h:327
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
#define GL_VIEWPORT
Definition: glew.h:418
GLAPI void GLAPIENTRY glMultMatrixd(const GLdouble *m)
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
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::img::TColor &back_col=mrpt::img::TColor(0, 0, 50, 150), const mrpt::img::TColor &border_col=mrpt::img::TColor(0, 0, 0, 140), const mrpt::img::TColor &text_col=mrpt::img::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.
Definition: gl_utils.cpp:400
const float R
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
GLAPI void GLAPIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z)
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().
Definition: gl_utils.cpp:315
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:155
GLAPI void GLAPIENTRY glGetIntegerv(GLenum pname, GLint *params)
GLAPI GLenum GLAPIENTRY glGetError(void)
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
void getCurrentRenderingInfo(TRenderInfo &ri)
Gather useful information on the render parameters.
Definition: gl_utils.cpp:228
GLAPI void GLAPIENTRY glEnd(void)
#define GL_TRANSFORM_BIT
Definition: glew.h:264
GLenum GLint GLint y
Definition: glext.h:3542
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...
float getScaleY() const
Get the current scaling factor in one axis.
GLbyte by
Definition: glext.h:6193
#define GL_TRIANGLE_FAN
Definition: glew.h:279
int GLint
Definition: glew.h:210
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
#define GL_PROJECTION_MATRIX
Definition: glew.h:423
GLAPI void GLAPIENTRY glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
A RGB color - 8bit.
Definition: TColor.h:20
GLenum GLint x
Definition: glext.h:3542
#define GL_CURRENT_BIT
Definition: glew.h:252
GLAPI void GLAPIENTRY glPushMatrix(void)
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
Definition: CPose3D.h:224
double getColorB() const
Color components in the range [0,1].
Lightweight 3D point.
Definition: TPoint3D.h:90
void renderSetOfObjects(const mrpt::opengl::CListOpenGLObjects &objs)
For each object in the list:
Definition: gl_utils.cpp:35
void * aux_mrptfont2glutfont(const TOpenGLFont font)
Definition: gl_utils.cpp:282
GLAPI void GLAPIENTRY glVertex2f(GLfloat x, GLfloat y)
virtual void render() const =0
Implements the rendering of 3D objects in each class derived from CRenderizable.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
double getColorG() const
Color components in the range [0,1].
float getScaleZ() const
Get the current scaling factor in one axis.
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...
Definition: os.cpp:191
uint8_t A
Definition: TColor.h:46
mrpt::math::CMatrixFixed< float, 4, 4 > model_matrix
The 4x4 model transformation matrix.
Definition: gl_utils.h:38
double getColorR() const
Color components in the range [0,1].
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186
mrpt::math::TPoint3Df camera_position
The 3D location of the camera.
Definition: gl_utils.h:42



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 928d0abbd Sun Oct 13 02:28:49 2019 +0200 at dom oct 13 02:30:11 CEST 2019