Opengl_functions and opengl_renderer with embedded liboctinterp

Hi, I’m developing a C++ application that embeds octave using liboctinterp.

In my application I have defined and registered a new graphics_toolkit, which does some rendering on a GLFW (simple OpenGL library) hidden window (the idea is not depending on Qt).

The rendering happens on the redraw_figure method of the graphics_toolkit, whose code is something like this:

void toolkit::redraw_figure(const graphics_object& go) const {
	figure::properties& figureProperties = dynamic_cast<figure::properties&>(graphics_object(go).get_properties());
	Matrix figurePosition = figureProperties.get_position().matrix_value();

	double dpr = figureProperties.get___device_pixel_ratio__();

	int width = figurePosition(2) * dpr;
	int height = figurePosition(3) * dpr;

	octave::opengl_functions m_glfcns;
	octave::opengl_renderer m_renderer(m_glfcns);

	auto window = glfwCreateWindow(width, height, "", NULL, NULL);
	glfwMakeContextCurrent(window);

	m_renderer.set_viewport(width, height);
	m_renderer.set_device_pixel_ratio(dpr);

	m_renderer.draw(go);

	unsigned char* screen = new unsigned char[width * height * 3];
	glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, screen);

// More stuff happening

	delete[] screen;

	glfwDestroyWindow(window);
}

The main issue with this code is that the public API for liboctinterp does not provide the oct-opengl.h file, which defines the octave::opengl_functions class required by opengl_renderer. The only thing I could do was copying that file in my source tree.

This is however not really portable, and I think it might have broken my binaries a few times on octave updates, forcing me to rebuild them.

My question is, would it be possible to export that class in the public headers? Or at least add a default constructor (with no params) to opengl_renderer that instanciates that class on its own? (given that opengl functions seem to be the same default ones in most environments, from what I understood)

Thank you in advance for your help!

Thanks for this detailed request :slightly_smiling_face:

This topic seems more suited for the maintainers section.

My suspicion is that your use case of providing a custom graphics_toolkit has not been regarded so far and the header was not made public for that reason.

Are there opinions against making it public?

I understand that you don’t want to depend on Qt, which is a huge library, but what about FLTK?

Hi and thank you for the fast response!

Well I could, however (sorry for not being clear) the main point with my request is not really avoiding Qt (still important), but instead the possibility to use a opengl_renderer inside my custom graphic toolkit.

In fact, apart from rendering the figure I need this toolkit to perform some additional actions, which are, extracting the pixel data, compressing it and sending through a dedicated communication channel to a visualizer. I don’t think all these things could be done as seamlessly if I used an existing toolkit (e.g. FLTK).

Furthermore, as my application is headless, GLFW is only needed to have a cross-platform way to obtain a OpenGL context, otherwise I’d have avoided it as well :slight_smile:, I don’t really need any “GUI” capability.

There is however a similar use case (even though not using a custom graphics toolkit) for the opengl_renderer class, which is GitHub - gnu-octave/octave-gl-print: Offscreen rendering print using OSMesa and gl2ps.

I’m not sure this would still work or even build, however, because I believe it was written before the introduction of the opengl_functions class, and the opengl_renderer is initialized without any parameters.