Is it possible to use the openGL quick render for rendering from the command line?
e.g. something like blender -b <file> -E opengl -f 1
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityIs it possible to use the openGL quick render for rendering from the command line?
e.g. something like blender -b <file> -E opengl -f 1
It is possible, in a round-about way. Operator render.opengl()
needs OpenGL display context, i.e. Blender's window, to be opened. Hence, we can't do UI-less rendering using -b
command switch. We'll need to do it through a script:
import bpy
import sys # read argument from sys.argv
from bpy.app.handlers import persistent
@persistent
def do_render_opengl(dummy):
bpy.ops.render.opengl(animation=True, view_context=False)
bpy.ops.wm.quit_blender()
bpy.app.handlers.load_post.append(do_render_opengl)
It is to be executed like this:
blender -P render_opengl.py <file>.blend
Executing wm.quit_blender()
is necessary, because otherwise Blender doesn't automatically close when render finishes. We also wrap the rendering code in load_post
handler, to make sure the right context is loaded up before rendering. This is especially important if the scene's name is non-default. Otherwise Blender creates new scene Scene
and renders it, instead of the scene we want.
The script above is to render preview animation. To render preview image and specify frame range, modify it to read argument from sys.argv
(I've written code that does it before) and assigning appropriate values to bpy.context.scene.frame_*
.
view_context
in the script to True
. I set it to False
so it renders through active camera, irrespective of view settings, but it doesn't play well with antialiasing.
$\endgroup$
load_post
, is due to you calling the script before loading the file. Changing the order of the arguments, works as expected.
$\endgroup$