-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdl2_test.py
67 lines (51 loc) · 1.7 KB
/
sdl2_test.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
64
65
66
67
import sys
import struct
import ctypes
try:
from sdl2 import *
import sdl2.ext as sdl2ext
import sdl2.sdlttf as sdlttf
except ImportError:
import traceback
traceback.print_exc()
sys.exit(1)
def run():
sdl2ext.init()
sdlttf.TTF_Init(SDL_INIT_EVERYTHING)
font = sdlttf.TTF_OpenFont(str.encode("himalaya.ttf"), 300)
flags = SDL_WINDOW_SHOWN
color = sdlttf.SDL_Color(255, 255, 255, 255)
tibstring = 'བསྐྱོངས་'
sdlstr = (ctypes.c_uint16 * len(tibstring))(*map(ord, tibstring))
window = SDL_CreateWindow(b'TTF TEST',
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800,
600,
flags)
renderer = SDL_CreateRenderer(window,
-1,
SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTVSYNC)
# message = sdlttf.TTF_RenderUTF8_Blended(font,
# str.encode(tibstring),
# color)
message = sdlttf.TTF_RenderUNICODE_Blended(
font,
sdlstr,
color)
tex = SDL_CreateTextureFromSurface(renderer, message)
dst = SDL_Rect(0, 0, 640, 480)
SDL_RenderCopy(renderer, tex, None, dst)
SDL_ShowWindow(window)
running = True
while running:
events = sdl2ext.get_events()
for event in events:
if event.type == SDL_QUIT:
running = False
break
SDL_RenderPresent(renderer)
return 0
if __name__ == "__main__":
sys.exit(run())