]> git.mxchange.org Git - flightgear.git/blobdiff - utils/Modeller/texture.cxx
Bugfixes and some finetuning:
[flightgear.git] / utils / Modeller / texture.cxx
index 6f744c35dda23fece90a776141333658d6849c97..75c720a250e3cad5b6415ec2f181d03d1d4c2c17 100644 (file)
@@ -17,7 +17,7 @@
 # include <windows.h>
 #endif
 
-#include <osg/GLU>
+#include <osg/Matrixf>
 
 #include <math.h>
 #include <zlib.h>
@@ -95,6 +95,7 @@ SGTexture::bind()
 void
 SGTexture::resize(unsigned int width, unsigned int height)
 {
+    using namespace osg;
     GLfloat aspect;
 
     // Make sure that we don't get a divide by zero exception
@@ -110,10 +111,10 @@ SGTexture::resize(unsigned int width, unsigned int height)
     // Go to the projection matrix, this gets modified by the perspective
     // calulations
     glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
 
     // Do the perspective calculations
-    gluPerspective(45.0, aspect, 1.0, 400.0);
+    Matrixf proj = Matrixf::perspective(45.0, aspect, 1.0, 400.0);
+    glLoadMatrix(proj.ptr());
 
     // Return to the modelview matrix
     glMatrixMode(GL_MODELVIEW);
@@ -901,6 +902,7 @@ SGTexture::make_normalmap(float brightness, float contrast) {
          int yp1 = (y < (texture_height-1)) ? y+1 : 0;
          int posxp1 = (xp1 + ytw)*num_colors;
          int posyp1 = (x + yp1*texture_width)*num_colors;
+         float fx,fy;
 
          GLubyte c = texture_data[dpos];
          GLubyte cx1 = texture_data[posxp1];
@@ -918,8 +920,11 @@ SGTexture::make_normalmap(float brightness, float contrast) {
             map[mpos+3] = a;
          }
 
-         map[mpos+0] = (128+(cx1-c)/2);
-         map[mpos+1] = (128+(cy1-c)/2);
+         fx = asin((c/256.0-cx1/256.0))/1.57079633;
+         fy = asin((cy1/256.0-c/256.0))/1.57079633;
+
+         map[mpos+0] = (GLuint)(fx*256.0)-128;
+         map[mpos+1] = (GLuint)(fy*256.0)-128;
          map[mpos+2] = 127+int(brightness*128); // 255-c/2;
 
          mpos += colors;