*
* This file is in public domain.
*/
+#include <simgear/compiler.h>
#include <string.h>
-#include <GL/gl.h>
-#include <simgear/screen/texture.hxx>
+#include <stdlib.h>
+#include <osg/GL>
+
+#include "texture.hxx"
static float contrast = 1.0;
}
sz = strlen(opt);
- if (!strncmp(opt, "-help", sz)) {
- printf("usage:\n normalmap [-c=contrast] [-b=brightness]");
- printf(" --t=file [--o=file]\n");
- exit(0);
- }
if (!strncmp(opt, "-contrast", sz)) {
contrast = atof(arg);
return ret;
normalmap_file = strdup(arg);
return ret;
}
+ if (!strncmp(opt, "-help", sz)) {
+ printf("usage:\n normalmap [-c=contrast] [-b=brightness]");
+ printf(" --i=file [--o=file]\n\n");
+ exit(0);
+ }
return 1;
}
-GLubyte *make_map( GLubyte *data, int width, int height, int colors )
-{
- GLubyte *map = (GLubyte *)malloc (width * height * 3);
-
- for (int y=0; y<height; y++)
- for (int x=0; x<width; x++)
- {
- int mpos = (x + y*width)*3;
- int dpos = (x + y*width)*colors;
-
- int xp1 = (x < (width-1)) ? x+1 : 0;
- int yp1 = (y < (height-1)) ? y+1 : 0;
- int posxp1 = (xp1 + y*width)*colors;
- int posyp1 = (x + yp1*width)*colors;
-
- map[mpos+0] = (128+(data[posxp1]-data[dpos])/2);
- map[mpos+1] = (128+(data[posyp1]-data[dpos])/2);
- map[mpos+2] = 128 + GLubyte(128*brightness);
- }
-
- return map;
-}
-
int main (int argc, char **argv)
{
int i;
if ( !texture_file )
{
- printf("Error: texture file not specified\n");
+ printf("Error: texture file not specified.\n");
+ printf("usage:\n normalmap [-c=contrast] [-b=brightness]");
+ printf(" --i=file [--o=file]\n\n");
return -1;
}
if ( !texture.texture() )
{
printf("Error: unable to process input file: %s\n", texture_file);
- printf(" (%s)\n", texture.err_str());
+ printf(" (%s)\n\n", texture.err_str());
return -2;
}
memcpy(normalmap_file+i, "_n.rgb\0", 7);
}
- // texture.make_grayscale();
- texture.make_normalmap();
+ texture.make_normalmap(brightness, contrast);
texture.write_texture(normalmap_file);
free( normalmap_file );