23 CFBORender::CFBORender(
24 unsigned int width,
unsigned int height,
const bool skip_glut_window)
27 m_win_used(!skip_glut_window),
28 m_default_bk_color(.6f, .6f, .6f, 1)
30 #if MRPT_HAS_OPENCV && MRPT_HAS_OPENGL_GLUT 37 if (!glutGet(GLUT_INIT_STATE))
41 char*
argv[1] = {
nullptr};
46 m_win = glutCreateWindow(
"CFBORender");
56 glGenFramebuffersEXT =
57 (PFNGLGENFRAMEBUFFERSEXTPROC)wglGetProcAddress(
"glGenFramebuffersEXT");
58 glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)wglGetProcAddress(
59 "glDeleteFramebuffersEXT");
60 glBindFramebufferEXT =
61 (PFNGLBINDFRAMEBUFFEREXTPROC)wglGetProcAddress(
"glBindFramebufferEXT");
62 glFramebufferTexture2DEXT =
63 (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)wglGetProcAddress(
64 "glFramebufferTexture2DEXT");
66 ASSERT_(glGenFramebuffersEXT !=
nullptr);
67 ASSERT_(glDeleteFramebuffersEXT !=
nullptr);
68 ASSERT_(glBindFramebufferEXT !=
nullptr);
69 ASSERT_(glFramebufferTexture2DEXT !=
nullptr);
73 glGenFramebuffersEXT(1, &
m_fbo);
76 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_fbo);
82 glGenTextures(1, &
m_tex);
85 const GLenum texTarget =
86 #if defined(GL_TEXTURE_RECTANGLE_NV) 87 GL_TEXTURE_RECTANGLE_NV;
88 #elif defined(GL_TEXTURE_RECTANGLE_ARB) 89 GL_TEXTURE_RECTANGLE_ARB;
91 GL_TEXTURE_RECTANGLE_EXT;
94 glBindTexture(texTarget,
m_tex);
100 glFramebufferTexture2DEXT(
101 GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, texTarget,
m_tex, 0);
106 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
120 #if MRPT_HAS_OPENGL_GLUT 122 glDeleteTextures(1, &
m_tex);
123 glDeleteFramebuffersEXT(1, &
m_fbo);
159 #if MRPT_HAS_OPENCV && MRPT_HAS_OPENGL_GLUT 164 if (buffer.getWidth() !=
static_cast<size_t>(
m_width) ||
165 buffer.getHeight() !=
static_cast<size_t>(
m_height) ||
166 buffer.getChannelCount() != 3 || buffer.isOriginTopLeft() !=
false)
186 #if MRPT_HAS_OPENGL_GLUT 196 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_fbo);
214 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
224 [[maybe_unused]]
unsigned int width, [[maybe_unused]]
unsigned int height)
226 #if MRPT_HAS_OPENCV && MRPT_HAS_OPENGL_GLUT 235 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_fbo);
241 const GLenum texTarget =
242 #if defined(GL_TEXTURE_RECTANGLE_NV) 243 GL_TEXTURE_RECTANGLE_NV;
244 #elif defined(GL_TEXTURE_RECTANGLE_ARB) 245 GL_TEXTURE_RECTANGLE_ARB;
247 GL_TEXTURE_RECTANGLE_EXT;
250 glBindTexture(texTarget,
m_tex);
258 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
272 #if MRPT_HAS_OPENGL_GLUT 277 auto where = strchr(extension,
' ');
278 if (where || *extension ==
'\0')
return 0;
279 const auto extensions = glGetString(GL_EXTENSIONS);
284 auto start =
reinterpret_cast<const char*
>(extensions);
287 where = strstr(start, extension);
289 auto terminator = where + strlen(extension);
290 if (where == start || *(where - 1) ==
' ')
291 if (*terminator ==
' ' || *terminator ==
'\0')
return 1;
int isExtensionSupported(const char *extension)
Provide information on Framebuffer object extension.
#define THROW_EXCEPTION(msg)
void getFrame(const COpenGLScene &scene, mrpt::img::CImage &image)
Render the scene and get the rendered rgb image.
#define ASSERT_(f)
Defines an assertion mechanism.
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
CCamera & getCamera(const COpenGLScene &scene)
Get a reference to the scene camera.
virtual ~CFBORender()
Destructor.
void getFrame2(const COpenGLScene &scene, mrpt::img::CImage &image)
Render the scene and get the rendered rgb image.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
COpenGLViewport::Ptr getViewport(const std::string &viewportName=std::string("main")) const
Returns the viewport with the given name, or nullptr if it does not exist; note that the default view...
void setCamera(const COpenGLScene &scene, const CCamera &camera)
Change the scene camera.
void resize(unsigned int width, unsigned int height)
Resize the rendering canvas size.
The namespace for 3D scene representation and rendering.
This class allows the user to create, load, save, and render 3D scenes using OpenGL primitives...
mrpt::img::TColorf m_default_bk_color
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
A class for storing images as grayscale or RGB bitmaps.