How to get last frame

I want to implement a full-screen cellular automata.

As an early experiment a while back I made a cellular automata with deprecated glBitmap. It was slow, I could only run at about 512x512 at the speed i wanted.

Now I want to try and see if I can do this with shaders. Should I make a texture and draw into it so that I can read as the last frame? Do i need a FBO for this? Very newbie with these things

Thanks.

It seems like if I’m using double buffering that there should already be the two framebuffers I need, but as far as I know framebuffer 0 is the only window-created buffer I can access?

Don’t mess with double buffering of the default framebuffer, always draw to the back buffer, then swap.

Framebuffer and framebuffer object are different.
An FBO allows to take a framebuffer as a texture. Not possible with default framebuffer.
You can also glCopyTexSubImage from any framebuffer to any texture.

The real advantage of FBO is that you never risk to have glitches due to pixel ownership problems (which can happen when gl window is not entirely visible).

So how do I read a fragment from the previous frame? I want to update the current fragment based on what the neighboring fragments were last frame.

-render on FBO1
loop:
-use FBO1 as source texture
-render on FBO2
-use FBO2 as source texture
-render on FBO1
goto loop.

Okay so I take that to mean that I can’t read from the front(?) buffer (the one that was drawn last frame), i have to copy it to a texture which can then be sampled by the fragment shader?