result += c
return result;
-def make_tex(fn):
+def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None):
import Image
img = Image.open(fn)
fmt = "LUMINANCE"
result = "storage %s %d %d;\n"%(fmt, img.size[0], img.size[1])
- result += "min_filter LINEAR;\n"
+ result += "filter %s;\n"%filter
+ if "MIPMAP" in filter:
+ result += "generate_mipmap true;\n"
+ if anisotropy:
+ result += "max_anisotropy %d;\n"%anisotropy
+ if wrap:
+ result += "wrap %s;\n"%wrap
result += "raw_data \""
data = list(img.getdata())
for y in range(img.size[1]):
return result
if __name__=="__main__":
- import sys
import os
+ import argparse
- 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]))
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-o", "--output", metavar="FILE", help="Output filename")
+ parser.add_argument("-f", "--filter", choices=["NEAREST", "LINEAR", "MIPMAP"], default="LINEAR", help="Filtering mode")
+ parser.add_argument("-a", "--anisotropy", metavar="NUMBER", help="Maximum anisotropy, 0 = disable")
+ parser.add_argument("-w", "--wrap", choices=["REPEAT", "CLAMP_TO_EDGE", "MIRRORED_REPEAT"], help="Wrapping mode")
+ parser.add_argument("image")
+
+ args = parser.parse_args()
+
+ filter = args.filter
+ if filter=="MIPMAP":
+ filter = "LINEAR_MIPMAP_LINEAR"
+
+ out_fn = args.output
+ if not out_fn:
+ out_fn = os.path.splitext(args.image)[0]+".tex2d"
+ out = file(out_fn, "w")
+ out.write(make_tex(args.image, filter, args.anisotropy, args.wrap))