14 #include <Eigen/Dense> 18 #if MRPT_HAS_OPENGL_GLUT 19 #include <cvd/gl_helpers.h> 37 #if MRPT_HAS_OPENGL_GLUT 40 CListOpenGLObjects::const_iterator itP;
43 for (itP = objectsToRender.begin(); itP != objectsToRender.end(); ++itP)
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,
99 float eye_distance = raster_pos[3];
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;
127 str, 1000,
"Exception while rendering a class '%s'\n%s",
128 (*itP)->GetRuntimeClass()->className, e.what());
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 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];
157 #if MRPT_HAS_OPENGL_GLUT 163 std::cerr <<
"[gl_utils::checkOpenGLError] " << sErr << std::endl;
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;
178 const float bx = p3.
x - p1.
x;
179 const float by = p3.
y - p1.
y;
180 const float bz = p3.
z - p1.
z;
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;
202 const float bx = p3.
x - p1.
x;
203 const float by = p3.
y - p1.
y;
204 const float bz = p3.
z - p1.
z;
230 #if MRPT_HAS_OPENGL_GLUT 234 ri.
vp_x = win_dims[0];
235 ri.
vp_y = win_dims[1];
247 const auto cam_pose_hm = HMinv.col(3).eval();
248 if (cam_pose_hm[3] != 0)
274 #if MRPT_HAS_OPENGL_GLUT 275 while (*str) glutBitmapCharacter(fontStyle, *(str++));
284 #if MRPT_HAS_OPENGL_GLUT 289 return GLUT_BITMAP_TIMES_ROMAN_10;
292 return GLUT_BITMAP_TIMES_ROMAN_24;
296 return GLUT_BITMAP_HELVETICA_10;
299 return GLUT_BITMAP_HELVETICA_12;
302 return GLUT_BITMAP_HELVETICA_18;
318 #if MRPT_HAS_OPENGL_GLUT 319 if (str.empty())
return 0;
320 return glutBitmapLength(
333 int screen_x,
int screen_y,
const std::string& str,
float color_r,
336 #if MRPT_HAS_OPENGL_GLUT 340 if (screen_x < 0 || screen_y < 0)
346 if (screen_x < 0) screen_x += win_dims[2];
347 if (screen_y < 0) screen_y += win_dims[3];
368 glViewport((
int)screen_x - 1, (
int)screen_y - 1, 2, 2);
371 fx = screen_x - (int)screen_x;
372 fy = screen_y - (int)screen_y;
386 for (
char i : str) glutBitmapCharacter(glut_font_sel, i);
401 const float msg_x,
const float msg_y,
const float msg_w,
const float msg_h,
406 const double text_spacing,
const double text_kerning)
408 #if MRPT_HAS_OPENGL_GLUT 409 const int nLines = 1 +
std::count(text.begin(), text.end(),
'\n');
413 const int w = win_dims[2];
414 const int h = win_dims[3];
417 const float vw_w =
w / float(min_wh);
418 const float vw_h = h / float(min_wh);
424 glOrtho(0, vw_w, 0, vw_h, -1, 1);
436 const float msg_x0 = vw_w * msg_x;
437 const float msg_y0 = vw_h * msg_y;
439 const float msg_x1 = vw_w * (msg_x + msg_w);
440 const float msg_y1 = vw_h * (msg_y + msg_h);
442 const float msg_real_w = msg_x1 - msg_x0;
443 const float msg_real_h = msg_y1 - msg_y0;
445 const float msg_cx = .5 * (msg_x0 + msg_x1);
446 const float msg_cy = .5 * (msg_y0 + msg_y1);
458 glColor4ub(border_col.
R, border_col.
G, border_col.
B, border_col.
A);
475 if (txtSize.
x > msg_real_w)
477 const float K = 0.99f * msg_real_w / txtSize.
x;
482 if (txtSize.
y > msg_real_h)
484 const float K = 0.99f * msg_real_h / txtSize.
y;
490 const float text_w = txtSize.
x;
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;
499 text, text_scale, text_style, text_spacing, text_kerning);
529 #if MRPT_HAS_OPENGL_GLUT 538 #if MRPT_HAS_OPENGL_GLUT 549 #if MRPT_HAS_OPENGL_GLUT 552 glScaled(textScale, textScale, textScale);
554 text, static_cast<CVD::TEXT_STYLE>(style), spacing, kerning);
568 const std::string& text,
const double textScale,
double spacing,
571 #if MRPT_HAS_OPENGL_GLUT void 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].
GLuint GLuint GLsizei count
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...
GLAPI void GLAPIENTRY glGetFloatv(GLenum pname, GLfloat *params)
double x
X,Y,Z coordinates.
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
float getScaleX() const
Get the current scaling factor in one axis.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
#define THROW_EXCEPTION(msg)
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...
mrpt::math::CMatrixFixed< float, 4, 4 > full_matrix
PROJ * MODEL.
mrpt::math::CVectorFixedDouble< 3 > m_coords
The translation vector [x,y,z] access directly or with x(), y(), z() setter/getter methods...
const std::string & glGetFont()
returns the name of the currently active font
GLAPI void GLAPIENTRY glScaled(GLdouble x, GLdouble y, GLdouble z)
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.
mrpt::math::CMatrixFixed< float, 4, 4 > proj_matrix
The 4x4 projection matrix.
A pair (x,y) of pixel coordinates (subpixel resolution).
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.
#define GL_ONE_MINUS_SRC_ALPHA
GLAPI void GLAPIENTRY glPopAttrib(void)
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
void 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
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
#define MRPT_PROFILE_FUNC_START
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.
Lightweight 3D point (float version).
bool isVisible() const
Is the object visible?
TOpenGLFontStyle
Different style for vectorized font rendering.
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 ...
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 glBegin(GLenum mode)
int vp_x
Rendering viewport geometry (in pixels)
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)
bool isShowNameEnabled() const
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)
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.
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 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 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)
The namespace for 3D scene representation and rendering.
void getCurrentRenderingInfo(TRenderInfo &ri)
Gather useful information on the render parameters.
GLAPI void GLAPIENTRY glEnd(void)
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.
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 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.
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...
mrpt::math::CMatrixFixed< float, 4, 4 > model_matrix
The 4x4 model transformation matrix.
double getColorR() const
Color components in the range [0,1].
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
mrpt::math::TPoint3Df camera_position
The 3D location of the camera.