Main MRPT website > C++ reference for MRPT 1.9.9
gl_utils.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/gl_utils.h> // Include these before windows.h!!
13 #include <mrpt/system/os.h>
14 #include "opengl_internals.h"
15 
16 #include <map>
17 
18 using namespace std;
19 using namespace mrpt;
20 using namespace mrpt::math;
21 using namespace mrpt::poses;
22 using namespace mrpt::system;
23 using namespace mrpt::opengl;
24 using namespace mrpt::utils;
25 
26 /** For each object in the list:
27 * - checks visibility of each object
28 * - prepare the GL_MODELVIEW matrix according to its coordinates
29 * - call its ::render()
30 * - shows its name (if enabled).
31 */
33 {
34 #if MRPT_HAS_OPENGL_GLUT
35  MRPT_PROFILE_FUNC_START // Just the non-try/catch part of MRPT_START
36 
38  try
39  {
40  for (itP = objectsToRender.begin(); itP != objectsToRender.end(); ++itP)
41  {
42  if (!*itP) continue;
43  const CRenderizable* it =
44  itP->get(); // Use plain pointers, faster than smart pointers:
45  if (!it->isVisible()) continue;
46 
47  // 3D coordinates transformation:
49  glPushMatrix();
50 
51  glPushAttrib(GL_CURRENT_BIT); // drawing color, etc
52  glPushAttrib(GL_LIGHTING_BIT); // lighting
53  // gl_utils::checkOpenGLError();
54 
55  // It's more efficient to prepare the 4x4 matrix ourselves and load
56  // it directly into opengl stack:
57  // A homogeneous transformation matrix, in this order:
58  //
59  // 0 4 8 12
60  // 1 5 9 13
61  // 2 6 10 14
62  // 3 7 11 15
63  //
64  const CPose3D& pos = it->getPoseRef();
65  const CMatrixDouble33& R = pos.getRotationMatrix();
66  const GLdouble m[16] = {
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,
70  pos.m_coords[0], pos.m_coords[1], pos.m_coords[2], 1};
71  glMultMatrixd(m); // Multiply so it's composed with the previous,
72  // current MODELVIEW matrix
73 
74  // Do scaling after the other transformations!
75  if (it->getScaleX() != 1 || it->getScaleY() != 1 ||
76  it->getScaleZ() != 1)
77  glScalef(it->getScaleX(), it->getScaleY(), it->getScaleZ());
78 
79  // Set color:
80  glColor4f(
81  it->getColorR(), it->getColorG(), it->getColorB(),
82  it->getColorA());
83 
84  it->render();
86 
87  if (it->isShowNameEnabled())
88  {
90  glColor3f(
91  1.f, 1.f, 1.f); // Must be called BEFORE glRasterPos3f
92  glRasterPos3f(0.0f, 0.0f, 0.0f);
93 
94  GLfloat raster_pos[4];
96  float eye_distance = raster_pos[3];
97 
98  void* font = nullptr;
99  if (eye_distance < 2)
100  font = GLUT_BITMAP_TIMES_ROMAN_24;
101  else if (eye_distance < 200)
102  font = GLUT_BITMAP_TIMES_ROMAN_10;
103 
104  if (font)
106  it->getName().c_str(), font);
107 
109  }
110 
111  glPopAttrib();
112  glPopAttrib();
113  // gl_utils::checkOpenGLError();
114 
115  glPopMatrix();
117 
118  } // end foreach object
119  }
120  catch (exception& e)
121  {
122  char str[1000];
123  os::sprintf(
124  str, 1000, "Exception while rendering a class '%s'\n%s",
125  (*itP)->GetRuntimeClass()->className, e.what());
126  THROW_EXCEPTION(str);
127  }
128  catch (...)
129  {
130  THROW_EXCEPTION("Runtime error!");
131  }
132 #else
133  MRPT_UNUSED_PARAM(objectsToRender);
134 #endif
135 }
136 
137 /*---------------------------------------------------------------
138  checkOpenGLError
139  ---------------------------------------------------------------*/
141 {
142 #if MRPT_HAS_OPENGL_GLUT
143  int openglErr;
144  if ((openglErr = glGetError()) != GL_NO_ERROR)
145  {
146  const std::string sErr = std::string("OpenGL error: ") +
147  std::string((char*)gluErrorString(openglErr));
148  std::cerr << "[gl_utils::checkOpenGLError] " << sErr << std::endl;
149  // THROW_EXCEPTION(sErr)
150  }
151 #endif
152 }
153 
155  const mrpt::math::TPoint3D& p1, const mrpt::math::TPoint3D& p2,
156  const mrpt::math::TPoint3D& p3)
157 {
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;
162 
163  const float bx = p3.x - p1.x;
164  const float by = p3.y - p1.y;
165  const float bz = p3.z - p1.z;
166 
167  glNormal3f(ay * bz - az * by, -ax * bz + az * bx, ax * by - ay * bx);
168 
169  glVertex3f(p1.x, p1.y, p1.z);
170  glVertex3f(p2.x, p2.y, p2.z);
171  glVertex3f(p3.x, p3.y, p3.z);
172 #else
173  MRPT_UNUSED_PARAM(p1);
174  MRPT_UNUSED_PARAM(p2);
175  MRPT_UNUSED_PARAM(p3);
176 #endif
177 }
179  const mrpt::math::TPoint3Df& p1, const mrpt::math::TPoint3Df& p2,
180  const mrpt::math::TPoint3Df& p3)
181 {
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;
186 
187  const float bx = p3.x - p1.x;
188  const float by = p3.y - p1.y;
189  const float bz = p3.z - p1.z;
190 
191  glNormal3f(ay * bz - az * by, -ax * bz + az * bx, ax * by - ay * bx);
192 
193  glVertex3f(p1.x, p1.y, p1.z);
194  glVertex3f(p2.x, p2.y, p2.z);
195  glVertex3f(p3.x, p3.y, p3.z);
196 #else
197  MRPT_UNUSED_PARAM(p1);
198  MRPT_UNUSED_PARAM(p2);
199  MRPT_UNUSED_PARAM(p3);
200 #endif
201 }
203  const mrpt::math::TPoint3Df& p1, const mrpt::math::TPoint3Df& p2,
204  const mrpt::math::TPoint3Df& p3, const mrpt::math::TPoint3Df& p4)
205 {
206  renderTriangleWithNormal(p1, p2, p3);
207  renderTriangleWithNormal(p3, p4, p1);
208 }
209 
210 /** Gather useful information on the render parameters.
211  * It can be called from within the render() method of derived classes.
212  */
214 {
215 #if MRPT_HAS_OPENGL_GLUT
216  // Viewport geometry:
217  GLint win_dims[4];
218  glGetIntegerv(GL_VIEWPORT, win_dims);
219  ri.vp_x = win_dims[0];
220  ri.vp_y = win_dims[1];
221  ri.vp_width = win_dims[2];
222  ri.vp_height = win_dims[3];
223 
224  // Get the inverse camera position:
225  GLfloat mat_proj[16];
227  ri.proj_matrix = Eigen::Matrix<float, 4, 4, Eigen::ColMajor>(mat_proj);
228 
229  // Extract the camera position:
230  Eigen::Matrix<float, 4, 1> cam_pose_hm = ri.proj_matrix.inverse().col(3);
231  if (cam_pose_hm[3] != 0)
232  {
233  ri.camera_position.x = cam_pose_hm[0] / cam_pose_hm[3];
234  ri.camera_position.y = cam_pose_hm[1] / cam_pose_hm[3];
235  ri.camera_position.z = cam_pose_hm[2] / cam_pose_hm[3];
236  }
237  else
239 
240  // Get the model transformation:
241  GLfloat mat_mod[16];
243  ri.model_matrix = Eigen::Matrix<float, 4, 4, Eigen::ColMajor>(mat_mod);
244 
245  // PROJ * MODEL
246  ri.full_matrix = ri.proj_matrix * ri.model_matrix;
247 #else
248  MRPT_UNUSED_PARAM(ri);
249 #endif
250 }
251 
252 /*---------------------------------------------------------------
253  renderTextBitmap
254  ---------------------------------------------------------------*/
255 void gl_utils::renderTextBitmap(const char* str, void* fontStyle)
256 {
257 #if MRPT_HAS_OPENGL_GLUT
258  while (*str) glutBitmapCharacter(fontStyle, *(str++));
259 #else
260  MRPT_UNUSED_PARAM(str);
261  MRPT_UNUSED_PARAM(fontStyle);
262 #endif
263 }
264 
266 {
267 #if MRPT_HAS_OPENGL_GLUT
268  switch (font)
269  {
270  default:
272  return GLUT_BITMAP_TIMES_ROMAN_10;
273  break;
275  return GLUT_BITMAP_TIMES_ROMAN_24;
276  break;
277 
279  return GLUT_BITMAP_HELVETICA_10;
280  break;
282  return GLUT_BITMAP_HELVETICA_12;
283  break;
285  return GLUT_BITMAP_HELVETICA_18;
286  break;
287  }
288 #else
289  MRPT_UNUSED_PARAM(font);
290  return nullptr;
291 #endif
292 }
293 
294 /** Return the exact width in pixels for a given string, as will be rendered by
295  * renderTextBitmap().
296  * \sa renderTextBitmap
297  */
299  const std::string& str, mrpt::opengl::TOpenGLFont font)
300 {
301 #if MRPT_HAS_OPENGL_GLUT
302  if (str.empty()) return 0;
303  return glutBitmapLength(
304  aux_mrptfont2glutfont(font), (const unsigned char*)str.c_str());
305 #else
306  MRPT_UNUSED_PARAM(str);
307  MRPT_UNUSED_PARAM(font);
308  return 10;
309 #endif
310 }
311 
312 /*---------------------------------------------------------------
313  renderTextBitmap
314  ---------------------------------------------------------------*/
316  int screen_x, int screen_y, const std::string& str, float color_r,
317  float color_g, float color_b, TOpenGLFont font)
318 {
319 #if MRPT_HAS_OPENGL_GLUT
321 
322  // If (x,y) are negative, wrap to the opposite side:
323  if (screen_x < 0 || screen_y < 0)
324  {
325  // Size of the viewport:
326  GLint win_dims[4]; // [2]:width ,[3]:height
327  glGetIntegerv(GL_VIEWPORT, win_dims);
328 
329  if (screen_x < 0) screen_x += win_dims[2];
330  if (screen_y < 0) screen_y += win_dims[3];
331  }
332 
333  // Draw text:
334  glColor3f(color_r, color_g, color_b);
335 
336  // From: http://www.mesa3d.org/brianp/sig97/gotchas.htm
337  GLfloat fx, fy;
338 
339  /* Push current matrix mode and viewport attributes */
341 
342  /* Setup projection parameters */
344  glPushMatrix();
345  glLoadIdentity();
347  glPushMatrix();
348  glLoadIdentity();
349 
350  // glDepthRange( z, z );
351  glViewport((int)screen_x - 1, (int)screen_y - 1, 2, 2);
352 
353  /* set the raster (window) position */
354  fx = screen_x - (int)screen_x;
355  fy = screen_y - (int)screen_y;
356  // glRasterPos4f( fx, fy, 0.0, w );
357  glRasterPos3f(fx, fy, 0.0);
358 
359  /* restore matrices, viewport and matrix mode */
360  glPopMatrix();
362  glPopMatrix();
363 
364  glPopAttrib();
365 
366  // Select font:
367  void* glut_font_sel = aux_mrptfont2glutfont(font);
368 
369  for (size_t i = 0; i < str.size(); i++)
370  glutBitmapCharacter(glut_font_sel, str[i]);
371 
373 #else
374  MRPT_UNUSED_PARAM(screen_x);
375  MRPT_UNUSED_PARAM(screen_y);
376  MRPT_UNUSED_PARAM(str);
377  MRPT_UNUSED_PARAM(color_r);
378  MRPT_UNUSED_PARAM(color_g);
379  MRPT_UNUSED_PARAM(color_b);
380  MRPT_UNUSED_PARAM(font);
381 #endif
382 }
383 
385  const float msg_x, const float msg_y, const float msg_w, const float msg_h,
386  const std::string& text, float text_scale,
387  const mrpt::utils::TColor& back_col, const mrpt::utils::TColor& border_col,
388  const mrpt::utils::TColor& text_col, const float border_width,
389  const std::string& text_font, mrpt::opengl::TOpenGLFontStyle text_style,
390  const double text_spacing, const double text_kerning)
391 {
392 #if MRPT_HAS_OPENGL_GLUT
393  const int nLines = 1 + std::count(text.begin(), text.end(), '\n');
394 
395  GLint win_dims[4];
396  glGetIntegerv(GL_VIEWPORT, win_dims);
397  const int w = win_dims[2];
398  const int h = win_dims[3];
399 
400  const int min_wh = std::min(w, h);
401  const float vw_w = w / float(min_wh);
402  const float vw_h = h / float(min_wh);
403 
405  glPushMatrix();
406 
407  glLoadIdentity();
408  glOrtho(0, vw_w, 0, vw_h, -1, 1);
409 
411  glPushMatrix();
412 
413  glLoadIdentity();
414 
418 
419  // The center of the message box:
420  const float msg_x0 = vw_w * msg_x;
421  const float msg_y0 = vw_h * msg_y;
422 
423  const float msg_x1 = vw_w * (msg_x + msg_w);
424  const float msg_y1 = vw_h * (msg_y + msg_h);
425 
426  const float msg_real_w = msg_x1 - msg_x0;
427  const float msg_real_h = msg_y1 - msg_y0;
428 
429  const float msg_cx = .5 * (msg_x0 + msg_x1);
430  const float msg_cy = .5 * (msg_y0 + msg_y1);
431 
432  // Background:
433  glColor4ub(back_col.R, back_col.G, back_col.B, back_col.A);
435  glVertex2f(msg_x0, msg_y0);
436  glVertex2f(msg_x1, msg_y0);
437  glVertex2f(msg_x1, msg_y1);
438  glVertex2f(msg_x0, msg_y1);
439  glEnd();
440 
441  // Border:
442  glColor4ub(border_col.R, border_col.G, border_col.B, border_col.A);
443  glLineWidth(border_width);
444  glDisable(GL_LIGHTING); // Disable lights when drawing lines
446  glVertex2f(msg_x0, msg_y0);
447  glVertex2f(msg_x1, msg_y0);
448  glVertex2f(msg_x1, msg_y1);
449  glVertex2f(msg_x0, msg_y1);
450  glEnd();
451  glEnable(GL_LIGHTING); // Disable lights when drawing lines
452 
453  // Draw text (centered):
454  gl_utils::glSetFont(text_font);
455  mrpt::utils::TPixelCoordf txtSize =
456  gl_utils::glGetExtends(text, text_scale, text_spacing, text_kerning);
457 
458  // Adjust text size if it doesn't fit into the box:
459  if (txtSize.x > msg_real_w)
460  {
461  const float K = 0.99f * msg_real_w / txtSize.x;
462  text_scale *= K;
463  txtSize.x *= K;
464  txtSize.y *= K;
465  }
466  if (txtSize.y > msg_real_h)
467  {
468  const float K = 0.99f * msg_real_h / txtSize.y;
469  text_scale *= K;
470  txtSize.x *= K;
471  txtSize.y *= K;
472  }
473 
474  const float text_w = txtSize.x;
475  const float text_h =
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;
479 
480  glTranslatef(text_x0, text_y0, 0);
481  glColor4ub(text_col.R, text_col.G, text_col.B, text_col.A);
483  text, text_scale, text_style, text_spacing, text_kerning);
484 
485  // Restore gl flags:
488 
489  glPopMatrix();
490 
492  glPopMatrix();
493 #else
494  MRPT_UNUSED_PARAM(msg_x);
495  MRPT_UNUSED_PARAM(msg_y);
496  MRPT_UNUSED_PARAM(msg_w);
497  MRPT_UNUSED_PARAM(msg_h);
498  MRPT_UNUSED_PARAM(text);
499  MRPT_UNUSED_PARAM(text_scale);
500  MRPT_UNUSED_PARAM(back_col);
501  MRPT_UNUSED_PARAM(border_col);
502  MRPT_UNUSED_PARAM(text_col);
503  MRPT_UNUSED_PARAM(border_width);
504  MRPT_UNUSED_PARAM(text_font);
505  MRPT_UNUSED_PARAM(text_style);
506  MRPT_UNUSED_PARAM(text_spacing);
507  MRPT_UNUSED_PARAM(text_kerning);
508 #endif
509 }
510 
511 // =============== START OF CODE FROM "libcvd -> gltext.cpp" ===============
512 // License: LGPL
513 #if MRPT_HAS_OPENGL_GLUT
514 namespace Internal
515 {
516 struct Point
517 {
518  float x, y;
519 };
520 
521 struct Font
522 {
523  typedef unsigned short Index;
524 
525  struct Char
526  {
527  Index vertexOffset;
528  Index triangleOffset;
529  Index outlineOffset;
530  GLsizei numTriangles;
531  GLsizei numOutlines;
532  float advance;
533  };
534 
535  Point* vertices;
536  Index* triangles;
537  Index* outlines;
538  Char* characters;
539  string glyphs;
540 
541  const Char* findChar(const char c) const
542  {
543  size_t ind = glyphs.find(c);
544  if (ind == string::npos) return nullptr;
545  return characters + ind;
546  }
547 
548  float getAdvance(const char c) const
549  {
550  const Char* ch = findChar(c);
551  if (!ch) return 0;
552  return ch->advance;
553  }
554 
555  void fill(const char c) const
556  {
557  const Char* ch = findChar(c);
558  if (!ch || !ch->numTriangles) return;
559  glVertexPointer(2, GL_FLOAT, 0, vertices + ch->vertexOffset);
560  glDisable(GL_LIGHTING); // Disable lights when drawing lines
562  GL_TRIANGLES, ch->numTriangles, GL_UNSIGNED_SHORT,
563  triangles + ch->triangleOffset);
565  }
566 
567  void outline(const char c) const
568  {
569  const Char* ch = findChar(c);
570  if (!ch || !ch->numOutlines) return;
571  glVertexPointer(2, GL_FLOAT, 0, vertices + ch->vertexOffset);
572  glDisable(GL_LIGHTING); // Disable lights when drawing lines
574  GL_LINES, ch->numOutlines, GL_UNSIGNED_SHORT,
575  outlines + ch->outlineOffset);
577  }
578 
579  void draw(const char c) const
580  {
581  const Char* ch = findChar(c);
582  if (!ch || !ch->numTriangles || !ch->numOutlines) return;
583  glVertexPointer(2, GL_FLOAT, 0, vertices + ch->vertexOffset);
584  glDisable(GL_LIGHTING); // Disable lights when drawing lines
586  GL_TRIANGLES, ch->numTriangles, GL_UNSIGNED_SHORT,
587  triangles + ch->triangleOffset);
589  GL_LINES, ch->numOutlines, GL_UNSIGNED_SHORT,
590  outlines + ch->outlineOffset);
591  glEnable(GL_LIGHTING); // Disable lights when drawing lines
592  }
593 };
594 
595 // the fonts defined in these headers are derived from Bitstream Vera fonts. See
596 // http://www.gnome.org/fonts/ for license and details
597 #include "glfont_sans.h"
598 #include "glfont_mono.h"
599 #include "glfont_serif.h"
600 
601 struct FontData
602 {
603  typedef map<string, Font*> FontMap;
604 
605  FontData()
606  {
607  fonts["sans"] = &sans_font;
608  fonts["mono"] = &mono_font;
609  fonts["serif"] = &serif_font;
610  gl_utils::glSetFont("sans");
611  }
612  inline Font* currentFont() { return fonts[currentFontName]; }
613  string currentFontName;
614  FontMap fonts;
615 };
616 
617 static struct FontData data;
618 } // namespace Internal
619 #endif
620 
621 void gl_utils::glSetFont(const std::string& fontname)
622 {
623 #if MRPT_HAS_OPENGL_GLUT
624  if (Internal::data.fonts.count(fontname) > 0)
625  Internal::data.currentFontName = fontname;
626 #else
627  MRPT_UNUSED_PARAM(fontname);
628 #endif
629 }
630 
632 {
633 #if MRPT_HAS_OPENGL_GLUT
634  return Internal::data.currentFontName;
635 #else
636  THROW_EXCEPTION("MRPT built without OpenGL")
637 #endif
638 }
639 
641  const std::string& text, const double textScale,
642  enum TOpenGLFontStyle style, double spacing, double kerning)
643 {
644 #if MRPT_HAS_OPENGL_GLUT
646  glPushMatrix();
647  if (style == NICE)
648  {
653  glLineWidth(1);
654  }
656 
657  // figure out which operation to do on the Char (yes, this is a pointer to
658  // member function :)
659  void (Internal::Font::*operation)(const char c) const;
660  operation = nullptr;
661  switch (style)
662  {
663  case FILL:
664  operation = &Internal::Font::fill;
665  break;
666  case OUTLINE:
667  operation = &Internal::Font::outline;
668  break;
669  case NICE:
670  operation = &Internal::Font::draw;
671  break;
672  default:
673  THROW_EXCEPTION("Invalid text style value.");
674  }
675 
676  // Scale of the text:
677  glScaled(textScale, textScale, textScale);
678 
679  int lines = 0;
680  double max_total = 0;
681  double total = 0;
682  const Internal::Font* font = Internal::data.currentFont();
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)
686  {
687  char c = text[i];
688  if (c == '\n')
689  {
690  glTranslated(-total, -spacing, 0);
691  max_total = std::max(max_total, total);
692  total = 0;
693  ++lines;
694  continue;
695  }
696  if (c == '\t')
697  {
698  const float advance = tab_width - std::fmod(total, tab_width);
699  total += advance;
700  glTranslated(advance, 0, 0);
701  continue;
702  }
703  const Internal::Font::Char* ch = font->findChar(c);
704  if (!ch)
705  {
706  c = toupper(c);
707  ch = font->findChar(c);
708  if (!ch)
709  {
710  c = '?';
711  ch = font->findChar(c);
712  }
713  }
714  if (!ch) continue;
715  (font->*operation)(c);
716 
717  double w = ch->advance + kerning;
718  glTranslated(w, 0, 0);
719  total += w;
720  }
721 
723  if (style == NICE)
724  {
725  glPopAttrib();
726  }
727  glPopMatrix();
728 
729  max_total = std::max(total, max_total);
730 
732  textScale * max_total, textScale * (lines + 1) * spacing);
733 #else
734  MRPT_UNUSED_PARAM(text);
735  MRPT_UNUSED_PARAM(textScale);
736  MRPT_UNUSED_PARAM(style);
737  MRPT_UNUSED_PARAM(spacing);
738  MRPT_UNUSED_PARAM(kerning);
739  THROW_EXCEPTION("MRPT built without OpenGL")
740 #endif
741 }
742 
744  const std::string& text, const double textScale, double spacing,
745  double kerning)
746 {
747 #if MRPT_HAS_OPENGL_GLUT
748  int lines = 0;
749  double max_total = 0;
750  double total = 0;
751  const Internal::Font* font = Internal::data.currentFont();
752  for (size_t i = 0; i < text.length(); ++i)
753  {
754  char c = text[i];
755  if (c == '\n')
756  {
757  max_total = std::max(max_total, total);
758  total = 0;
759  ++lines;
760  continue;
761  }
762  const Internal::Font::Char* ch = font->findChar(c);
763  if (!ch)
764  {
765  c = toupper(c);
766  ch = font->findChar(c);
767  if (!ch)
768  {
769  c = '?';
770  ch = font->findChar(c);
771  }
772  }
773  if (!ch) continue;
774  total += ch->advance + kerning;
775  }
776  max_total = std::max(total, max_total);
778  textScale * max_total, textScale * (lines + 1) * spacing);
779 #else
780  MRPT_UNUSED_PARAM(text);
781  MRPT_UNUSED_PARAM(textScale);
782  MRPT_UNUSED_PARAM(spacing);
783  MRPT_UNUSED_PARAM(kerning);
784  THROW_EXCEPTION("MRPT built without OpenGL")
785 #endif
786 }
787 // =============== 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:255
double getColorA() const
Color components in the range [0,1].
GLAPI void GLAPIENTRY glDisableClientState(GLenum array)
GLAPI void GLAPIENTRY glEnableClientState(GLenum array)
A pair (x,y) of pixel coordinates (subpixel resolution).
Definition: TPixelCoord.h:21
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.
Definition: gl_utils.cpp:640
GLuint GLuint GLsizei count
Definition: glext.h:3528
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:154
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.
Definition: gl_utils.cpp:384
GLAPI void GLAPIENTRY glGetFloatv(GLenum pname, GLfloat *params)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
#define min(a, b)
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
float getScaleX() const
Get the current scaling factor in one axis.
double GLdouble
Definition: glew.h:219
EIGEN_STRONG_INLINE void fill(const Scalar v)
Definition: eigen_plugins.h:46
GLbyte GLbyte bz
Definition: glext.h:6105
GLAPI void GLAPIENTRY glEnable(GLenum cap)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:30
GLAPI void GLAPIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
#define GL_VERTEX_ARRAY
Definition: glew.h:724
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:202
#define GL_LIGHTING_BIT
Definition: glew.h:257
const std::string & glGetFont()
returns the name of the currently active font
Definition: gl_utils.cpp:631
Font mono_font
Definition: glfont_mono.h:2649
GLAPI void GLAPIENTRY glScaled(GLdouble x, GLdouble y, GLdouble z)
#define GL_MODELVIEW
Definition: glew.h:610
std::deque< CRenderizable::Ptr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
#define THROW_EXCEPTION(msg)
GLAPI void GLAPIENTRY glPopMatrix(void)
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
#define GL_TRIANGLES
Definition: glew.h:276
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:43
#define GL_VIEWPORT_BIT
Definition: glew.h:262
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:27
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
#define GL_DEPTH_TEST
Definition: glew.h:401
GLAPI void GLAPIENTRY glPopAttrib(void)
#define GL_LIGHTING
Definition: glew.h:385
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:621
GLAPI void GLAPIENTRY glLoadIdentity(void)
#define GL_CURRENT_RASTER_POSITION
Definition: glew.h:360
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
renders glyphs as outlines with GL_LINES
Definition: opengl_fonts.h:39
float GLfloat
Definition: glew.h:217
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
#define GL_COLOR_BUFFER_BIT
Definition: glew.h:265
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
TOpenGLFont
Existing fonts for 2D texts in mrpt::opengl methods.
Definition: opengl_fonts.h:25
Lightweight 3D point (float version).
mrpt::math::CArrayDouble< 3 > m_coords
The translation vector [x,y,z] access directly or with x(), y(), z() setter/getter methods...
Definition: CPose3D.h:98
#define GL_LINE_SMOOTH
Definition: glew.h:367
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
const GLubyte * c
Definition: glext.h:6313
bool isVisible() const
Is the object visible?
Definition: CRenderizable.h:71
TOpenGLFontStyle
Different style for vectorized font rendering.
Definition: opengl_fonts.h:36
Information about the rendering process being issued.
Definition: gl_utils.h:34
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > model_matrix
The 4x4 model transformation matrix.
Definition: gl_utils.h:41
#define GL_MODELVIEW_MATRIX
Definition: glew.h:421
A RGB color - 8bit.
Definition: TColor.h:25
#define GL_PROJECTION
Definition: glew.h:611
GLAPI void GLAPIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue)
const std::string & getName() const
Returns the name of the object.
Definition: CRenderizable.h:70
double x
X,Y,Z coordinates.
GLAPI void GLAPIENTRY glTranslated(GLdouble x, GLdouble y, GLdouble z)
GLAPI void GLAPIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
GLAPI void GLAPIENTRY glBegin(GLenum mode)
#define GL_BLEND
Definition: glew.h:432
int vp_x
Rendering viewport geometry (in pixels)
Definition: gl_utils.h:37
GLsizei const GLchar ** string
Definition: glext.h:4101
#define GL_LINE_LOOP
Definition: glew.h:274
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
#define GL_UNSIGNED_SHORT
Definition: glew.h:304
#define MRPT_PROFILE_FUNC_START
GLAPI void GLAPIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
#define GL_SRC_ALPHA
Definition: glew.h:286
Font sans_font
Definition: glfont_sans.h:2587
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define GL_NO_ERROR
Definition: glew.h:326
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
#define GL_VIEWPORT
Definition: glew.h:417
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > full_matrix
PROJ * MODEL.
Definition: gl_utils.h:43
GLAPI void GLAPIENTRY glMultMatrixd(const GLdouble *m)
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 ...
Definition: gl_utils.cpp:743
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
const float R
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
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:298
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:140
GLAPI void GLAPIENTRY glGetIntegerv(GLenum pname, GLint *params)
GLAPI GLenum GLAPIENTRY glGetError(void)
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > proj_matrix
The 4x4 projection matrix.
Definition: gl_utils.h:39
renders glyphs filled with antialiased outlines
Definition: opengl_fonts.h:40
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:213
GLAPI void GLAPIENTRY glEnd(void)
#define GL_TRANSFORM_BIT
Definition: glew.h:263
GLenum GLint GLint y
Definition: glext.h:3538
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:6105
#define GL_TRIANGLE_FAN
Definition: glew.h:278
#define GL_FLOAT
Definition: glew.h:307
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
int GLint
Definition: glew.h:209
#define GL_LINES
Definition: glew.h:273
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
#define GL_PROJECTION_MATRIX
Definition: glew.h:422
GLAPI void GLAPIENTRY glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
GLenum GLint x
Definition: glext.h:3538
#define GL_CURRENT_BIT
Definition: glew.h:251
GLAPI void GLAPIENTRY glPushMatrix(void)
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
Definition: CPose3D.h:237
double getColorB() const
Color components in the range [0,1].
Lightweight 3D point.
void renderSetOfObjects(const mrpt::opengl::CListOpenGLObjects &objs)
For each object in the list:
Definition: gl_utils.cpp:32
void * aux_mrptfont2glutfont(const TOpenGLFont font)
Definition: gl_utils.cpp:265
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.
renders glyphs as filled polygons
Definition: opengl_fonts.h:38
GLAPI void GLAPIENTRY glDisable(GLenum cap)
double getColorG() const
Color components in the range [0,1].
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
int GLsizei
Definition: glew.h:210
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:188
#define GL_LINE_BIT
Definition: glew.h:253
double getColorR() const
Color components in the range [0,1].
Font serif_font
mrpt::math::TPoint3Df camera_position
The 3D location of the camera.
Definition: gl_utils.h:45



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