MRPT  1.9.9
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
mrpt::opengl::CFBORender Class Reference

Detailed Description

A class for rendering 3D scenes off-screen directly into an image using OpenGL extensions (glext).

To define a background color, set it in the scene's "main" viewport.

You can add overlaid text messages, see base class CTextMessageCapable

See also
Example "fbo_render_test"

Definition at line 27 of file CFBORender.h.

#include <mrpt/opengl/CFBORender.h>

Inheritance diagram for mrpt::opengl::CFBORender:

Public Member Functions

 CFBORender (unsigned int width=800, unsigned int height=600, const bool skip_glut_window=false)
 Constructor. More...
 
virtual ~CFBORender ()
 Destructor. More...
 
void setCamera (const COpenGLScene &scene, const CCamera &camera)
 Change the scene camera. More...
 
CCameragetCamera (const COpenGLScene &scene)
 Get a reference to the scene camera. More...
 
void getFrame (const COpenGLScene &scene, mrpt::img::CImage &image)
 Render the scene and get the rendered rgb image. More...
 
void getFrame2 (const COpenGLScene &scene, mrpt::img::CImage &image)
 Render the scene and get the rendered rgb image. More...
 
void resize (unsigned int width, unsigned int height)
 Resize the rendering canvas size. More...
 
const mrpt::img::TColorfgetBackgroundColor () const
 Get the default background color (unles an COpenGLViewport defines a custom color) More...
 
void setBackgroundColor (const mrpt::img::TColorf &col)
 Set the default background color (unles an COpenGLViewport defines a custom color) More...
 
void clearTextMessages ()
 
void addTextMessage (const double x_frac, const double y_frac, const std::string &text, const mrpt::img::TColorf &color=mrpt::img::TColorf(1.0, 1.0, 1.0), const size_t unique_index=0, const mrpt::opengl::TOpenGLFont font=mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24)
 Add 2D text messages overlapped to the 3D rendered scene. More...
 
void addTextMessage (const double x_frac, const double y_frac, const std::string &text, const mrpt::img::TColorf &color, const std::string &font_name, const double font_size, const mrpt::opengl::TOpenGLFontStyle font_style=mrpt::opengl::NICE, const size_t unique_index=0, const double font_spacing=1.5, const double font_kerning=0.1, const bool has_shadow=false, const mrpt::img::TColorf &shadow_color=mrpt::img::TColorf(0, 0, 0))
 overload with more font parameters - refer to mrpt::opengl::gl_utils::glDrawText() More...
 
bool updateTextMessage (const size_t unique_index, const std::string &text)
 Just updates the text of a given text message, without touching the other parameters. More...
 

Protected Member Functions

int isExtensionSupported (const char *extension)
 Provide information on Framebuffer object extension. More...
 
void render_text_messages (const int w, const int h) const
 Renders the messages to the current opengl rendering context (to be called OUT of MRPT mrpt::opengl render() methods ). More...
 

Protected Attributes

int m_win
 
int m_width
 
int m_height
 
unsigned int m_fbo {0}
 
unsigned int m_tex {0}
 
bool m_win_used
 
mrpt::img::TColorf m_default_bk_color
 
std::map< size_t, mrpt::opengl::T2DTextDatam_2D_texts
 

Constructor & Destructor Documentation

◆ CFBORender()

CFBORender::CFBORender ( unsigned int  width = 800,
unsigned int  height = 600,
const bool  skip_glut_window = false 
)

Constructor.

Parameters
[in]skip_glut_windowShould be set to true only if another GUI windows already exist with an associated OpenGL context. If left to false, a hidden GLUT window will be created.

Definition at line 23 of file CFBORender.cpp.

References argc, argv, ASSERT_, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_EXT, GL_RGB, GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_RECTANGLE_NV, GL_UNSIGNED_BYTE, glBindFramebufferEXT, glBindTexture(), glDeleteFramebuffersEXT, glFramebufferTexture2DEXT, glGenFramebuffersEXT, glGenTextures(), glTexImage2D(), glViewport(), isExtensionSupported(), m_fbo, m_height, m_tex, m_width, m_win, m_win_used, MRPT_END, MRPT_START, and THROW_EXCEPTION.

Here is the call graph for this function:

◆ ~CFBORender()

CFBORender::~CFBORender ( )
virtual

Destructor.

Definition at line 118 of file CFBORender.cpp.

References glDeleteFramebuffersEXT, glDeleteTextures(), m_fbo, m_tex, m_win, and m_win_used.

Here is the call graph for this function:

Member Function Documentation

◆ addTextMessage() [1/2]

void CTextMessageCapable::addTextMessage ( const double  x_frac,
const double  y_frac,
const std::string text,
const mrpt::img::TColorf color = mrpt::img::TColorf(1.0, 1.0, 1.0),
const size_t  unique_index = 0,
const mrpt::opengl::TOpenGLFont  font = mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24 
)
inherited

Add 2D text messages overlapped to the 3D rendered scene.

The string will remain displayed in the 3D window until it's changed with subsequent calls to this same method, or all the texts are cleared with clearTextMessages().

Parameters
xThe X position, interpreted as absolute pixels from the left if X>=1, absolute pixels from the left if X<0 or as a width factor if in the range [0,1[.
yThe Y position, interpreted as absolute pixels from the bottom if Y>=1, absolute pixels from the top if Y<0 or as a height factor if in the range [0,1[.
textThe text string to display.
colorThe text color. For example: TColorf(1.0,1.0,1.0)
unique_indexAn "index" for this text message, so that subsequent calls with the same index will overwrite this text message instead of creating new ones.

You'll need to refresh the display manually with forceRepaint().

See also
clearTextMessages

Definition at line 150 of file CTextMessageCapable.cpp.

References mrpt::opengl::TFontParams::color, mrpt::opengl::TFontParams::font, mrpt::opengl::T2DTextData::text, mrpt::opengl::T2DTextData::x, and mrpt::opengl::T2DTextData::y.

◆ addTextMessage() [2/2]

void CTextMessageCapable::addTextMessage ( const double  x_frac,
const double  y_frac,
const std::string text,
const mrpt::img::TColorf color,
const std::string font_name,
const double  font_size,
const mrpt::opengl::TOpenGLFontStyle  font_style = mrpt::opengl::NICE,
const size_t  unique_index = 0,
const double  font_spacing = 1.5,
const double  font_kerning = 0.1,
const bool  has_shadow = false,
const mrpt::img::TColorf shadow_color = mrpt::img::TColorf(0, 0, 0) 
)
inherited

◆ clearTextMessages()

void CTextMessageCapable::clearTextMessages ( )
inherited

Definition at line 149 of file CTextMessageCapable.cpp.

◆ getBackgroundColor()

const mrpt::img::TColorf& mrpt::opengl::CFBORender::getBackgroundColor ( ) const
inline

Get the default background color (unles an COpenGLViewport defines a custom color)

Definition at line 67 of file CFBORender.h.

References m_default_bk_color.

◆ getCamera()

CCamera & CFBORender::getCamera ( const COpenGLScene scene)

Get a reference to the scene camera.

Definition at line 143 of file CFBORender.cpp.

References mrpt::opengl::COpenGLScene::getViewport(), MRPT_END, and MRPT_START.

Here is the call graph for this function:

◆ getFrame()

void CFBORender::getFrame ( const COpenGLScene scene,
mrpt::img::CImage image 
)

Render the scene and get the rendered rgb image.

Resizes the image buffer if it is necessary.

Definition at line 156 of file CFBORender.cpp.

References mrpt::img::CH_RGB, getFrame2(), m_height, m_width, MRPT_END, MRPT_START, and MRPT_UNUSED_PARAM.

Here is the call graph for this function:

◆ getFrame2()

void CFBORender::getFrame2 ( const COpenGLScene scene,
mrpt::img::CImage image 
)

Render the scene and get the rendered rgb image.

Does not resize the image buffer. MANDATORY: The image origin must be bottom left.

Definition at line 185 of file CFBORender.cpp.

References mrpt::img::TColorf::A, ASSERT_EQUAL_, mrpt::img::TColorf::B, mrpt::img::TColorf::G, GL_BGR_EXT, GL_FRAMEBUFFER_EXT, GL_UNSIGNED_BYTE, glBindFramebufferEXT, glClearColor(), glReadPixels(), m_default_bk_color, m_fbo, m_height, m_width, MRPT_END, MRPT_START, MRPT_UNUSED_PARAM, mrpt::img::TColorf::R, mrpt::opengl::COpenGLScene::render(), and mrpt::opengl::CTextMessageCapable::render_text_messages().

Referenced by getFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isExtensionSupported()

int CFBORender::isExtensionSupported ( const char *  extension)
protected

Provide information on Framebuffer object extension.

Definition at line 280 of file CFBORender.cpp.

References GL_EXTENSIONS, glGetString(), MRPT_END, MRPT_START, and MRPT_UNUSED_PARAM.

Referenced by CFBORender().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_text_messages()

void CTextMessageCapable::render_text_messages ( const int  w,
const int  h 
) const
protectedinherited

Renders the messages to the current opengl rendering context (to be called OUT of MRPT mrpt::opengl render() methods ).

(w,h) are the dimensions of the rendering area in pixels.

Definition at line 25 of file CTextMessageCapable.cpp.

References mrpt::opengl::FILL, GL_DEPTH_TEST, GL_MATRIX_MODE, GL_MODELVIEW, GL_PROJECTION, glColor3f(), glDisable(), mrpt::opengl::gl_utils::glDrawText(), glEnable(), glGetIntegerv(), glLoadIdentity(), glMatrixMode(), glOrtho(), glPopMatrix(), glPushMatrix(), mrpt::opengl::gl_utils::glSetFont(), glTranslatef(), mrpt::opengl::MRPT_GLUT_BITMAP_HELVETICA_10, mrpt::opengl::MRPT_GLUT_BITMAP_HELVETICA_12, mrpt::opengl::MRPT_GLUT_BITMAP_HELVETICA_18, mrpt::opengl::MRPT_GLUT_BITMAP_NONE, mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_10, mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24, and MRPT_UNUSED_PARAM.

Referenced by getFrame2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize()

void CFBORender::resize ( unsigned int  width,
unsigned int  height 
)

Resize the rendering canvas size.

Definition at line 231 of file CFBORender.cpp.

References GL_FRAMEBUFFER_EXT, GL_RGB, GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_RECTANGLE_NV, GL_UNSIGNED_BYTE, glBindFramebufferEXT, glBindTexture(), glTexImage2D(), glViewport(), m_fbo, m_height, m_tex, m_width, MRPT_END, MRPT_START, and MRPT_UNUSED_PARAM.

Here is the call graph for this function:

◆ setBackgroundColor()

void mrpt::opengl::CFBORender::setBackgroundColor ( const mrpt::img::TColorf col)
inline

Set the default background color (unles an COpenGLViewport defines a custom color)

Definition at line 74 of file CFBORender.h.

References m_default_bk_color.

◆ setCamera()

void CFBORender::setCamera ( const COpenGLScene scene,
const CCamera camera 
)

Change the scene camera.

Definition at line 131 of file CFBORender.cpp.

References mrpt::opengl::COpenGLScene::getViewport(), MRPT_END, and MRPT_START.

Here is the call graph for this function:

◆ updateTextMessage()

bool CTextMessageCapable::updateTextMessage ( const size_t  unique_index,
const std::string text 
)
inherited

Just updates the text of a given text message, without touching the other parameters.

Returns
false if given ID doesn't exist.

Definition at line 169 of file CTextMessageCapable.cpp.

References mrpt::opengl::T2DTextData::text.

Member Data Documentation

◆ m_2D_texts

std::map<size_t, mrpt::opengl::T2DTextData> mrpt::opengl::CTextMessageCapable::m_2D_texts
protectedinherited

Definition at line 24 of file CTextMessageCapable.h.

◆ m_default_bk_color

mrpt::img::TColorf mrpt::opengl::CFBORender::m_default_bk_color
protected

Definition at line 83 of file CFBORender.h.

Referenced by getBackgroundColor(), getFrame2(), and setBackgroundColor().

◆ m_fbo

unsigned int mrpt::opengl::CFBORender::m_fbo {0}
protected

Definition at line 81 of file CFBORender.h.

Referenced by CFBORender(), getFrame2(), resize(), and ~CFBORender().

◆ m_height

int mrpt::opengl::CFBORender::m_height
protected

Definition at line 80 of file CFBORender.h.

Referenced by CFBORender(), getFrame(), getFrame2(), and resize().

◆ m_tex

unsigned int mrpt::opengl::CFBORender::m_tex {0}
protected

Definition at line 81 of file CFBORender.h.

Referenced by CFBORender(), resize(), and ~CFBORender().

◆ m_width

int mrpt::opengl::CFBORender::m_width
protected

Definition at line 80 of file CFBORender.h.

Referenced by CFBORender(), getFrame(), getFrame2(), and resize().

◆ m_win

int mrpt::opengl::CFBORender::m_win
protected

Definition at line 80 of file CFBORender.h.

Referenced by CFBORender(), and ~CFBORender().

◆ m_win_used

bool mrpt::opengl::CFBORender::m_win_used
protected

Definition at line 82 of file CFBORender.h.

Referenced by CFBORender(), and ~CFBORender().




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 479715d5b Tue Nov 12 07:26:21 2019 +0100 at mar nov 12 07:30:12 CET 2019