#๐Ÿ”’ Help with Game Of Life using Shaders - Pygame and Pygame Shaders

4 messages ยท Page 1 of 1 (latest)

limpid yarrow
#

Hello! I am making a game of life simulation but using shaders. I am using Pygame Shaders.
I followed this tutorial https://www.youtube.com/watch?v=XcII7comJ00&t=198s.
The problem is that the simulation stops after one iteration. It steps one and freezes.
My shader logic seems to be correct and I think the problem is that the shader is not getting the next generation but i dont know how to solve it.
Any help is appreciated.
Thanks!

This is the code:

import pygame as pg
import pygame_shaders as pgs

pg.init()

WIDTH = 1920
HEIGHT = 1080
FPS = 120

screen = pg.display.set_mode((WIDTH, HEIGHT), pg.OPENGL | pg.DOUBLEBUF)

buffer = pg.Surface((WIDTH, HEIGHT))

shader = pgs.Shader(pgs.DEFAULT_VERTEX_SHADER, "shaders/gol.frag", screen)
shader.send("u_resolution", (WIDTH, HEIGHT))
shader.send("normalRes", (1/WIDTH, 1/HEIGHT))

buffer.fill((0,0,0))
pg.draw.rect(buffer, (255,255,255), (200,200,500,500), 2)

clock = pg.time.Clock()
is_running = True
pmx, pmy = 0, 0

while is_running:
    dt = clock.tick(FPS) / 1000
    mx, my = pg.mouse.get_pos()

    for event in pg.event.get():
        if event.type == pg.QUIT:
            is_running = False
        if event.type == pg.KEYDOWN:
            if event.key == pg.K_ESCAPE:
                is_running = False

    screen.blit(buffer, (0,0))

    shader.render_direct(pg.Rect(0,0,WIDTH,HEIGHT))

    buffer.blit(screen, (0,0))

    if pg.mouse.get_pressed()[0]:
        pg.draw.line(buffer, (255,255,255), (pmx,pmy), (mx,my), 2)

    pg.display.flip()

    pmx, pmy = mx, my

Code from video: https://editor.p5js.org/BarneyCodes/sketches/HLpsvCXus

Conway's Game of Life is a classic creative coding challenge and today we look at how to optimise it to run fast in P5js using shaders!
The method used is a sort of pseudo compute shader where the frame from the last generation of the game of life is fed into the shader as ...

โ–ถ Play video
long craterBOT
#

@limpid yarrow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

long craterBOT
#

@limpid yarrow

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.