# Using save/saveFrame to save screenshot in iGeo update method

**URL:** https://discourse.processing.org/t/using-save-saveframe-to-save-screenshot-in-igeo-update-method/31757
**Category:** Libraries
**Created:** [August 17, 2021, 8:58am UTC](https://discourse.processing.org/t/using-save-saveframe-to-save-screenshot-in-igeo-update-method/31757 "2021-08-17T08:58:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Renruojos](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Renruojos](https://discourse.processing.org/u/Renruojos)
#### Post date: [August 17, 2021, 8:58am UTC](https://discourse.processing.org/t/using-save-saveframe-to-save-screenshot-in-igeo-update-method/31757/1 "2021-08-17T08:58:12Z")

</div>

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:

```auto
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')

```

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [August 17, 2021, 5:39pm UTC](https://discourse.processing.org/t/using-save-saveframe-to-save-screenshot-in-igeo-update-method/31757/2 "2021-08-17T17:39:20Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![Renruojos](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Renruojos](https://discourse.processing.org/u/Renruojos)
#### Post date: [August 18, 2021, 5:17am UTC](https://discourse.processing.org/t/using-save-saveframe-to-save-screenshot-in-igeo-update-method/31757/3 "2021-08-18T05:17:05Z")

</div>

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.

```auto
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?)…
