Sitelet https://github.com/sofa-framework/SofaGLFW/pull/298
Skip to content

[GLFW] add Offscreen rendering - #298

Open
fredroy wants to merge 5 commits into
sofa-framework:masterfrom
fredroy:offscreen_rendering
Open

fredroy wants to merge 5 commits into
sofa-framework:masterfrom
fredroy:offscreen_rendering

Conversation

@fredroy

@fredroy fredroy commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Based on

Add a new feature to render without opening any window.
Only usable with glfw GUI (as the imgui is by definition interactive in my opinion)

add 2 flags:

  • --offscreen (to set offcreen)
  • -n/--nbIter like Batch for the number of frames

Note that you still need opengl/context/ whatever stuff like that of course

Comment thread exe/Main.cpp
msg_info("SofaGLFW") << "Batch mode: computing " << targetNbIterations << " iterations.";
startAnim = true;
}
else if (isOffscreen)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might never fall into this case since nb_iterations is cast as std::size_t

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? 🤔

If I nb_iterations is '0' (not set or given as argument),
auto targetNbIterations = result["nb_iterations"].as<std::size_t>(); will make targetNbIterations == 0 therefore going into the else.

And it works, at least on my setup at least:

./bin/runSofaGLFW --offscreen
....
[WARNING] [InteractiveCamera(InteractiveCamera1)] Too many missing parameters ; taking default ...
[WARNING] [SofaGLFW] Offscreen mode without a number of iterations (--nb_iterations): the simulation will run until the process is interrupted.

/// than once is a no-op.
static int RegisterGUIParameters(sofa::gui::common::ArgumentParser* argumentParser);

/// Number of iterations requested with the '-n'/'--nbIter' argument of the batch GUI;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could actually not trigger infinite iterations with -n=0 option, could you?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you have to write -n 0, not -n=0
like batch actually

Render without showing anything on screen, while still calling all the
graphics functions: the window and its OpenGL context are created as
usual, they are simply never mapped on screen (GLFW_VISIBLE hint).

Available as '--offscreen' in runSofaGLFW, and in runSofa with the glfw
and imgui GUIs. SofaGLFWGUI::RegisterGUIParameters() declares it for both
of them: GUIManager declares the parameters of every registered GUI, so
the function guards against a second registration.

Fullscreen is ignored in offscreen mode, and switchFullScreen() (F11) is
refused, since it would map the window.
'-n'/'--nbIter' only stopped the batch GUI; with glfw or imgui the
simulation ran until the window was closed, which made it impossible to
run a bounded simulation while still rendering, e.g. together with
'--offscreen'.

The argument is registered by the batch GUI, and cxxopts refuses a
duplicate, so it is not declared a second time: SofaGLFWGUI keeps the
ArgumentParser given to RegisterGUIParameters and reads the already
parsed value in mainLoop(). Only arguments actually present on the
command line end up in the parse result, hence the simulation keeps
running indefinitely when '-n' is not given. 'infinite' is supported as
in the batch GUI.
The imgui GUI is the glfw one plus interactive widgets, so rendering it
without ever showing the window serves no purpose.
@fredroy
fredroy force-pushed the offscreen_rendering branch from e91f315 to 05d0f75 Compare October 5, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants