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


1 Answer 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

def do_render_opengl(dummy):
    bpy.ops.render.opengl(animation=True, view_context=False)


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

  • $\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, 2013 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, 2013 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, 2013 at 14:36
  • $\begingroup$ @Aldrik: Cool! I haven't noticed that one. $\endgroup$
    – Adhi
    Aug 26, 2013 at 16:45
  • $\begingroup$ @Adhi I'm getting some context error using your method when running bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM') or bpy.context.workspace.screens[0].areas Any idea how to fix that? $\endgroup$
    – June Wang
    May 15, 2021 at 10:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .