-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.py
63 lines (48 loc) · 1.38 KB
/
example2.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from random import randint
from time import time
import pygame
from pygame_render import RenderEngine
# Initialize pygame
pygame.init()
# Create a render engine
width, height = 1280, 720
engine = RenderEngine(width, height)
# Load texture
tex = engine.load_texture('sprite.png')
# Clock
clock = pygame.time.Clock()
# Positions
num_sprites = 1000
positions = [(randint(0, width), randint(0, height))
for _ in range(num_sprites)]
# Load shader
shader_glow = engine.load_shader_from_path('vertex.glsl', 'fragment_glow.glsl')
# Main game loop
running = True
total_time = 0
while running:
# Tick the clock at 60 frames per second
clock.tick(60)
t0 = time()
# Clear the screen
engine.clear(64, 128, 64)
# Update the time
total_time += clock.get_time()
# Send time uniform to glow shader
shader_glow['time'] = total_time
# Render texture to screen
angle = total_time * 0.05
for p in positions:
engine.render(tex, engine.screen,
position=p, scale=16., angle=angle, shader=shader_glow)
# Update the display
pygame.display.flip()
# Display mspt
t = time()
mspt = (t-t0)*1000
pygame.display.set_caption(
f'Rendering {num_sprites} sprites at {mspt:.3f} ms per tick!')
# Process events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False