Go to the documentation of this file.
16 #if MRPT_HAS_OPENGL_GLUT
17 #include <cvd/gl_helpers.h>
37 #if MRPT_HAS_OPENGL_GLUT
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());
145 #if MRPT_HAS_OPENGL_GLUT
151 std::cerr <<
"[gl_utils::checkOpenGLError] " << sErr << std::endl;
161 #if MRPT_HAS_OPENGL_GLUT
162 const float ax = p2.
x - p1.
x;
163 const float ay = p2.
y - p1.
y;
164 const float az = p2.
z - p1.
z;
166 const float bx = p3.
x - p1.
x;
167 const float by = p3.
y - p1.
y;
168 const float bz = p3.
z - p1.
z;
185 #if MRPT_HAS_OPENGL_GLUT
186 const float ax = p2.
x - p1.
x;
187 const float ay = p2.
y - p1.
y;
188 const float az = p2.
z - p1.
z;
190 const float bx = p3.
x - p1.
x;
191 const float by = p3.
y - p1.
y;
192 const float bz = p3.
z - p1.
z;
218 #if MRPT_HAS_OPENGL_GLUT
222 ri.
vp_x = win_dims[0];
223 ri.
vp_y = win_dims[1];
230 ri.
proj_matrix = Eigen::Matrix<float, 4, 4, Eigen::ColMajor>(mat_proj);
233 Eigen::Matrix<float, 4, 1> cam_pose_hm = ri.
proj_matrix.inverse().col(3);
234 if (cam_pose_hm[3] != 0)
246 ri.
model_matrix = Eigen::Matrix<float, 4, 4, Eigen::ColMajor>(mat_mod);
260 #if MRPT_HAS_OPENGL_GLUT
261 while (*str) glutBitmapCharacter(fontStyle, *(str++));
270 #if MRPT_HAS_OPENGL_GLUT
275 return GLUT_BITMAP_TIMES_ROMAN_10;
278 return GLUT_BITMAP_TIMES_ROMAN_24;
282 return GLUT_BITMAP_HELVETICA_10;
285 return GLUT_BITMAP_HELVETICA_12;
288 return GLUT_BITMAP_HELVETICA_18;
304 #if MRPT_HAS_OPENGL_GLUT
305 if (str.empty())
return 0;
306 return glutBitmapLength(
319 int screen_x,
int screen_y,
const std::string& str,
float color_r,
322 #if MRPT_HAS_OPENGL_GLUT
326 if (screen_x < 0 || screen_y < 0)
332 if (screen_x < 0) screen_x += win_dims[2];
333 if (screen_y < 0) screen_y += win_dims[3];
354 glViewport((
int)screen_x - 1, (
int)screen_y - 1, 2, 2);
357 fx = screen_x - (int)screen_x;
358 fy = screen_y - (int)screen_y;
372 for (
size_t i = 0; i < str.size(); i++)
373 glutBitmapCharacter(glut_font_sel, str[i]);
388 const float msg_x,
const float msg_y,
const float msg_w,
const float msg_h,
393 const double text_spacing,
const double text_kerning)
395 #if MRPT_HAS_OPENGL_GLUT
396 const int nLines = 1 +
std::count(text.begin(), text.end(),
'\n');
400 const int w = win_dims[2];
401 const int h = win_dims[3];
404 const float vw_w =
w / float(min_wh);
405 const float vw_h = h / float(min_wh);
411 glOrtho(0, vw_w, 0, vw_h, -1, 1);
423 const float msg_x0 = vw_w * msg_x;
424 const float msg_y0 = vw_h * msg_y;
426 const float msg_x1 = vw_w * (msg_x + msg_w);
427 const float msg_y1 = vw_h * (msg_y + msg_h);
429 const float msg_real_w = msg_x1 - msg_x0;
430 const float msg_real_h = msg_y1 - msg_y0;
432 const float msg_cx = .5 * (msg_x0 + msg_x1);
433 const float msg_cy = .5 * (msg_y0 + msg_y1);
445 glColor4ub(border_col.
R, border_col.
G, border_col.
B, border_col.
A);
462 if (txtSize.
x > msg_real_w)
464 const float K = 0.99f * msg_real_w / txtSize.
x;
469 if (txtSize.
y > msg_real_h)
471 const float K = 0.99f * msg_real_h / txtSize.
y;
477 const float text_w = txtSize.
x;
479 (nLines > 1 ? -(nLines - 1) * txtSize.
y /
float(nLines) : txtSize.
y);
480 const float text_x0 = msg_cx - .5f * text_w;
481 const float text_y0 = msg_cy - .5f * text_h;
486 text, text_scale, text_style, text_spacing, text_kerning);
516 #if MRPT_HAS_OPENGL_GLUT
525 #if MRPT_HAS_OPENGL_GLUT
536 #if MRPT_HAS_OPENGL_GLUT
539 glScaled(textScale, textScale, textScale);
540 auto ret =
CVD::glDrawText(text,
static_cast<CVD::TEXT_STYLE
>(style), spacing, kerning);
554 const std::string& text,
const double textScale,
double spacing,
557 #if MRPT_HAS_OPENGL_GLUT
Lightweight 3D point (float version).
TOpenGLFont
Existing fonts for 2D texts in mrpt::opengl methods.
A pair (x,y) of pixel coordinates (subpixel resolution).
GLAPI void GLAPIENTRY glBegin(GLenum mode)
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
const Scalar * const_iterator
GLAPI void GLAPIENTRY glGetFloatv(GLenum pname, GLfloat *params)
GLAPI void GLAPIENTRY glPopMatrix(void)
TOpenGLFontStyle
Different style for vectorized font rendering.
GLAPI void GLAPIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
#define GL_PROJECTION_MATRIX
double getColorG() const
Color components in the range [0,1].
void renderTextBitmap(const char *str, void *fontStyle)
This method is safe for calling from within ::render() methods.
The base class of 3D objects that can be directly rendered through OpenGL.
int vp_x
Rendering viewport geometry (in pixels)
const std::string & glGetFont()
returns the name of the currently active font
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.
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
float getScaleX() const
Get the current scaling factor in one axis.
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.
@ MRPT_GLUT_BITMAP_HELVETICA_10
void * aux_mrptfont2glutfont(const TOpenGLFont font)
void glSetFont(const std::string &fontname)
sets the font to use for future font rendering commands.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
bool isShowNameEnabled() const
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...
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
double getColorA() const
Color components in the range [0,1].
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLubyte GLubyte GLubyte GLubyte w
float getScaleZ() const
Get the current scaling factor in one axis.
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
#define THROW_EXCEPTION(msg)
Information about the rendering process being issued.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
@ MRPT_GLUT_BITMAP_HELVETICA_12
GLAPI void GLAPIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue)
double getColorB() const
Color components in the range [0,1].
GLAPI void GLAPIENTRY glPushMatrix(void)
GLAPI void GLAPIENTRY glVertex2f(GLfloat x, GLfloat y)
void renderSetOfObjects(const mrpt::opengl::CListOpenGLObjects &objs)
For each object in the list:
GLAPI void GLAPIENTRY glScaled(GLdouble x, GLdouble y, GLdouble z)
@ MRPT_GLUT_BITMAP_HELVETICA_18
GLAPI void GLAPIENTRY glEnd(void)
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...
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
GLuint GLuint GLsizei count
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
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.
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > model_matrix
The 4x4 model transformation matrix.
#define GL_ONE_MINUS_SRC_ALPHA
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
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...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > full_matrix
PROJ * MODEL.
double x
X,Y,Z coordinates.
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().
#define GL_CURRENT_RASTER_POSITION
virtual void render() const =0
Implements the rendering of 3D objects in each class derived from CRenderizable.
GLAPI void GLAPIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
const std::string & getName() const
Returns the name of the object.
GLAPI void GLAPIENTRY glGetIntegerv(GLenum pname, GLint *params)
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
GLAPI void GLAPIENTRY glLoadIdentity(void)
Eigen::Matrix< float, 4, 4, Eigen::ColMajor > proj_matrix
The 4x4 projection matrix.
@ MRPT_GLUT_BITMAP_TIMES_ROMAN_10
void getCurrentRenderingInfo(TRenderInfo &ri)
Gather useful information on the render parameters.
mrpt::math::TPoint3Df camera_position
The 3D location of the camera.
#define GL_MODELVIEW_MATRIX
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
GLAPI void GLAPIENTRY glPopAttrib(void)
std::deque< CRenderizable::Ptr > CListOpenGLObjects
A list of objects pointers, automatically managing memory free at destructor, and managing copies cor...
This base provides a set of functions for maths stuff.
double getColorR() const
Color components in the range [0,1].
GLsizei const GLchar ** string
The namespace for 3D scene representation and rendering.
bool isVisible() const
Is the object visible?
@ MRPT_GLUT_BITMAP_TIMES_ROMAN_24
GLAPI void GLAPIENTRY glMultMatrixd(const GLdouble *m)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
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 ...
#define MRPT_PROFILE_FUNC_START
GLAPI GLenum GLAPIENTRY glGetError(void)
mrpt::math::CArrayDouble< 3 > m_coords
The translation vector [x,y,z] access directly or with x(), y(), z() setter/getter methods.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |