-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathglslLoader
More file actions
executable file
·43 lines (35 loc) · 1.2 KB
/
glslLoader
File metadata and controls
executable file
·43 lines (35 loc) · 1.2 KB
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
#!/usr/bin/env python
import sys, urllib, os, re
COMMAND='glslViewer'
SHADER_PATH = ''
TMP_DIR = '/tmp/'
TMP_SHD = TMP_DIR + 'shader.frag'
if len(sys.argv) > 1:
SHADER_PATH = sys.argv[1]
else:
print 'This script dowload a shader and their resorces:\nUse:\n$ ./glslLoader.py [URL|LOG_#]\n'
exit()
if SHADER_PATH.isdigit():
SHADER_PATH='https://thebookofshaders.com/log/' + SHADER_PATH + '.frag'
if SHADER_PATH.startswith('http'):
http = urllib.URLopener()
http.addheaders = [('User-Agent', 'Mozilla/5.0')]
http.retrieve(SHADER_PATH, TMP_SHD)
SHADER_PATH=TMP_SHD
COMMAND += ' ' + SHADER_PATH
counter=0
with open(SHADER_PATH) as f:
for line in f:
result = re.search('uniform\\s*sampler2D\\s*([\\w]*);\\s*\\/\\/\\s*([\\w|\\:\\/\\/|\\.|\\-|\\_]*)', line, re.M)
if result:
uniform = result.group(1)
url = result.group(2)
ext = os.path.splitext(url)[1]
img_path = TMP_DIR + str(counter) + ext
print counter,uniform,url,ext
http = urllib.URLopener()
http.retrieve(url, img_path)
COMMAND += ' -' + uniform + ' ' + img_path
counter += 1
print COMMAND
os.system(COMMAND)