Run opengl render in background
No, you can't use OpenGL in the background. You shouldn't use the -b flag, and instead, close Blender in the end of your script using bpy.ops.wm.quit_blender().
Blender creates screenshot using python script but not when running in background
Render with openGL from the command line?