2 * Create normal map textures from regular textures.
3 * Created by: Erik Hofman
5 * This file is in public domain.
10 #include <simgear/screen/texture.hxx>
13 static float contrast = 1.0;
14 static float brightness = 1.0;
15 static char *texture_file = NULL, *normalmap_file = NULL;
16 static SGTexture texture;
18 int parse_option(char **args, int n) {
26 if ((arg = strchr(opt, '=')) != NULL)
35 if (!strncmp(opt, "-help", sz)) {
36 printf("usage:\n normalmap [-c=contrast] [-b=brightness]");
37 printf(" --t=file [--o=file]\n");
40 if (!strncmp(opt, "-contrast", sz)) {
44 if (!strncmp(opt, "-brightness", sz)) {
45 brightness = atof(arg);
48 if (!strncmp(opt, "-texture", sz) ||
49 !strncmp(opt, "-input", sz)) {
50 texture_file = strdup(arg);
53 if (!strncmp(opt, "-normalmap", sz) ||
54 !strncmp(opt, "-output", sz)) {
55 normalmap_file = strdup(arg);
62 int main (int argc, char **argv)
67 i += parse_option(argv, i);
71 printf("Error: texture file not specified\n");
75 texture.read_rgb_texture(texture_file);
76 if ( !texture.texture() )
78 printf("Error: unable to process input file: %s\n", texture_file);
79 printf(" (%s)\n", texture.err_str());
83 if ( !normalmap_file )
86 for (i=strlen(texture_file); i>=0; --i)
87 if (texture_file[i] == '.')
90 normalmap_file = (char *)malloc( i+8 );
91 memcpy(normalmap_file, texture_file, i);
92 memcpy(normalmap_file+i, "_n.rgb\0", 7);
95 texture.make_normalmap();
96 texture.write_texture(normalmap_file);
98 free( normalmap_file );