This project aims to compute Conway's game of life entirely through opengl shaders It is a toy project written to better understand OpenGl, so it may not be as efficient as possible
- Creation of a FrameBufferObject (FBO) containing two attachments: COLOR_ATTACHMENT0, COLOR_ATTACHMENT1 that are linked to two textures
- Filling COLOR_ATTACHMENT0 related texture with random data to init the grid
- While in the main loop, seletcting COLOR_ATTACHMENT1 as the destination for the next render
- Using a first shader program:
- We create 2 triangles with an identity vertex shader
- We render the next iteration of Conway's game of Life thanks to the fragment shader.
- This shader will use COLOR_ATTACHMENT0 as a uniform texture to know the current grid step, then it can use current texture/pixel position provided by the vertex shader and output the final pixel color
- We now have the next iteration of Conway's game of ligne in COLOR_ATTACHMENT1 texture
- We switch back to default ouput, and we use a new shader program (dispShaderProgram) to simply render COLOR_ATTACHMENT0 to the screen
- Finally, we swap textures (only swapping pointers to avoid heavy copy). During the next iteration, we will use COLOR_ATTACHMENT0 for first output and use COLOR_ATTACHMENT_1 as last-iteration grid
Note: We only use the R color canal for buffers because we only want to have a binary state (alive, dead)
- download glfw from here https://www.glfw.org/download.html
cd glfw-x.y.z
cmake -S . -B build
retrieve the libgkfw3.a
from build/src
and copy it to the extern folder
in the source folder, type make run
- The project could be better if we could change the resolution or interract with the screen to create new cells
- FPS could be displayed in real time on the screen instead of relying on stdout.
Heavily inspired by: