11
$\begingroup$

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

$\endgroup$
14
$\begingroup$

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_*.

$\endgroup$
  • $\begingroup$ Thanks! this works. (though it is a little awkward with ui popping up..) Is there a way to get it to render with antialiasing? $\endgroup$ – gandalf3 Aug 26 '13 at 1:46
  • 2
    $\begingroup$ @gandalf3: Ensure 3D View is set to camera view before saving, and change 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$ – Adhi Aug 26 '13 at 2:45
  • 2
    $\begingroup$ The reason you get the default Scene without load_post, is due to you calling the script before loading the file. Changing the order of the arguments, works as expected. $\endgroup$ – Aldrik Aug 26 '13 at 14:36
  • $\begingroup$ @Aldrik: Cool! I haven't noticed that one. $\endgroup$ – Adhi Aug 26 '13 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.