]> git.mxchange.org Git - flightgear.git/blobdiff - tests/test-env-map.cxx
latest changes for JSBSim (1.0 prerelease)
[flightgear.git] / tests / test-env-map.cxx
index ef56255c71520afb6fe821b3a24d65b0a07b200b..c3377bb3369e2c8fa7791d8ff6000d5d49e266f1 100644 (file)
@@ -1,14 +1,31 @@
-#include <GL/glut.h>
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>
+#endif
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <math.h>
 
+#include <simgear/compiler.h>
+#if defined( __APPLE__)
+# include <OpenGL/OpenGL.h>
+# include <GLUT/glut.h>
+#else
+# include <GL/gl.h>
+# include <GL/glut.h>
+#endif
+
 #define TEXRES_X 256
 #define TEXRES_Y 256
 
+
 unsigned char env_map[TEXRES_X][TEXRES_Y][4];
 GLuint texName;
-float window_x = 640, window_y = 480;
+int window_x = 640, window_y = 480;
 float alpha = 0.0, beta = 0.0;
 
   /*****************************************************************/
@@ -44,8 +61,8 @@ void setColor(float x, float y, float z, float angular_size, float r, float g, f
           float rz = -tz;
 
           float inv_m = 1.0 / (2.0 * sqrt(rx*rx + ry*ry + (rz + 1)*(rz + 1)));
-          int s = TEXRES_X * (rx * inv_m + 0.5);
-          int t = TEXRES_Y * (ry * inv_m + 0.5);
+          int s = (int)(TEXRES_X * (rx * inv_m + 0.5));
+          int t = (int)(TEXRES_Y * (ry * inv_m + 0.5));
 
           //seg_fault protection:
           if (s<0) s=0; 
@@ -54,10 +71,10 @@ void setColor(float x, float y, float z, float angular_size, float r, float g, f
           if (t<0) t=0;
           if (t>=TEXRES_Y) t=TEXRES_Y-1;
 
-          env_map[s][t][0] = r * 255;  
-          env_map[s][t][1] = g * 255;
-          env_map[s][t][2] = b * 255;
-          env_map[s][t][3] = a * 255;
+          env_map[s][t][0] = (unsigned char)(r * 255);
+          env_map[s][t][1] = (unsigned char)(g * 255);
+          env_map[s][t][2] = (unsigned char)(b * 255);
+          env_map[s][t][3] = (unsigned char)(a * 255);
         }
       }
     }
@@ -98,6 +115,8 @@ void init(void)
   glGenTextures(1, &texName);
   glBindTexture(GL_TEXTURE_2D, texName);
   
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
@@ -122,7 +141,7 @@ void display()
   //show light
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
-  gluPerspective((GLdouble) 60.0, window_x/window_y, (GLdouble) 1.0, (GLdouble) 100.0);
+  gluPerspective((GLdouble) 60.0, (float)window_x/window_y, (GLdouble) 1.0, (GLdouble) 100.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
 
@@ -157,6 +176,14 @@ void display()
   glVertex3f(1.0, -1.0, 0.0);
   glEnd();
 
+  /*
+  glPointSize(48.0);
+  glBegin(GL_POINTS);
+  glNormal3f(0.0, 0.0, 1.0);
+  glVertex3f(0.0, 0.0, 0.0);
+  glEnd();
+  */
+
   glDisable(GL_TEXTURE_GEN_S);
   glDisable(GL_TEXTURE_GEN_T);
   glDisable(GL_TEXTURE_2D);
@@ -167,9 +194,9 @@ void display()
   //show how the map looks like
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
-  //gluOrtho2D(0.0  -10.0, 1.0 +10.0, -window_x/window_y -10.0,0.0 +10.0);
+  //gluOrtho2D(0.0  -10.0, 1.0 +10.0, -(float)window_x/window_y -10.0,0.0 +10.0);
   //glOrtho(0.0, 5.0, -5.0, 0.0, -10.0, 10.0);
-  glOrtho(0.0, 5.0*(window_x/window_y), -5.0, 0.0, -10.0, 10.0);
+  glOrtho(0.0, 5.0*((float)window_x/window_y), -5.0, 0.0, -10.0, 10.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glEnable(GL_TEXTURE_2D);