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);
158 #if MRPT_HAS_OPENCV && MRPT_HAS_OPENGL_GLUT 187 #if MRPT_HAS_OPENGL_GLUT 197 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_fbo);
215 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
229 #if MRPT_HAS_OPENCV && MRPT_HAS_OPENGL_GLUT 238 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_fbo);
244 const GLenum texTarget =
245 #if defined(GL_TEXTURE_RECTANGLE_NV) 246 GL_TEXTURE_RECTANGLE_NV;
247 #elif defined(GL_TEXTURE_RECTANGLE_ARB) 248 GL_TEXTURE_RECTANGLE_ARB;
250 GL_TEXTURE_RECTANGLE_EXT;
253 glBindTexture(texTarget,
m_tex);
261 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
278 #if MRPT_HAS_OPENGL_GLUT 283 auto where = strchr(extension,
' ');
284 if (where || *extension ==
'\0')
return 0;
285 const auto extensions = glGetString(GL_EXTENSIONS);
290 auto start =
reinterpret_cast<const char*
>(extensions);
293 where = strstr(start, extension);
295 auto terminator = where + strlen(extension);
296 if (where == start || *(where - 1) ==
' ')
297 if (*terminator ==
' ' || *terminator ==
'\0')
return 1;
int isExtensionSupported(const char *extension)
Provide information on Framebuffer object extension.
#define THROW_EXCEPTION(msg)
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
size_t getHeight() const override
Returns the height of the image in pixels.
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.
size_t getWidth() const override
Returns the width of the image in pixels.
void resize(std::size_t width, std::size_t height, TImageChannels nChannels, PixelDepth depth=PixelDepth::D8U)
Changes the size of the image, erasing previous contents (does NOT scale its current content...
#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.
bool isOriginTopLeft() const
Returns true (as of MRPT v2.0.0, it's fixed)
void resize(unsigned int width, unsigned int height)
Resize the rendering canvas size.
void render() const
Render this scene.
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.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.