You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pyglet supports offscreen rendering through EGL, but PyGame does not.
The combination of RenderFramework.PYGAME and RenderMode.HEADLESS thus currently not work.
For the future, we should fallback to LLVMpipe and OSMesa for this case.
importosimportnumpyasnpfromPILimportImagefromOpenGL.GLimport*fromOpenGL.GLUTimport*fromOpenGL.raw.osmesaimportmesaasosmesa# Use LLVMpipe for renderingos.environ['LIBGL_ALWAYS_SOFTWARE'] ='1'os.environ['GALLIUM_DRIVER'] ='llvmpipe'# create a contextctx=osmesa.OSMesaCreateContextExt(osmesa.OSMESA_RGBA, 32, 0, 0, None)
ifnotctx:
print('Could not create OSMesa context')
exit(1)
# create a framebufferwidth, height=640, 480buffer=np.zeros([height, width, 4], dtype=np.uint8)
# make the context currentifnotosmesa.OSMesaMakeCurrent(ctx, buffer, GL_UNSIGNED_BYTE, width, height):
print('Could not make the OSMesa context current')
exit(1)
# setup viewportglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(-1, 1, -1, 1, -1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
# render a red triangleglBegin(GL_TRIANGLES)
glColor3f(1, 0, 0) # Red colorglVertex2f(-0.5, -0.5)
glVertex2f(0.5, -0.5)
glVertex2f(0, 0.5)
glEnd()
# unbind the context before deletionosmesa.OSMesaMakeCurrent(None, None, GL_UNSIGNED_BYTE, 0, 0)
# clean uposmesa.OSMesaDestroyContext(ctx)
# flip the buffer vertically (origin is different in OSMesa and PIL)buffer=np.flipud(buffer)
# convert the buffer to an image and save itimg=Image.fromarray(buffer, 'RGBA')
img.save('output.png')
The text was updated successfully, but these errors were encountered:
For systems with the Nvidia GPUs and their proprietary driver: make sure to set __GLX_VENDOR_LIBRARY_NAME=mesa
Example to test if LLVMpipe is available (output should be OpenGL renderer string: llvmpipe ...): __GLX_VENDOR_LIBRARY_NAME=mesa LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=llvmpipe glxinfo | grep "OpenGL renderer"
Command to run glxgears (apt install mesa-utils) with LLVMpipe: __GLX_VENDOR_LIBRARY_NAME=mesa LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=llvmpipe glxgears
Since Gymnasium uses pygame, I took a look, and they use Surface instead of display, when the render_mode is set to rgb_array. Maybe that fixes the issue?
Pyglet supports offscreen rendering through EGL, but PyGame does not.
The combination of RenderFramework.PYGAME and RenderMode.HEADLESS thus currently not work.
For the future, we should fallback to LLVMpipe and OSMesa for this case.
The text was updated successfully, but these errors were encountered: