Using save/saveFrame to save screenshot in iGeo update method

I am fairly new to both Processing and iGeo and for the life of me I cannot figured out how to take a simple screenshot of the canvas properly.

Take for instance the code below: I am creating a bunch of random points one by one on XY plane.
At each update iteration/duration I want to capture a screenshot to make a gif file afterward.
When I run the code, I will either get the “com.jogamp.opengl.GLException: GL-Error 0x502” or the generated screenshots will be all black with no objects in it.

I can, as a last resort, create a keyPressed function with the save/saveFrame method inside to capture screenshot on key press and that works, but it seems extremely counter intuitive. What am I doing wrong? What is the proper method to capture screenshot sequentially with iGeo?
I am using iGeo 0.9.4.1 and Processing 3.5.4 on Python mode.

the code:

add_library('igeo')

def setup():
    size(480,360,IG.GL)
    IG.bg(0)
    IG.persTarget()
    IG.duration(20)
    
    rPoint = RandPoint(0,200)
    
class RandPoint(IAgent):
    points = []
    frame = 0
    
    def __init__(self, mm, mx):
        self.min = mm
        self.max = mx
    
    def update(self):
        min = self.min
        max = self.max
        self.points.append(IPoint(IRand.get(min, max), IRand.get(min, max),0).clr(IRand.clr()))
        self.frame += 1
        print('add point number {}'.format(self.frame))
        saveFrame('ss'+str(self.frame)+'.jpg')

Hi! Welcome to the forum!

The version on library manager seems outdated and I assume you manually downloaded the latest version for 3.5.4.
http://igeo.jp/download.html

I also get blank screenshots. If you add saveFrame in def draw(), then you will get the final result (as you described with keyPressed). I’m guessing that when screen is saved, actually iGeo’s drawing is not done yet. I’m not fluent in python mode and iGeo so I don’t know in which order operations are processed, but I guess you need to add each point in draw loop then you can save the desired screenshots.

2 Likes

micuat, thankyou for your reply.
I think you’ve solved my problem!

I added a def draw() function and moved the save/saveFrame operation into it and the generated screenshots are valid now.

add_library('igeo')

def setup():
    size(480,360,IG.GL)
    IG.bg(0)
    IG.topView(100,100,1000)
    IG.duration(20)
    
    global rPoint
    rPoint = RandPoint(0,200)

def draw():
    saveFrame('frame'+str(rPoint.frame)+'.jpg')
    
class RandPoint(IAgent):
    points = []
    frame = 1
    
    def __init__(self, mm, mx):
        self.min = mm
        self.max = mx
    
    def update(self):
        min = self.min
        max = self.max
        self.points.append(IPoint(IRand.get(min, max), IRand.get(min, max),0).clr(IRand.clr()))
        print('add point number {}'.format(self.frame))
        self.frame += 1
        

One little caveat though, this method does not generated a screenshot at every single iteration, there are quite a few missing (it generated 14 screenshots out of 20 iterations). I guess this is due to the continuous nature of the draw function, and the number of times it capture the screenshots is dependent on some other factor (my cpu speed?)…

1 Like