Skip to content

This project aims to compute Conway's game of life entirely through opengl shaders

Notifications You must be signed in to change notification settings

spineki/GameOpengLife

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conway's game of life in Opengl

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 alt text

How does it works?

  1. Creation of a FrameBufferObject (FBO) containing two attachments: COLOR_ATTACHMENT0, COLOR_ATTACHMENT1 that are linked to two textures
  2. Filling COLOR_ATTACHMENT0 related texture with random data to init the grid
  3. While in the main loop, seletcting COLOR_ATTACHMENT1 as the destination for the next render
  4. 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
  1. We now have the next iteration of Conway's game of ligne in COLOR_ATTACHMENT1 texture
  2. We switch back to default ouput, and we use a new shader program (dispShaderProgram) to simply render COLOR_ATTACHMENT0 to the screen
  3. 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)

  • The window is built with GLFW
  • glad handles OpenGl function pointer loading

Requirements

  1. download glfw from here https://www.glfw.org/download.html
  2. cd glfw-x.y.z
  3. cmake -S . -B build

retrieve the libgkfw3.a from build/src and copy it to the extern folder

How to run it?

in the source folder, type make run

Potential improvements

  • 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.

Sources

Heavily inspired by:

About

This project aims to compute Conway's game of life entirely through opengl shaders

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published