2 * Create normal map textures from regular textures.
3 * Created by: Erik Hofman
5 * This file is in public domain.
7 #include <simgear/compiler.h>
13 #include <simgear/screen/texture.hxx>
16 static float contrast = 1.0;
17 static float brightness = 1.0;
18 static char *texture_file = NULL, *normalmap_file = NULL;
19 static SGTexture texture;
21 int parse_option(char **args, int n) {
29 if ((arg = strchr(opt, '=')) != NULL)
38 if (!strncmp(opt, "-help", sz)) {
39 printf("usage:\n normalmap [-c=contrast] [-b=brightness]");
40 printf(" --t=file [--o=file]\n");
43 if (!strncmp(opt, "-contrast", sz)) {
47 if (!strncmp(opt, "-brightness", sz)) {
48 brightness = atof(arg);
51 if (!strncmp(opt, "-texture", sz) ||
52 !strncmp(opt, "-input", sz)) {
53 texture_file = strdup(arg);
56 if (!strncmp(opt, "-normalmap", sz) ||
57 !strncmp(opt, "-output", sz)) {
58 normalmap_file = strdup(arg);
65 int main (int argc, char **argv)
70 i += parse_option(argv, i);
74 printf("Error: texture file not specified\n");
78 texture.read_rgb_texture(texture_file);
79 if ( !texture.texture() )
81 printf("Error: unable to process input file: %s\n", texture_file);
82 printf(" (%s)\n", texture.err_str());
86 if ( !normalmap_file )
89 for (i=strlen(texture_file); i>=0; --i)
90 if (texture_file[i] == '.')
93 normalmap_file = (char *)malloc( i+8 );
94 memcpy(normalmap_file, texture_file, i);
95 memcpy(normalmap_file+i, "_n.rgb\0", 7);
98 texture.make_normalmap(brightness, contrast);
99 texture.write_texture(normalmap_file);
101 free( normalmap_file );
102 free( texture_file );