Elements not rendered properly when taking screenshot
Alevsk opened this issue · 0 comments
Alevsk commented
Hi, this question is directly related to #138, the following snippet code works
func Screenshot(win *pixelgl.Window) {
fmt.Println("taking screenshot...")
f, err := os.Create("screenshot.png")
if err != nil {
panic(err)
}
defer f.Close()
img := pixel.PictureDataFromPicture(win)
png.Encode(f, img.Image())
fmt.Println("done")
}
However some times when generating the screenshots some elements are not fully rendered in the image, ie:
In my specific scenario code looks almost the same with some minor differences:
func GenerateImage() {
f, err := os.Create("screenshot.png")
if err != nil {
panic(err)
}
defer f.Close()
img := pixel.PictureDataFromPicture(win)
err = png.Encode(f, img.Image())
if err != nil {
panic(err)
}
fmt.Println("done")
}
win is a global variable var win *pixelgl.Window
and I'm invoking the GenerateImage()
from a different thread than the main thread, I'm wondering if that could be causing the problem and if there's a way to freeze or make win
wait for all elements to be rendered before pixel.PictureDataFromPicture(win)
is executed.