A set of auxiliary functions that can be called to render OpenGL primitives from MRPT or user code.
Classes | |
struct | TRenderInfo |
Information about the rendering process being issued. More... | |
Functions | |
Miscellaneous rendering methods | |
void OPENGL_IMPEXP | renderSetOfObjects (const mrpt::opengl::CListOpenGLObjects &objs) |
For each object in the list: More... | |
void OPENGL_IMPEXP | checkOpenGLError () |
Checks glGetError and throws an exception if an error situation is found. More... | |
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 called within a glBegin()-glEnd() block. More... | |
void OPENGL_IMPEXP | renderTriangleWithNormal (const mrpt::math::TPoint3Df &p1, const mrpt::math::TPoint3Df &p2, const mrpt::math::TPoint3Df &p3) |
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 called within a glBegin()-glEnd() block. More... | |
void OPENGL_IMPEXP | getCurrentRenderingInfo (TRenderInfo &ri) |
Gather useful information on the render parameters. More... | |
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. More... | |
OpenGL bitmapped 2D fonts | |
void OPENGL_IMPEXP | renderTextBitmap (const char *str, void *fontStyle) |
This method is safe for calling from within ::render() methods. More... | |
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(). More... | |
OpenGL vector 3D fonts | |
void OPENGL_IMPEXP | glSetFont (const std::string &fontname) |
sets the font to use for future font rendering commands. More... | |
const OPENGL_IMPEXP std::string & | glGetFont () |
returns the name of the currently active font More... | |
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. More... | |
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 visual output More... | |
void mrpt::opengl::gl_utils::checkOpenGLError | ( | ) |
Checks glGetError and throws an exception if an error situation is found.
Definition at line 134 of file gl_utils.cpp.
References GL_NO_ERROR, and glGetError().
Referenced by mrpt::opengl::CRenderizable::checkOpenGLError(), mrpt::opengl::CPointCloudColoured::render(), mrpt::opengl::CPointCloud::render(), mrpt::opengl::CDisk::render_dl(), mrpt::opengl::CCylinder::render_dl(), mrpt::opengl::CSphere::render_dl(), mrpt::opengl::CAxis::render_dl(), mrpt::opengl::CFrustum::render_dl(), mrpt::opengl::CEllipsoid::render_dl(), mrpt::opengl::CPlanarLaserScan::render_dl(), mrpt::opengl::CGeneralizedCylinder::render_dl(), mrpt::opengl::CMeshFast::render_dl(), mrpt::opengl::COctoMapVoxels::render_dl(), mrpt::opengl::CPolyhedron::render_dl(), mrpt::opengl::detail::renderGeneralizedEllipsoidTemplate< 2 >(), mrpt::opengl::detail::renderGeneralizedEllipsoidTemplate< 3 >(), and renderSetOfObjects().
void mrpt::opengl::gl_utils::getCurrentRenderingInfo | ( | TRenderInfo & | ri | ) |
Gather useful information on the render parameters.
It can be called from within the render() method of CRenderizable-derived classes, and the returned matrices can be used to determine whether a given point (lx,ly,lz) in local coordinates wrt the object being rendered falls within the screen or not:
where (rend_x,rend_y) are both in the range [-1,1].
It can be called from within the render() method of derived classes.
Definition at line 197 of file gl_utils.cpp.
References mrpt::opengl::gl_utils::TRenderInfo::camera_position, mrpt::opengl::gl_utils::TRenderInfo::full_matrix, GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX, GL_VIEWPORT, glGetFloatv(), glGetIntegerv(), mrpt::opengl::gl_utils::TRenderInfo::model_matrix, MRPT_UNUSED_PARAM, mrpt::opengl::gl_utils::TRenderInfo::proj_matrix, mrpt::opengl::gl_utils::TRenderInfo::vp_height, mrpt::opengl::gl_utils::TRenderInfo::vp_width, mrpt::opengl::gl_utils::TRenderInfo::vp_x, mrpt::opengl::gl_utils::TRenderInfo::vp_y, mrpt::math::TPoint3Df::x, mrpt::math::TPoint3Df::y, and mrpt::math::TPoint3Df::z.
Referenced by mrpt::opengl::CPointCloudColoured::render(), and mrpt::opengl::CPointCloud::render().
mrpt::utils::TPixelCoordf mrpt::opengl::gl_utils::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.
Font coordinates are +X along the line and +Y along the up direction of glyphs. The origin is at the top baseline at the left of the first character. Characters have a maximum size of 1. linefeed is interpreted as a new line and the start is offset in -Y direction by spacing . Individual characters are separated by kerning + plus their individual with.
text | string to be rendered, unknown characters are replaced with '?' |
textScale | The size of the characters (default=1.0) |
style | rendering style |
spacing | distance between individual text lines |
kerning | distance between characters |
Definition at line 600 of file gl_utils.cpp.
References mrpt::opengl::FILL, fill(), GL_BLEND, GL_COLOR_BUFFER_BIT, GL_LINE_BIT, GL_LINE_SMOOTH, GL_MODELVIEW, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_VERTEX_ARRAY, glBlendFunc(), glDisableClientState(), glEnable(), glEnableClientState(), glLineWidth(), glMatrixMode(), glPopAttrib(), glPopMatrix(), glPushAttrib(), glPushMatrix(), glScaled(), glTranslated(), MRPT_UNUSED_PARAM, mrpt::opengl::NICE, mrpt::opengl::OUTLINE, THROW_EXCEPTION, and void().
Referenced by mrpt::opengl::CColorBar::render_dl(), mrpt::opengl::CAxis::render_dl(), mrpt::opengl::CText3D::render_dl(), mrpt::opengl::CTextMessageCapable::render_text_messages(), and renderMessageBox().
mrpt::utils::TPixelCoordf mrpt::opengl::gl_utils::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 visual output
Definition at line 684 of file gl_utils.cpp.
References MRPT_UNUSED_PARAM, and THROW_EXCEPTION.
Referenced by renderMessageBox().
const std::string & mrpt::opengl::gl_utils::glGetFont | ( | ) |
returns the name of the currently active font
Definition at line 592 of file gl_utils.cpp.
References THROW_EXCEPTION.
void mrpt::opengl::gl_utils::glSetFont | ( | const std::string & | fontname | ) |
sets the font to use for future font rendering commands.
currently "sans", "serif" and "mono" are available.
fontname | string containing font name |
Definition at line 583 of file gl_utils.cpp.
References MRPT_UNUSED_PARAM.
Referenced by mrpt::opengl::CColorBar::render_dl(), mrpt::opengl::CText3D::render_dl(), mrpt::opengl::CTextMessageCapable::render_text_messages(), and renderMessageBox().
void mrpt::opengl::gl_utils::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.
It consists of a filled rectangle with a frame around and the centered text in the middle.
The appearance of the box is highly configurable via parameters.
[in] | msg_x,msg_y | The left-lower corner coordinates, in ratio [0,1] of the viewport size. (0,0) if the left-bottom corner of the viewport. |
[in] | msg_w,msg_h | The width & height, in ratio [0,1] of the viewport size. |
[in] | text | The text to display. Multiple lines can be drawn with the ' ' character. |
[in] | text_scale | Size of characters, in ration [0,1] of the viewport size. Note that this size may be scaled automatically reduced to fit the text withtin the rectangle of the message box. |
[in] | back_col | Color of the rectangle background. Alpha can be <255 to enable transparency. |
[in] | border_col | Color of the rectangle frame. Alpha can be <255 to enable transparency. |
[in] | text_col | Color of the text background. Alpha can be <255 to enable transparency. |
[in] | border_width | Width of the border, in pixels |
[in] | text_font,text_style,text_spacing,text_kerning | See mrpt::opengl::gl_utils::glDrawText() |
Example (see directory: 'samples/display3D_custom_render'):
Definition at line 358 of file gl_utils.cpp.
References mrpt::utils::TColor::A, mrpt::utils::TColor::B, mrpt::utils::TColor::G, GL_BLEND, GL_DEPTH_TEST, GL_LIGHTING, GL_LINE_LOOP, GL_MODELVIEW, GL_ONE_MINUS_SRC_ALPHA, GL_PROJECTION, GL_SRC_ALPHA, GL_TRIANGLE_FAN, GL_VIEWPORT, glBegin(), glBlendFunc(), glColor4ub(), glDisable(), glDrawText(), glEnable(), glEnd(), glGetExtends(), glGetIntegerv(), glLineWidth(), glLoadIdentity(), glMatrixMode(), glOrtho(), glPopMatrix(), glPushMatrix(), glSetFont(), glTranslatef(), glVertex2f(), min, MRPT_UNUSED_PARAM, mrpt::utils::TColor::R, mrpt::utils::TPixelCoordf::x, and mrpt::utils::TPixelCoordf::y.
Referenced by mrpt::graphslam::CWindowObserver::OnEvent().
void mrpt::opengl::gl_utils::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 called within a glBegin()-glEnd() block.
Definition at line 187 of file gl_utils.cpp.
References renderTriangleWithNormal().
Referenced by mrpt::opengl::CFrustum::render_dl().
void mrpt::opengl::gl_utils::renderSetOfObjects | ( | const mrpt::opengl::CListOpenGLObjects & | objs | ) |
For each object in the list:
Definition at line 33 of file gl_utils.cpp.
References checkOpenGLError(), mrpt::opengl::CRenderizable::getColorA(), mrpt::opengl::CRenderizable::getColorB(), mrpt::opengl::CRenderizable::getColorG(), mrpt::opengl::CRenderizable::getColorR(), mrpt::opengl::CRenderizable::getName(), mrpt::opengl::CRenderizable::getPoseRef(), mrpt::poses::CPose3D::getRotationMatrix(), mrpt::opengl::CRenderizable::getScaleX(), mrpt::opengl::CRenderizable::getScaleY(), mrpt::opengl::CRenderizable::getScaleZ(), GL_CURRENT_BIT, GL_CURRENT_RASTER_POSITION, GL_DEPTH_TEST, GL_LIGHTING_BIT, GL_MODELVIEW, glColor3f(), glColor4f(), glDisable(), glEnable(), glGetFloatv(), glMatrixMode(), glMultMatrixd(), glPopAttrib(), glPopMatrix(), glPushAttrib(), glPushMatrix(), glRasterPos3f(), glScalef(), mrpt::opengl::CRenderizable::isShowNameEnabled(), mrpt::opengl::CRenderizable::isVisible(), mrpt::poses::CPose3D::m_coords, MRPT_PROFILE_FUNC_START, MRPT_UNUSED_PARAM, R, mrpt::opengl::CRenderizable::render(), renderTextBitmap(), mrpt::system::os::sprintf(), and THROW_EXCEPTION.
Referenced by mrpt::opengl::CSetOfObjects::render(), and mrpt::opengl::COpenGLViewport::render().
This method is safe for calling from within ::render() methods.
Definition at line 238 of file gl_utils.cpp.
References MRPT_UNUSED_PARAM.
Referenced by mrpt::opengl::CText::render(), renderSetOfObjects(), and mrpt::opengl::CRenderizable::renderTextBitmap().
void mrpt::opengl::gl_utils::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 called within a glBegin()-glEnd() block.
Definition at line 147 of file gl_utils.cpp.
References glNormal3f(), glVertex3f(), MRPT_UNUSED_PARAM, mrpt::math::TPoint3D::x, mrpt::math::TPoint3D::y, and mrpt::math::TPoint3D::z.
Referenced by mrpt::opengl::CBox::render_dl(), and renderQuadWithNormal().
void mrpt::opengl::gl_utils::renderTriangleWithNormal | ( | const mrpt::math::TPoint3Df & | p1, |
const mrpt::math::TPoint3Df & | p2, | ||
const mrpt::math::TPoint3Df & | p3 | ||
) |
Definition at line 167 of file gl_utils.cpp.
References glNormal3f(), glVertex3f(), MRPT_UNUSED_PARAM, mrpt::math::TPoint3Df::x, mrpt::math::TPoint3Df::y, and mrpt::math::TPoint3Df::z.
int mrpt::opengl::gl_utils::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 at line 270 of file gl_utils.cpp.
References aux_mrptfont2glutfont(), and MRPT_UNUSED_PARAM.
Referenced by mrpt::opengl::CRenderizable::textBitmapWidth().
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 |