Headless Screenshots

So, I spent about 5 hours looking for this information and could not find it, so here is my question.

I need to set up a scene and then dump a render to a png.

I’ve seen this workflow mentioned, but never described, so, I’m hoping that somebody can help me out.

Thank You

In it’s simplest form, it’s base.screenshot().
This saves a .jpg file in the same directory.

To make it a .png file:

base.screenshot("yourfile.png", False)

The second argument indicates that Panda shouldn’t auto-generate a name for the screenshot, but must use ‘yourfile.png’ instead.

Sorry, I must be really tired.

I need to do this without a window being open. When I tried window-type none and did base.screenshot I got a

Basically I want to be able to do this on a server, where I get a request, generate a png and then hand that png back to them.

I know how to do everything except without a window open, generate a png.

Well, with “window-type” set to “none”, nothing is being rendered of course, so there’s nothing to make a screenshot of. Try “offscreen” as “window-type”, this renders stuff into an offscreen buffer.

1 Like

Does that still require run()? I was hoping to avoid the run loop all together.

Sorry, I was hoping to write a concise question to begin with, but obviously I failed.

Screenshot might be the wrong word here.

On a headless machine I want to set up a scene and render that into a png.

Basically I don’t want the runloop, I just need to set up the scene take a picture of that scene, and output a png.

I’m not sure, but I think base.screenshot() renders the scene too. Try it and see if it works.
If not, just invoke base.graphicsEngine.renderFrame(). You might need to invoke it twice, because a render operation will always only show the last frame’s results - or call base.graphicsEngine.flipFrame() after renderFrame().

Thank you, that did it.

Now to figure out the rest of the engine.

1 Like

So, I just tried this on a machine where I don’t have access to xwindows and it died, saying it needed access to X.

More ideas would be welcome, I need to be able to render without access to X.

I tried xvfb and that didn’t work either.

Thank You

You can enable software rendering with “load-display tinydisplay” in your Config.prc file. This will run just fine without access to the X display.

But if you want to use your graphics hardware to render images, you need to have permission to access the X display, because that’s who owns the graphics hardware.


Thanks, Not the answer I was wishing for, but it should be good enough for now, I’ll make decisions based on this now.

If someone is logged onto the console, they can run the command “xhost +”, which gives everyone logged in remotely access to the X display.