forked from libtcod/python-tcod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdl_hook_test.py
More file actions
41 lines (31 loc) · 971 Bytes
/
sdl_hook_test.py
File metadata and controls
41 lines (31 loc) · 971 Bytes
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/env python
"""
example of libtcod's SDL hook
draws a simple white square.
"""
import tcod
import tdl
import numpy as np
# generate a callback for libtcod
@tcod.ffi.callback('SDL_renderer_t')
def sdl_hook(surface):
tcod.lib.SDL_UpperBlit(my_surface, tcod.ffi.NULL, surface, [{'x':0, 'y':0}])
pixels = np.zeros((100, 150, 4), dtype=np.uint8)
my_surface = tcod.lib.SDL_CreateRGBSurfaceWithFormatFrom(
tcod.ffi.cast('void*', pixels.ctypes.data),
pixels.shape[1], pixels.shape[0], 32,
pixels.strides[0],
tcod.lib.SDL_PIXELFORMAT_RGBA32,
)
if __name__ == '__main__':
# hook callback to libtcod
tcod.sys_register_SDL_renderer(sdl_hook)
con = tdl.init(32, 32, renderer='SDL') # MUST BE SDL RENDERER
pixels[:] = 255
tick = 0
while(True):
tick += 1
for event in tdl.event.get():
if event.type == 'QUIT':
raise SystemExit()
tdl.flush() # will call sdl_hook