]> git.tdb.fi Git - libs/gl.git/commitdiff
Move scripts to their own directory
authorMikko Rasa <tdb@tdb.fi>
Tue, 6 Sep 2011 18:20:52 +0000 (21:20 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 6 Sep 2011 18:20:52 +0000 (21:20 +0300)
extgen.py [deleted file]
makefont.py [deleted file]
maketex.py [deleted file]
scripts/extgen.py [new file with mode: 0755]
scripts/makefont.py [new file with mode: 0755]
scripts/maketex.py [new file with mode: 0755]

diff --git a/extgen.py b/extgen.py
deleted file mode 100755 (executable)
index 2c515f2..0000000
--- a/extgen.py
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/python
-
-import sys
-
-ext=sys.argv[1]
-
-funcs=[]
-cur_func=None
-for line in file("gl.spec"):
-       if line[0]=='#' or line.find(':')>=0:
-               continue
-       elif line[0]=='\t' and cur_func:
-               parts=line.split()
-               if parts[0]=="category" and parts[1]==ext:
-                       funcs.append(cur_func)
-       else:
-               paren=line.find('(')
-               if paren>0:
-                       cur_func=line[:paren]
-
-out=file(ext.lower()+".h", "w")
-out.write("#ifndef MSP_GL_%s_\n"%ext.upper())
-out.write("#define MSP_GL_%s_\n"%ext.upper())
-
-out.write("""
-#include "gl.h"
-#include <GL/glext.h>
-
-namespace Msp {
-namespace GL {
-
-""")
-
-for f in funcs:
-       out.write("extern PFNGL%sPROC gl%s;\n"%(f.upper(), f))
-
-out.write("\nvoid init_%s();\n"%ext.lower())
-
-out.write("""
-} // namespace GL
-} // namespace Msp
-
-#endif
-""")
-
-out=file(ext.lower()+".cpp", "w")
-out.write("#include \"extension.h\"\n")
-out.write("#include \"%s.h\"\n"%ext.lower())
-
-out.write("""
-namespace Msp {
-namespace GL {
-
-""")
-
-for f in funcs:
-       out.write("PFNGL%sPROC gl%s=0;\n"%(f.upper(), f))
-
-out.write("\nvoid init_%s()\n{\n"%ext.lower())
-for f in funcs:
-       out.write("\tgl%s=reinterpret_cast<PFNGL%sPROC>(get_proc_address(\"gl%s\"));\n"%(f, f.upper(), f))
-out.write("}\n")
-
-out.write("""
-} // namespace GL
-} // namespace Msp
-""")
diff --git a/makefont.py b/makefont.py
deleted file mode 100755 (executable)
index e0b5879..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/python
-
-def convert_def(fn):
-       src=file(fn)
-
-       line=src.readline()
-       tw,th,fh,fa,fd=map(int, line.split())
-
-       result="native_size %d;\n"%fh
-       result+="ascent %.3f;\n"%(float(fa)/fh)
-       result+="descent %.3f;\n"%(float(fd)/fh)
-
-       for line in src.readlines():
-               g,x,y,w,h,ox,oy,a=map(int, line.split())
-               result+="glyph %d\n{\n"%g
-               result+="\ttexcoords %f %f %f %f;\n"%(float(x)/tw, float(th-y-h)/th, float(x+w)/tw, float(th-y)/th)
-               result+="\tsize %.3f %.3f;\n"%(float(w)/fh, float(h)/fh)
-               result+="\toffset %.3f %.3f;\n"%(float(ox)/fh, float(oy)/fh)
-               result+="\tadvance %.3f;\n"%(float(a)/fh)
-               result+="};\n"
-
-       return result
-
-def make_font(fn, size):
-       import maketex
-       import os
-
-       if os.system("ttf2png \"%s\" -o makefont-tmp.png -d makefont-tmp.def -t -p -s %d"%(fn, size)):
-               raise Exception("Could not execute ttf2png")
-
-       result="texture\n{\n"
-       result+="wrap CLAMP_TO_EDGE;\n"
-       result+=maketex.make_tex("makefont-tmp.png")
-       result+="};\n"
-       result+=convert_def("makefont-tmp.def")
-
-       os.unlink("makefont-tmp.png")
-       os.unlink("makefont-tmp.def")
-
-       return result
-
-if __name__=="__main__":
-       import sys
-
-       if len(sys.argv)<4:
-               import os
-               print "Usage: %s <font.ttf> <outfile> <size>"%os.path.basename(sys.argv[0])
-       else:
-               out=file(sys.argv[2], "w")
-               out.write(make_font(sys.argv[1], int(sys.argv[3])))
diff --git a/maketex.py b/maketex.py
deleted file mode 100755 (executable)
index 92a2842..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/usr/bin/python
-
-def escape(str):
-       result=""
-       for c in str:
-               if c=='"':
-                       result+='\\"'
-               elif c=='\\':
-                       result+='\\\\'
-               elif ord(c)<0x20:
-                       result+="\\%03o"%ord(c)
-               else:
-                       result+=c
-       return result;
-
-def make_tex(fn):
-       import Image
-
-       img=Image.open(fn)
-
-       fmt="".join(img.getbands())
-       if fmt=="LA":
-               fmt="LUMINANCE_ALPHA"
-       elif fmt=="L":
-               fmt="LUMINANCE"
-
-       result="storage %s %d %d;\n"%(fmt, img.size[0], img.size[1])
-       result+="min_filter LINEAR;\n"
-       result+="raw_data \""
-       data=list(img.getdata())
-       for y in range(img.size[1]):
-               i=(img.size[1]-1-y)*img.size[0]
-               result+=escape("".join(["".join([chr(v) for v in p]) for p in data[i:i+img.size[0]]]))
-       result+="\";\n"
-
-       return result
-
-if __name__=="__main__":
-       import sys
-       import os
-
-       if len(sys.argv)<2:
-               print "Usage: %s <image>"%sys.argv[0]
-       else:
-               out=file(os.path.splitext(sys.argv[1])[0]+".tex", "w")
-               out.write(make_tex(sys.argv[1]))
diff --git a/scripts/extgen.py b/scripts/extgen.py
new file mode 100755 (executable)
index 0000000..2c515f2
--- /dev/null
@@ -0,0 +1,67 @@
+#!/usr/bin/python
+
+import sys
+
+ext=sys.argv[1]
+
+funcs=[]
+cur_func=None
+for line in file("gl.spec"):
+       if line[0]=='#' or line.find(':')>=0:
+               continue
+       elif line[0]=='\t' and cur_func:
+               parts=line.split()
+               if parts[0]=="category" and parts[1]==ext:
+                       funcs.append(cur_func)
+       else:
+               paren=line.find('(')
+               if paren>0:
+                       cur_func=line[:paren]
+
+out=file(ext.lower()+".h", "w")
+out.write("#ifndef MSP_GL_%s_\n"%ext.upper())
+out.write("#define MSP_GL_%s_\n"%ext.upper())
+
+out.write("""
+#include "gl.h"
+#include <GL/glext.h>
+
+namespace Msp {
+namespace GL {
+
+""")
+
+for f in funcs:
+       out.write("extern PFNGL%sPROC gl%s;\n"%(f.upper(), f))
+
+out.write("\nvoid init_%s();\n"%ext.lower())
+
+out.write("""
+} // namespace GL
+} // namespace Msp
+
+#endif
+""")
+
+out=file(ext.lower()+".cpp", "w")
+out.write("#include \"extension.h\"\n")
+out.write("#include \"%s.h\"\n"%ext.lower())
+
+out.write("""
+namespace Msp {
+namespace GL {
+
+""")
+
+for f in funcs:
+       out.write("PFNGL%sPROC gl%s=0;\n"%(f.upper(), f))
+
+out.write("\nvoid init_%s()\n{\n"%ext.lower())
+for f in funcs:
+       out.write("\tgl%s=reinterpret_cast<PFNGL%sPROC>(get_proc_address(\"gl%s\"));\n"%(f, f.upper(), f))
+out.write("}\n")
+
+out.write("""
+} // namespace GL
+} // namespace Msp
+""")
diff --git a/scripts/makefont.py b/scripts/makefont.py
new file mode 100755 (executable)
index 0000000..e0b5879
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+
+def convert_def(fn):
+       src=file(fn)
+
+       line=src.readline()
+       tw,th,fh,fa,fd=map(int, line.split())
+
+       result="native_size %d;\n"%fh
+       result+="ascent %.3f;\n"%(float(fa)/fh)
+       result+="descent %.3f;\n"%(float(fd)/fh)
+
+       for line in src.readlines():
+               g,x,y,w,h,ox,oy,a=map(int, line.split())
+               result+="glyph %d\n{\n"%g
+               result+="\ttexcoords %f %f %f %f;\n"%(float(x)/tw, float(th-y-h)/th, float(x+w)/tw, float(th-y)/th)
+               result+="\tsize %.3f %.3f;\n"%(float(w)/fh, float(h)/fh)
+               result+="\toffset %.3f %.3f;\n"%(float(ox)/fh, float(oy)/fh)
+               result+="\tadvance %.3f;\n"%(float(a)/fh)
+               result+="};\n"
+
+       return result
+
+def make_font(fn, size):
+       import maketex
+       import os
+
+       if os.system("ttf2png \"%s\" -o makefont-tmp.png -d makefont-tmp.def -t -p -s %d"%(fn, size)):
+               raise Exception("Could not execute ttf2png")
+
+       result="texture\n{\n"
+       result+="wrap CLAMP_TO_EDGE;\n"
+       result+=maketex.make_tex("makefont-tmp.png")
+       result+="};\n"
+       result+=convert_def("makefont-tmp.def")
+
+       os.unlink("makefont-tmp.png")
+       os.unlink("makefont-tmp.def")
+
+       return result
+
+if __name__=="__main__":
+       import sys
+
+       if len(sys.argv)<4:
+               import os
+               print "Usage: %s <font.ttf> <outfile> <size>"%os.path.basename(sys.argv[0])
+       else:
+               out=file(sys.argv[2], "w")
+               out.write(make_font(sys.argv[1], int(sys.argv[3])))
diff --git a/scripts/maketex.py b/scripts/maketex.py
new file mode 100755 (executable)
index 0000000..92a2842
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+def escape(str):
+       result=""
+       for c in str:
+               if c=='"':
+                       result+='\\"'
+               elif c=='\\':
+                       result+='\\\\'
+               elif ord(c)<0x20:
+                       result+="\\%03o"%ord(c)
+               else:
+                       result+=c
+       return result;
+
+def make_tex(fn):
+       import Image
+
+       img=Image.open(fn)
+
+       fmt="".join(img.getbands())
+       if fmt=="LA":
+               fmt="LUMINANCE_ALPHA"
+       elif fmt=="L":
+               fmt="LUMINANCE"
+
+       result="storage %s %d %d;\n"%(fmt, img.size[0], img.size[1])
+       result+="min_filter LINEAR;\n"
+       result+="raw_data \""
+       data=list(img.getdata())
+       for y in range(img.size[1]):
+               i=(img.size[1]-1-y)*img.size[0]
+               result+=escape("".join(["".join([chr(v) for v in p]) for p in data[i:i+img.size[0]]]))
+       result+="\";\n"
+
+       return result
+
+if __name__=="__main__":
+       import sys
+       import os
+
+       if len(sys.argv)<2:
+               print "Usage: %s <image>"%sys.argv[0]
+       else:
+               out=file(os.path.splitext(sys.argv[1])[0]+".tex", "w")
+               out.write(make_tex(sys.argv[1]))