-
Notifications
You must be signed in to change notification settings - Fork 33
/
Conway.py
41 lines (33 loc) · 1.23 KB
/
Conway.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals
""" GPU doing conways game of life. ESC to quit
this shows how it is possible to recycle images from the renderbuffer
and use the very fast processing speed of the GPU to do certain tasks.
"""
import ctypes
import demo
import pi3d
from pi3d.constants import GL_TEXTURE_2D, GL_RGB
WIDTH = 800
HEIGHT = 800
DISPLAY = pi3d.Display.create(w=WIDTH, h=HEIGHT)
CAMERA = pi3d.Camera(is_3d=False)
shader = pi3d.Shader("conway")
tex = []
tex.append(pi3d.Texture("textures/Roof.png", mipmap=False))
tex.append(pi3d.Texture("textures/Roof.png", mipmap=False))
sprite = pi3d.Sprite(camera=CAMERA, w=WIDTH, h=HEIGHT, x=0.0, y=0.0, z=1.0)
sprite.set_draw_details(shader, [tex[0]])
sprite.set_2d_size(WIDTH, HEIGHT, 0.0, 0.0) # used to get pixel scale by shader
ti = 0 # variable to toggle between two textures
mykeys = pi3d.Keyboard()
while DISPLAY.loop_running():
sprite.draw()
ti = (ti+1) % 2
pi3d.opengles.glBindTexture(GL_TEXTURE_2D, tex[ti]._tex)
pi3d.opengles.glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, WIDTH, HEIGHT, 0)
sprite.set_draw_details(shader, [tex[ti]])
if mykeys.read() == 27:
mykeys.close()
DISPLAY.destroy()
break