bjornbytes/lovr

how to save a screenshot from code?

blenderman94 opened this issue · 10 comments

hey im trying to put some in game ai to my project but i dont know how to get a screen shot?

what im trying to do is to save the contents of a window to an image on disk

There's a nice example in docs for this:

Texture:newReadback

that part i have but i just dont know how to write it to the disk

nevermind

i tryes this method. and copied it all together. yet it does not saves anything to the disk it says its doing so but the image is nowhere. im using windows 11 i have given read/write pernissions to lovr and runnning it as admin

i printer the blob returned to the console it has rgb values in it so the image is not empty.

also i set the bg color but in the readback its semingly just black it print prints a tons of 0. this method is just getting wierder as it goes

Weird, it's working for me. I pasted the example into main.lua, typed lovr . to run it, pressed p to take a screenshot, it printed "saved screenshot to screenshot.png". I opened ~/.local/share/LOVR/default/screenshot.png and it's a transparent png with the "helooo" text in it.

Make sure to check the save folder, on Windows it's at %APPDATA%\LOVR

You can change the background color of the intermediate pass with pass:setClear(r, g, b, a). If you use lovr.graphics.setBackgroundColor, it will change the background color of the window, but that example renders to an offscreen canvas and screenshots that, so you have to set the background of the offscreen canvas.