New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Screenshoting on headless window results in blank image #720
Comments
It's probably because |
@BelTol3011 you should probably add most of the example reproducible code before all the |
Sadly can't be. I added a call to I hope that's what you mean with next frame. import pyglet
pyglet.options["headless"] = True
from pyglet.graphics import Batch
from pyglet.window import Window
import PIL.Image
import io
batch = Batch()
window = Window(500, 500)
circle = pyglet.shapes.Circle(250, 250, 100, color=(255, 255, 0), batch=batch)
@window.event
def on_draw():
print("on_draw")
window.clear()
batch.draw()
def make_screenshot(_):
out = io.BytesIO()
pyglet.image.get_buffer_manager().get_color_buffer().save(file=out)
pil_img = PIL.Image.open(out, formats=("png",))
pil_img.show()
pyglet.app.exit()
pyglet.clock.schedule_interval(lambda _: None, 1 / 60)
pyglet.clock.schedule_once(make_screenshot, 2)
pyglet.app.run() |
You can try changing the buffer which ColorBuffer is taking from. For example: pyglet.image.ColorBufferImage.gl_buffer = pyglet.gl.GL_FRONT On my Linux machine (AMD, Mesa stack) your example works. In my case it works with either GL_FRONT or GL_BACK buffers. |
@benmoran56 import pyglet
pyglet.options["headless"] = True
from pyglet.graphics import Batch
from pyglet.window import Window
import PIL.Image
import io
batch = Batch()
window = Window(500, 500)
window.set_caption("Transparent Window")
circle = pyglet.shapes.Circle(250, 250, 100, color=(255, 255, 0), batch=batch)
@window.event
def on_draw():
print("on_draw")
window.clear()
batch.draw()
def make_screenshot(_):
out = io.BytesIO()
pyglet.image.ColorBufferImage.gl_buffer = pyglet.gl.GL_FRONT
pyglet.image.get_buffer_manager().get_color_buffer().save(file=out)
pil_img = PIL.Image.open(out, formats=("png",))
pil_img.show()
pyglet.app.exit()
pyglet.clock.schedule_interval(lambda _: None, 1 / 60)
pyglet.clock.schedule_once(make_screenshot, 2)
pyglet.app.run() I now get the following exception when the Traceback (most recent call last):
File "/home/bela/.config/JetBrains/PyCharm2022.3/scratches/scratch_29.py", line 40, in <module>
pyglet.app.run()
File "/home/bela/venv310/lib/python3.10/site-packages/pyglet/app/__init__.py", line 107, in run
event_loop.run()
File "/home/bela/venv310/lib/python3.10/site-packages/pyglet/app/base.py", line 169, in run
timeout = self.idle()
File "/home/bela/venv310/lib/python3.10/site-packages/pyglet/app/base.py", line 239, in idle
redraw_all = self.clock.call_scheduled_functions(dt)
File "/home/bela/venv310/lib/python3.10/site-packages/pyglet/clock.py", line 292, in call_scheduled_functions
item.func(now - item.last_ts, *item.args, **item.kwargs)
File "/home/bela/.config/JetBrains/PyCharm2022.3/scratches/scratch_29.py", line 29, in make_screenshot
pyglet.image.get_buffer_manager().get_color_buffer().save(file=out)
File "/home/bela/venv310/lib/python3.10/site-packages/pyglet/image/__init__.py", line 500, in save
encoder.encode(self, file, filename)
File "/home/bela/venv310/lib/python3.10/site-packages/pyglet/image/codecs/pil.py", line 129, in encode
image = image.get_image_data()
File "/home/bela/venv310/lib/python3.10/site-packages/pyglet/image/__init__.py", line 2046, in get_image_data
glReadBuffer(self.gl_buffer)
File "/home/bela/venv310/lib/python3.10/site-packages/pyglet/gl/lib.py", line 107, in errcheck
raise GLException(msg)
pyglet.gl.lib.GLException: b'invalid operation' With |
Describe the bug
When executing the code below, I get shown the following image:
I expected this image:
wich is exactly what I get, when I comment line 3 (
pyglet.options["headless"] = True
).I expect the headless and not-headless outputs to be identical (at least that's what I think is intuitive).
Let me know if the functionality in the
make_screenshot
function supported in headless mode or how I can get an image of the frame buffer of a headless window, if they even have that.How To Reproduce
I used the following code:
System Information:
The text was updated successfully, but these errors were encountered: