35 #if MRPT_HAS_OPENGL_GLUT 41 for (itP=objectsToRender.begin();itP!=objectsToRender.end();++itP)
43 if (!itP->present())
continue;
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,
91 float eye_distance= raster_pos[3];
95 font = GLUT_BITMAP_TIMES_ROMAN_24;
96 else if(eye_distance<200)
97 font = GLUT_BITMAP_TIMES_ROMAN_10;
117 os::sprintf(str,1000,
"Exception while rendering a class '%s'\n%s",
118 (*itP)->GetRuntimeClass()->className,
136 #if MRPT_HAS_OPENGL_GLUT 141 std::cerr <<
"[gl_utils::checkOpenGLError] " << sErr << std::endl;
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;
154 const float bx= p3.
x - p1.
x;
155 const float by= p3.
y - p1.
y;
156 const float bz= p3.
z - p1.
z;
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;
174 const float bx= p3.
x - p1.
x;
175 const float by= p3.
y - p1.
y;
176 const float bz= p3.
z - p1.
z;
199 #if MRPT_HAS_OPENGL_GLUT 203 ri.
vp_x = win_dims[0];
204 ri.
vp_y = win_dims[1];
211 ri.
proj_matrix = Eigen::Matrix<float,4,4,Eigen::ColMajor>(mat_proj);
214 Eigen::Matrix<float,4,1> cam_pose_hm = ri.
proj_matrix.inverse().col(3);
215 if (cam_pose_hm[3]!=0)
226 ri.
model_matrix = Eigen::Matrix<float,4,4,Eigen::ColMajor>(mat_mod);
240 #if MRPT_HAS_OPENGL_GLUT 241 while ( *str ) glutBitmapCharacter( fontStyle ,*(str++) );
250 #if MRPT_HAS_OPENGL_GLUT 274 #if MRPT_HAS_OPENGL_GLUT 275 if (str.empty())
return 0;
296 #if MRPT_HAS_OPENGL_GLUT 300 if (screen_x<0 || screen_y<0)
306 if (screen_x<0) screen_x += win_dims[2];
307 if (screen_y<0) screen_y += win_dims[3];
328 glViewport( (
int) screen_x - 1, (
int) screen_y - 1, 2, 2 );
331 fx = screen_x - (int) screen_x;
332 fy = screen_y - (int) screen_y;
346 for (
size_t i=0;i<str.size();i++)
347 glutBitmapCharacter( glut_font_sel ,str[i] );
359 const float msg_x,
const float msg_y,
360 const float msg_w,
const float msg_h,
366 const float border_width,
369 const double text_spacing,
370 const double text_kerning
373 #if MRPT_HAS_OPENGL_GLUT 374 const int nLines = 1 +
std::count(text.begin(),text.end(),
'\n');
378 const int w = win_dims[2];
379 const int h = win_dims[3];
382 const float vw_w =
w/float(min_wh);
383 const float vw_h = h/float(min_wh);
401 const float msg_x0 = vw_w * msg_x;
402 const float msg_y0 = vw_h * msg_y;
404 const float msg_x1 = vw_w * (msg_x+msg_w);
405 const float msg_y1 = vw_h * (msg_y+msg_h);
407 const float msg_real_w = msg_x1-msg_x0;
408 const float msg_real_h = msg_y1-msg_y0;
410 const float msg_cx = .5*(msg_x0+msg_x1);
411 const float msg_cy = .5*(msg_y0+msg_y1);
440 if (txtSize.
x>msg_real_w)
442 const float K = 0.99f * msg_real_w/txtSize.
x;
444 txtSize.
x *=K; txtSize.
y *=K;
446 if (txtSize.
y>msg_real_h)
448 const float K = 0.99f * msg_real_h/txtSize.
y;
450 txtSize.
x *=K; txtSize.
y *=K;
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;
484 #if MRPT_HAS_OPENGL_GLUT 493 typedef unsigned short Index;
497 Index triangleOffset;
510 const Char * findChar(
const char c )
const {
511 size_t ind = glyphs.find(
c);
512 if(ind == string::npos)
514 return characters + ind;
517 float getAdvance(
const char c )
const {
518 const Char * ch = findChar(
c);
524 void fill(
const char c )
const {
525 const Char * ch = findChar(
c);
526 if(!ch || !ch->numTriangles)
534 void outline(
const char c )
const {
535 const Char * ch = findChar(
c);
536 if(!ch || !ch->numOutlines)
544 void draw(
const char c )
const {
545 const Char * ch = findChar(
c);
546 if(!ch || !ch->numTriangles || !ch->numOutlines)
563 typedef map<string,Font *> FontMap;
571 inline Font * currentFont(){
572 return fonts[currentFontName];
575 string currentFontName;
579 static struct FontData
data;
584 #if MRPT_HAS_OPENGL_GLUT 593 #if MRPT_HAS_OPENGL_GLUT 601 #if MRPT_HAS_OPENGL_GLUT 614 void (Internal::Font::* operation)(
const char c)
const;
619 case OUTLINE: operation = &Internal::Font::outline;
621 case NICE: operation = &Internal::Font::draw;
627 glScaled(textScale,textScale,textScale);
630 double max_total = 0;
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) {
639 max_total = std::max(max_total, total);
645 const float advance = tab_width - std::fmod(total, tab_width);
650 const Internal::Font::Char * ch = font->findChar(
c);
653 ch = font->findChar(
c);
656 ch = font->findChar(
c);
661 (font->*operation)(
c);
663 double w = ch->advance + kerning;
674 max_total = std::max(total, max_total);
686 #if MRPT_HAS_OPENGL_GLUT 688 double max_total = 0;
691 for (
size_t i=0; i<text.length(); ++i) {
694 max_total = std::max(max_total, total);
699 const Internal::Font::Char * ch = font->findChar(
c);
702 ch = font->findChar(
c);
705 ch = font->findChar(
c);
710 total += ch->advance + kerning;
712 max_total = std::max(total, max_total);
void OPENGL_IMPEXP renderTextBitmap(const char *str, void *fontStyle)
This method is safe for calling from within ::render() methods.
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).
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.
GLuint GLuint GLsizei count
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...
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.
GLAPI void GLAPIENTRY glGetFloatv(GLenum pname, GLfloat *params)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
float getScaleX() const
Get the current scaling factor in one axis.
EIGEN_STRONG_INLINE void fill(const Scalar v)
GLAPI void GLAPIENTRY glEnable(GLenum cap)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
GLAPI void GLAPIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
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...
const OPENGL_IMPEXP std::string & glGetFont()
returns the name of the currently active font
GLAPI void GLAPIENTRY glScaled(GLdouble x, GLdouble y, GLdouble z)
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > proj_matrix
The 4x4 projection matrix.
#define THROW_EXCEPTION(msg)
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.
std::deque< CRenderizablePtr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
const Scalar * const_iterator
#define GL_ONE_MINUS_SRC_ALPHA
double z
X,Y,Z coordinates.
GLAPI void GLAPIENTRY glPopAttrib(void)
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
void OPENGL_IMPEXP glSetFont(const std::string &fontname)
sets the font to use for future font rendering commands.
GLAPI void GLAPIENTRY glLoadIdentity(void)
#define GL_CURRENT_RASTER_POSITION
GLubyte GLubyte GLubyte GLubyte w
renders glyphs as outlines with GL_LINES
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
int vp_height
Rendering viewport geometry (in pixels)
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > full_matrix
PROJ * MODEL.
#define GL_COLOR_BUFFER_BIT
This base provides a set of functions for maths stuff.
TOpenGLFont
Existing fonts for 2D texts in mrpt::opengl methods.
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...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
bool isVisible() const
Is the object visible?
TOpenGLFontStyle
Different style for vectorized font rendering.
Information about the rendering process being issued.
#define GL_MODELVIEW_MATRIX
GLAPI void GLAPIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue)
const std::string & getName() const
Returns the name of the object.
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)
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
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
#define MRPT_PROFILE_FUNC_START
bool isShowNameEnabled() const
GLAPI void GLAPIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
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 ...
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
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().
void OPENGL_IMPEXP checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
GLAPI void GLAPIENTRY glGetIntegerv(GLenum pname, GLint *params)
GLAPI GLenum GLAPIENTRY glGetError(void)
renders glyphs filled with antialiased outlines
The namespace for 3D scene representation and rendering.
void OPENGL_IMPEXP getCurrentRenderingInfo(TRenderInfo &ri)
Gather useful information on the render parameters.
GLAPI void GLAPIENTRY glEnd(void)
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > model_matrix
The 4x4 model transformation matrix.
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...
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...
float getScaleY() const
Get the current scaling factor in one axis.
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
#define GL_PROJECTION_MATRIX
GLAPI void GLAPIENTRY glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
GLAPI void GLAPIENTRY glPushMatrix(void)
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
double getColorB() const
Color components in the range [0,1].
void OPENGL_IMPEXP renderSetOfObjects(const mrpt::opengl::CListOpenGLObjects &objs)
For each object in the list:
void * aux_mrptfont2glutfont(const TOpenGLFont font)
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
GLAPI void GLAPIENTRY glDisable(GLenum cap)
double getColorG() const
Color components in the range [0,1].
GLsizei GLsizei GLenum GLenum const GLvoid * data
float getScaleZ() const
Get the current scaling factor in one axis.
double getColorR() const
Color components in the range [0,1].
mrpt::math::TPoint3Df camera_position
The 3D location of the camera.