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



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019