changeset 2:c24af3462002

initial commit
author Eris Caffee <discordia@eldalin.com>
date Sat, 27 Apr 2013 13:22:17 -0500
parents 9c54994a2635
children 4f8b47ac2715 7ae4ee5c27f8
files CMakeLists.txt src/solar-system.cpp textures/Marble.tga textures/Marslike.tga textures/MoonLike.tga textures/earth.tga textures/jupiter.png textures/jupiter.tga textures/jupiter.xcf textures/marble.tga textures/marslike.tga textures/moon.tga textures/moonlike.tga textures/sun.tga
diffstat 14 files changed, 606 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/CMakeLists.txt	Tue Mar 29 00:27:15 2011 -0500
     1.2 +++ b/CMakeLists.txt	Sat Apr 27 13:22:17 2013 -0500
     1.3 @@ -66,7 +66,7 @@
     1.4  #set (CMAKE_VERBOSE_MAKEFILE ON)
     1.5  
     1.6  # Name your program!
     1.7 -set (App_Name "")
     1.8 +set (App_Name "solar-system")
     1.9  if (App_Name STREQUAL "") 
    1.10    message (FATAL_ERROR "You must set the App_Name variable!")
    1.11  endif ()
    1.12 @@ -112,12 +112,12 @@
    1.13  
    1.14  ################################################################################
    1.15  # When using GCC turn on lots of warnings.
    1.16 -# Some other options to consider:
    1.17 -#   C++  -Weffc++
    1.18 + # Some other options to consider:
    1.19 +#   C++  -Weffc++ -std=c++0x
    1.20  #   C    -std=gnu99 -std=c99
    1.21  
    1.22  if (CMAKE_COMPILER_IS_GNUCXX)
    1.23 -  add_definitions(-pedantic -Wall)
    1.24 +  add_definitions(-pedantic -Wall -std=c++0x)
    1.25  endif ()
    1.26  
    1.27  
    1.28 @@ -133,8 +133,14 @@
    1.29  ################################################################################
    1.30  # The core project files 
    1.31  
    1.32 -file (GLOB SRCS src/*.c src/*.cpp)
    1.33 -file (GLOB HDRS include/*.h include/*.hpp)
    1.34 +file (GLOB SRCS src/*.c src/*.cpp     
    1.35 +  /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/src/*
    1.36 +)
    1.37 +file (GLOB HDRS include/*.h include/*.hpp     
    1.38 +  /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/*     
    1.39 +  /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/GL/*
    1.40 +
    1.41 +)
    1.42  
    1.43  # The directories that contain the libraries we will be linking against.
    1.44  # This must come before the ADD_EXECUTABLE directive.
    1.45 @@ -145,6 +151,8 @@
    1.46  # This must come before the ADD_EXECUTABLE directive.
    1.47  include_directories (
    1.48    ${CMAKE_SOURCE_DIR}/include
    1.49 +  /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/
    1.50 +  /home/eris/gamedev/study/OpenGL_Superbible/work/Src/GLTools/include/GL
    1.51    )
    1.52  
    1.53  # Define the executable program file we are creating.  We must list all of
    1.54 @@ -155,6 +163,9 @@
    1.55      ${HDRS}
    1.56      )
    1.57  else ()
    1.58 +  # I should NOT have to define this symbol explictly.  Why do I?
    1.59 +  add_definitions(-Dlinux)
    1.60 +
    1.61    add_executable (${App_Name}
    1.62      ${SRCS}
    1.63      ${HDRS}
    1.64 @@ -400,14 +411,14 @@
    1.65  
    1.66  ################################################################################
    1.67  
    1.68 -option(Option_OpenGL_Dev "Build an OpenGL Application." OFF)
    1.69 +option(Option_OpenGL_Dev "Build an OpenGL Application." ON)
    1.70  
    1.71  if (Option_OpenGL_Dev)
    1.72  
    1.73    find_package(OpenGL)
    1.74 -  if (NOT OPEN_FOUND)
    1.75 +  if (NOT OPENGL_FOUND)
    1.76      message (FATAL_ERROR "OpenGL not found!")
    1.77 -  endif (NOT OPEN_FOUND)
    1.78 +  endif (NOT OPENGL_FOUND)
    1.79  
    1.80    include_directories(
    1.81      ${OPENGL_INCLUDE_DIR}
    1.82 @@ -419,6 +430,27 @@
    1.83      ${TARGET_LINK_LIBRARIES}
    1.84      )
    1.85  
    1.86 +  option(Option_GLUT_Dev "Build a GLUT Application." ON)
    1.87 +
    1.88 +  if (Option_GLUT_Dev)
    1.89 +
    1.90 +    find_package(GLUT)
    1.91 +    if (NOT GLUT_FOUND)
    1.92 +      message (FATAL_ERROR "GLUT not found!")
    1.93 +    endif()
    1.94 +
    1.95 +    include_directories(
    1.96 +      ${GLUT_INCLUDE_DIR}
    1.97 +      ${INCLUDE_DIRECTORIES}
    1.98 +      )
    1.99 +
   1.100 +    target_link_libraries(${App_Name}
   1.101 +      ${GLUT_LIBRARIES}
   1.102 +      ${TARGET_LINK_LIBRARIES}
   1.103 +      )
   1.104 +
   1.105 +  endif()
   1.106 +
   1.107  endif ()
   1.108  
   1.109  ################################################################################
   1.110 @@ -445,3 +477,4 @@
   1.111  endif ()
   1.112  
   1.113  ################################################################################
   1.114 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/solar-system.cpp	Sat Apr 27 13:22:17 2013 -0500
     2.3 @@ -0,0 +1,564 @@
     2.4 +#include <GLTools.h>
     2.5 +#include <GLShaderManager.h>
     2.6 +#include <GLFrustum.h>
     2.7 +#include <GLBatch.h>
     2.8 +#include <GLFrame.h>
     2.9 +#include <GLMatrixStack.h>
    2.10 +#include <GLGeometryTransform.h>
    2.11 +#include <StopWatch.h>
    2.12 +
    2.13 +#include <math.h>
    2.14 +#include <ctype.h>
    2.15 +#include <stdlib.h>
    2.16 +#include <string.h>
    2.17 +
    2.18 +#include <dirent.h>
    2.19 +
    2.20 +#include <GL/glut.h>
    2.21 +#include <GL/glx.h>
    2.22 +
    2.23 +GLShaderManager		shaderManager;
    2.24 +GLMatrixStack		modelViewMatrix;
    2.25 +GLMatrixStack		projectionMatrix;
    2.26 +GLFrustum		viewFrustum;
    2.27 +GLGeometryTransform	transformPipeline;
    2.28 +
    2.29 +GLFrame			cameraFrame;
    2.30 +
    2.31 +GLenum			polymode = GL_FILL;
    2.32 +
    2.33 +int			width = 800;
    2.34 +int			height = 600;
    2.35 +int			fullscreen = 0;
    2.36 +
    2.37 +#define NUM_SPHERES 50
    2.38 +GLFrame spheres[NUM_SPHERES];
    2.39 +
    2.40 +GLTriangleBatch jupiterBatch;
    2.41 +GLTriangleBatch sphereBatch;
    2.42 +GLTriangleBatch earthBatch;
    2.43 +GLTriangleBatch moonBatch;
    2.44 +GLTriangleBatch sunBatch;
    2.45 +GLBatch floorBatch;
    2.46 +
    2.47 +#define TEX_EARTH 1
    2.48 +#define TEX_MOON 2
    2.49 +#define TEX_JUPITER 3
    2.50 +#define TEX_SUN 4
    2.51 +#define NUM_TEXTURES 5
    2.52 +GLuint uiTextures[NUM_TEXTURES];
    2.53 +
    2.54 +////////////////////////////////////////////////////////////////////////////////
    2.55 +#define SCREENSHOT_FILENAME_BASE "screenshot-"
    2.56 +#define SCREENSHOT_FILENAME_BASELEN 11
    2.57 +#define SCREENSHOT_FILENAME_EXT ".tga"
    2.58 +#define SCREENSHOT_FILENAME_EXTLEN 4
    2.59 +
    2.60 +int scandir_filter(const struct dirent * d)
    2.61 +   {
    2.62 +   if (memcmp(d->d_name, SCREENSHOT_FILENAME_BASE,
    2.63 +       SCREENSHOT_FILENAME_BASELEN) != 0) return 0;
    2.64 +   if (memcmp(d->d_name+SCREENSHOT_FILENAME_BASELEN+3, 
    2.65 +       SCREENSHOT_FILENAME_EXT, SCREENSHOT_FILENAME_EXTLEN) != 0) 
    2.66 +      return 0;
    2.67 +   if (isdigit(d->d_name[SCREENSHOT_FILENAME_BASELEN]) 
    2.68 +       && isdigit(d->d_name[SCREENSHOT_FILENAME_BASELEN+1]) 
    2.69 +       && isdigit(d->d_name[SCREENSHOT_FILENAME_BASELEN+2])) 
    2.70 +      return 1;
    2.71 +   return 0;
    2.72 +   }
    2.73 +
    2.74 +
    2.75 +int get_next_file_name(char * filename)
    2.76 +   {
    2.77 +   static int i = 0;
    2.78 +
    2.79 +   if (i == 0)
    2.80 +      {
    2.81 +      char pattern[SCREENSHOT_FILENAME_BASELEN+3+SCREENSHOT_FILENAME_EXTLEN];
    2.82 +      struct dirent ** file_list;
    2.83 +      int num_files = scandir(".", &file_list, scandir_filter, alphasort);
    2.84 +      if (num_files != 0)
    2.85 +      sprintf(pattern, "%s%%03d%s", SCREENSHOT_FILENAME_BASE,
    2.86 +              SCREENSHOT_FILENAME_EXT);
    2.87 +	 sscanf(file_list[num_files-1]->d_name, pattern, &i);
    2.88 +      }
    2.89 +   i++;
    2.90 +
    2.91 +   sprintf(filename, "%s%03d%s", SCREENSHOT_FILENAME_BASE, i, 
    2.92 +	   SCREENSHOT_FILENAME_EXT);
    2.93 +   return i;
    2.94 +   }
    2.95 +
    2.96 +////////////////////////////////////////////////////////////////////////////////
    2.97 +bool LoadTGATexture(const char * szFileName, GLenum minFilter, 
    2.98 +		    GLenum magFilter, GLenum wrapMode)
    2.99 +   {
   2.100 +   GLbyte * pBits;
   2.101 +   int nWidth, nHeight, nComponents;
   2.102 +   GLenum eFormat;
   2.103 +
   2.104 +   pBits = gltReadTGABits(szFileName, &nWidth, &nHeight, &nComponents, &eFormat);
   2.105 +   if (pBits == NULL)
   2.106 +       {
   2.107 +       fprintf(stderr, "Failed to load %s\n", szFileName);
   2.108 +       exit(EXIT_FAILURE);
   2.109 +       }
   2.110 +
   2.111 +   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode);
   2.112 +   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode);
   2.113 +
   2.114 +   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
   2.115 +   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
   2.116 +
   2.117 +   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   2.118 +   glTexImage2D(GL_TEXTURE_2D, 0, nComponents, nWidth, nHeight, 0,
   2.119 +		eFormat, GL_UNSIGNED_BYTE, pBits);
   2.120 +
   2.121 +   free(pBits);
   2.122 +
   2.123 +   if (minFilter == GL_LINEAR_MIPMAP_LINEAR ||
   2.124 +       minFilter == GL_LINEAR_MIPMAP_NEAREST ||
   2.125 +       minFilter == GL_NEAREST_MIPMAP_LINEAR ||
   2.126 +       minFilter == GL_NEAREST_MIPMAP_NEAREST)
   2.127 +      {
   2.128 +      glGenerateMipmap(GL_TEXTURE_2D);
   2.129 +      }
   2.130 +
   2.131 +   return true;
   2.132 +   }
   2.133 +
   2.134 +////////////////////////////////////////////////////////////////////////////////
   2.135 +void DrawSolarSystem(GLfloat yRot)
   2.136 +   {
   2.137 +   static GLfloat vWhite[] = { 1.0f, 1.0f, 1.0f, 1.0f };
   2.138 +   static GLfloat vLightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
   2.139 +   static M3DVector3f vSunPos = { 0.0f, 0.0f, 0.0f };
   2.140 +   static M3DVector3f vEarthPos = { 5.0f, 0.0f, 0.0f };
   2.141 +   static M3DVector3f vJupiterPos = { 10.0f, 0.0f, 0.0f };
   2.142 +
   2.143 +   float RotScale = 100.0;
   2.144 +   float SunRotSpeed = 1.0/(25*24) * RotScale;
   2.145 +
   2.146 +   float JupiterRotSpeed = 1.0/9 * RotScale;
   2.147 +   float JupiterAxialTilt = 3.13;
   2.148 +
   2.149 +   float EarthRotSpeed = 1.0/24 * RotScale;
   2.150 +   float EarthAxialTilt = 23.5;
   2.151 +
   2.152 +   float MoonRotSpeed = 1.0/29.5 * RotScale;
   2.153 +   float MoonAxialTilt = 6.7;
   2.154 +   float MoonOrbitSpeed = 1.0/29.5 * RotScale;
   2.155 +   float MoonOrbitTilt = 5.145;
   2.156 +
   2.157 +   static CStopWatch rotTimer;
   2.158 +
   2.159 +   // Get the light position in eye space
   2.160 +   M3DVector4f vLightTransformed;
   2.161 +   M3DMatrix44f mCamera;
   2.162 +   modelViewMatrix.GetMatrix(mCamera);
   2.163 +   m3dTransformVector4(vLightTransformed, vLightPos, mCamera);
   2.164 +
   2.165 +
   2.166 +   ////////////////////////////////
   2.167 +   // Begin Sun
   2.168 +
   2.169 +   float SunRot = rotTimer.GetElapsedSeconds() * SunRotSpeed;
   2.170 +
   2.171 +   modelViewMatrix.PushMatrix();
   2.172 +
   2.173 +   modelViewMatrix.Translatev(vSunPos);
   2.174 +   // North is up!
   2.175 +   modelViewMatrix.Rotate(-90.0f, 1.0f, 0.0f, 0.0f);
   2.176 +   // Rotate on axis
   2.177 +   modelViewMatrix.Rotate(SunRot, 0.0f, 0.0f, 1.0f);
   2.178 +
   2.179 +   glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_SUN]);
   2.180 +   if (polymode == GL_FILL)
   2.181 +      {
   2.182 +      shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE,
   2.183 +   				   transformPipeline.GetModelViewProjectionMatrix(),
   2.184 +   				   0);
   2.185 +      }
   2.186 +   else
   2.187 +      {
   2.188 +      shaderManager.UseStockShader(GLT_SHADER_FLAT,
   2.189 +				   transformPipeline.GetModelViewProjectionMatrix(),
   2.190 +				   vWhite);
   2.191 +      }
   2.192 +   sunBatch.Draw();
   2.193 +   modelViewMatrix.PopMatrix();
   2.194 +   // End Sun
   2.195 +   /////////////////////////////////
   2.196 +
   2.197 +
   2.198 +   ////////////////////////////////
   2.199 +   // Jupiter
   2.200 +   float JupiterRot = rotTimer.GetElapsedSeconds() * JupiterRotSpeed;
   2.201 +
   2.202 +   modelViewMatrix.PushMatrix();
   2.203 +   modelViewMatrix.Translatev(vJupiterPos);
   2.204 +   // North is up!
   2.205 +   modelViewMatrix.Rotate(-90.0f - JupiterAxialTilt, 1.0f, 0.0f, 0.0f);
   2.206 +   // Rotate on axis
   2.207 +   modelViewMatrix.Rotate(JupiterRot, 0.0f, 0.0f, 1.0f);
   2.208 +
   2.209 +   glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_JUPITER]);
   2.210 +   if (polymode == GL_FILL)
   2.211 +      {
   2.212 +      // shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE,
   2.213 +      // 	  transformPipeline.GetModelViewProjectionMatrix(),
   2.214 +      // 	  0);
   2.215 +      shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
   2.216 +       				   modelViewMatrix.GetMatrix(),
   2.217 +       				   transformPipeline.GetProjectionMatrix(),
   2.218 +       				   vLightTransformed,
   2.219 +       				   vWhite,
   2.220 +       				   0);
   2.221 +      }
   2.222 +   else
   2.223 +      {
   2.224 +      shaderManager.UseStockShader(GLT_SHADER_FLAT,
   2.225 +   				   transformPipeline.GetModelViewProjectionMatrix(),
   2.226 +   				   vWhite);
   2.227 +
   2.228 +      }
   2.229 +   jupiterBatch.Draw();
   2.230 +   modelViewMatrix.PopMatrix();
   2.231 +   // End Jupiter
   2.232 +   ////////////////////////////////
   2.233 +
   2.234 +
   2.235 +
   2.236 +
   2.237 +   /////////////////////////////////
   2.238 +   // Begin Earth/Moon
   2.239 +
   2.240 +   // Begin Earth
   2.241 +   float EarthRot = rotTimer.GetElapsedSeconds() * EarthRotSpeed;
   2.242 +
   2.243 +   modelViewMatrix.PushMatrix();
   2.244 +   modelViewMatrix.Translatev(vEarthPos);
   2.245 +   modelViewMatrix.PushMatrix(); // Save unrotated matrix for when we do the Moon
   2.246 +
   2.247 +   // NOrth is up!
   2.248 +   modelViewMatrix.Rotate(-90.0f - EarthAxialTilt, 1.0f, 0.0f, 0.0f);
   2.249 +   // Rotate on the axis
   2.250 +   modelViewMatrix.Rotate(EarthRot, 0.0f, 0.0f, 1.0f);
   2.251 +
   2.252 +   if (polymode == GL_FILL)
   2.253 +      {
   2.254 +      glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_EARTH]);
   2.255 +      shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
   2.256 +   				   modelViewMatrix.GetMatrix(),
   2.257 +   				   transformPipeline.GetProjectionMatrix(),
   2.258 +   				   vLightTransformed,
   2.259 +   				   vWhite,
   2.260 +   				   0);
   2.261 +      }
   2.262 +   else
   2.263 +      {
   2.264 +      shaderManager.UseStockShader(GLT_SHADER_FLAT,
   2.265 +   				   transformPipeline.GetModelViewProjectionMatrix(),
   2.266 +   				   vWhite);
   2.267 +
   2.268 +      }
   2.269 +   earthBatch.Draw();
   2.270 +   modelViewMatrix.PopMatrix();
   2.271 +
   2.272 +   // Begin Moon
   2.273 + 
   2.274 +
   2.275 +   // orbit the Earth
   2.276 +   modelViewMatrix.Rotate(MoonOrbitTilt, 0.0f, 0.0f, 1.0f);
   2.277 +   // NOrth is up!
   2.278 +   modelViewMatrix.Rotate(-90.0f - MoonAxialTilt, 0.0f, 1.0f, 0.0f);
   2.279 +
   2.280 +   float MoonRot = rotTimer.GetElapsedSeconds() * MoonOrbitSpeed * 10;
   2.281 +   modelViewMatrix.Rotate(MoonRot, 0.0f, 1.0f, 0.0f);
   2.282 +
   2.283 +   modelViewMatrix.Translate(0.5f, 0.0f, 0.0f);
   2.284 +
   2.285 +
   2.286 +   glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_MOON]);
   2.287 +   if (polymode == GL_FILL)
   2.288 +      {
   2.289 +      shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
   2.290 +   				   modelViewMatrix.GetMatrix(),
   2.291 +   				   transformPipeline.GetProjectionMatrix(),
   2.292 +   				   vLightTransformed,
   2.293 +   				   vWhite,
   2.294 +   				   0);
   2.295 +      }
   2.296 +   else 
   2.297 +      {
   2.298 +      shaderManager.UseStockShader(GLT_SHADER_FLAT,
   2.299 +   				   transformPipeline.GetModelViewProjectionMatrix(),
   2.300 +   				   vWhite);
   2.301 +      }
   2.302 +   moonBatch.Draw();
   2.303 +   modelViewMatrix.PopMatrix();
   2.304 +
   2.305 +
   2.306 +   modelViewMatrix.PopMatrix();
   2.307 +   // End Earth/Moon
   2.308 +   ////////////////////////////////
   2.309 +   
   2.310 +   }
   2.311 +
   2.312 +////////////////////////////////////////////////////////////////////////////////
   2.313 +void RenderScene(void)
   2.314 +   {
   2.315 +   static CStopWatch rotTimer;
   2.316 +   float yRot = - rotTimer.GetElapsedSeconds() * 60.0f;
   2.317 +
   2.318 +   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
   2.319 +
   2.320 +   // Begin Render
   2.321 +   modelViewMatrix.PushMatrix();
   2.322 +
   2.323 +   // Begin Camera position
   2.324 +   static M3DMatrix44f mCamera;
   2.325 +   cameraFrame.GetCameraMatrix(mCamera);
   2.326 +   modelViewMatrix.MultMatrix(mCamera);
   2.327 +   // End Camera position
   2.328 +
   2.329 +   DrawSolarSystem(yRot);
   2.330 +
   2.331 +   // End Render
   2.332 +   modelViewMatrix.PopMatrix();
   2.333 +
   2.334 +   glutSwapBuffers();
   2.335 +   glutPostRedisplay();
   2.336 +   }
   2.337 +
   2.338 +////////////////////////////////////////////////////////////////////////////////
   2.339 +void SetupRC()
   2.340 +   {
   2.341 +   shaderManager.InitializeStockShaders();
   2.342 +   glEnable(GL_DEPTH_TEST);
   2.343 +   glEnable(GL_CULL_FACE);
   2.344 +   glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
   2.345 +
   2.346 +   gltMakeSphere(jupiterBatch, 0.5f, 128, 128 );
   2.347 +   gltMakeSphere(earthBatch, 0.2f, 26, 26);
   2.348 +   gltMakeSphere(moonBatch, 0.1f, 26, 26);
   2.349 +   gltMakeSphere(sunBatch, 1.0f, 26, 26);
   2.350 +
   2.351 +   glGenTextures(NUM_TEXTURES, uiTextures);
   2.352 +
   2.353 +   glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_EARTH]);
   2.354 +   LoadTGATexture("../textures/earth.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
   2.355 +
   2.356 +   glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_MOON]);
   2.357 +   LoadTGATexture("../textures/moon.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
   2.358 +
   2.359 +   glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_JUPITER]);
   2.360 +   LoadTGATexture("../textures/jupiter.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
   2.361 +
   2.362 +   glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_SUN]);
   2.363 +   LoadTGATexture("../textures/sun.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
   2.364 +
   2.365 +   static M3DMatrix44f mCamera;
   2.366 +   cameraFrame.GetCameraMatrix(mCamera);
   2.367 +   cameraFrame.MoveForward(-10.0);
   2.368 +//   cameraFrame.RotateWorld(15.0, 0.0f, 1.0f, 0.0f);
   2.369 +   }
   2.370 +
   2.371 +////////////////////////////////////////////////////////////////////////////////
   2.372 +void ShutDownRC(void)
   2.373 +   {
   2.374 +   glDeleteTextures(NUM_TEXTURES, uiTextures);
   2.375 +   }
   2.376 +
   2.377 +////////////////////////////////////////////////////////////////////////////////
   2.378 +void ChangeSize(int nWidth, int nHeight)
   2.379 +   {
   2.380 +   if (nHeight == 0)
   2.381 +      {
   2.382 +      nHeight = 1;
   2.383 +      }
   2.384 +   glViewport(0,0,nWidth, nHeight);
   2.385 +   viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f);
   2.386 +   projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
   2.387 +   transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
   2.388 +   }
   2.389 +
   2.390 +////////////////////////////////////////////////////////////////////////////////
   2.391 +void SpecialKeys(int key, int x, int y)
   2.392 +   {
   2.393 +   }
   2.394 +
   2.395 +////////////////////////////////////////////////////////////////////////////////
   2.396 +void KeyboardFunc(unsigned char key, int x, int y)
   2.397 +   {
   2.398 +   static int changed;
   2.399 +   static float linear = 0.1f;
   2.400 +
   2.401 +   changed = 0;
   2.402 +   
   2.403 +   if ('w' == key)
   2.404 +      {
   2.405 +      cameraFrame.MoveForward(linear);
   2.406 +      changed = 1;
   2.407 +      }
   2.408 +   else if ('W' == key)
   2.409 +      {
   2.410 +      cameraFrame.MoveForward(10*linear);
   2.411 +      changed = 1;
   2.412 +      }
   2.413 +   else if ('s' == key)
   2.414 +      {
   2.415 +      cameraFrame.MoveForward(-linear);
   2.416 +      changed = 1;
   2.417 +      }
   2.418 +   else if ('S' == key)
   2.419 +      {
   2.420 +      cameraFrame.MoveForward(-10*linear);
   2.421 +      changed = 1;
   2.422 +      }
   2.423 +   else if ('a' == key)
   2.424 +      {
   2.425 +      cameraFrame.MoveRight(linear);
   2.426 +      changed = 1;
   2.427 +      }
   2.428 +   else if ('A' == key)
   2.429 +      {
   2.430 +      cameraFrame.MoveRight(10*linear);
   2.431 +      changed = 1;
   2.432 +      }
   2.433 +   else if ('d' == key)
   2.434 +      {
   2.435 +      cameraFrame.MoveRight(-linear);
   2.436 +      changed = 1;
   2.437 +      }
   2.438 +   else if ('D' == key)
   2.439 +      {
   2.440 +      cameraFrame.MoveRight(-10*linear);
   2.441 +      changed = 1;
   2.442 +      }
   2.443 +
   2.444 +   else if ('q' == key)
   2.445 +      {
   2.446 +      exit(0);
   2.447 +      }
   2.448 +   else if ('f' == key)
   2.449 +      {
   2.450 +      if (fullscreen)
   2.451 +	 {
   2.452 +	 glutReshapeWindow(width, height);
   2.453 +	 fullscreen = 0;
   2.454 +	 }
   2.455 +      else
   2.456 +	 {
   2.457 + 	 width = glutGet(GLUT_WINDOW_WIDTH);
   2.458 +	 height = glutGet(GLUT_WINDOW_HEIGHT);
   2.459 +	 glutFullScreen();
   2.460 +	 fullscreen = 1;
   2.461 +	 } 
   2.462 +      }
   2.463 +   else if ('o' == key)
   2.464 +      {
   2.465 +      // 'o' for 'outline' - toggle wireframe rendering 
   2.466 +      polymode = (polymode == GL_FILL) ? GL_LINE : GL_FILL;
   2.467 +      glPolygonMode(GL_FRONT_AND_BACK, polymode);
   2.468 +      }
   2.469 +   else if ('p' == key)
   2.470 +      {
   2.471 +      // 'p' for 'print screen' - save a screenshot
   2.472 +      char filename[20];
   2.473 +      get_next_file_name(filename);
   2.474 +      
   2.475 +      gltGrabScreenTGA(filename);
   2.476 +      }
   2.477 +
   2.478 +   if (changed)
   2.479 +      {
   2.480 +      glutPostRedisplay();
   2.481 +      }
   2.482 +   }
   2.483 +
   2.484 +////////////////////////////////////////////////////////////////////////////////
   2.485 +void MouseMotionFunc (int x, int y)
   2.486 +   {
   2.487 +   static float angular = (float) m3dDegToRad(0.5f);
   2.488 +   static int xx = -1;
   2.489 +   static int yy = -1;
   2.490 +
   2.491 +   if (-1 == xx)
   2.492 +      {
   2.493 +      xx = x;
   2.494 +      yy = y;
   2.495 +      }
   2.496 +
   2.497 +   if ((0 == x) || (x < xx))
   2.498 +      {
   2.499 +      cameraFrame.RotateWorld(angular, 0.0f, 1.0f, 0.0f);
   2.500 +      glutPostRedisplay();
   2.501 +      }
   2.502 +   else if ((x == glutGet(GLUT_WINDOW_WIDTH) -1) || (x > xx))
   2.503 +      {
   2.504 +      cameraFrame.RotateWorld(-angular, 0.0f, 1.0f, 0.0f);
   2.505 +      glutPostRedisplay();
   2.506 +      }
   2.507 +   // Hmm.  Need to transform normal vector, don't I?
   2.508 +   // if ((0 == y) || (y < yy))
   2.509 +   //    {
   2.510 +   //    cameraFrame.RotateWorld(angular, 1.0f, 0.0f, 0.0f);
   2.511 +   //    }
   2.512 +   // else if ((y == glutGet(GLUT_WINDOW_HEIGHT) -1) || (y > yy))
   2.513 +   //    {
   2.514 +   //    cameraFrame.RotateWorld(-angular, 1.0f, 0.0f, 0.0f);
   2.515 +   //    }
   2.516 +
   2.517 +   xx = x; 
   2.518 +   yy = y;
   2.519 +   }
   2.520 +
   2.521 +////////////////////////////////////////////////////////////////////////////////
   2.522 +int main (int argc, char * argv[])
   2.523 +   {
   2.524 +   gltSetWorkingDirectory(argv[0]);
   2.525 +   glutInit(&argc, argv);
   2.526 +   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
   2.527 +   glutInitWindowSize(800, 600);
   2.528 +   glutCreateWindow("OpenGL SphereWorld");
   2.529 +
   2.530 +   glutReshapeFunc(ChangeSize);
   2.531 +   glutDisplayFunc(RenderScene);
   2.532 +   glutSpecialFunc(SpecialKeys);
   2.533 +   glutKeyboardFunc(KeyboardFunc);
   2.534 +   glutMotionFunc(MouseMotionFunc);
   2.535 +   glutPassiveMotionFunc(MouseMotionFunc);
   2.536 +   glutSetCursor(GLUT_CURSOR_NONE);
   2.537 +
   2.538 +   GLenum err = glewInit();
   2.539 +   if (GLEW_OK != err)
   2.540 +      {
   2.541 +      fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
   2.542 +      return 1;
   2.543 +      }
   2.544 +
   2.545 +   // This enabled vertical sync on Linux
   2.546 +   // For full generality I should use Glew and check what OS I'm on.
   2.547 +   // Note that the ATI Catalyst driver exports the WGL_EXT_swap_control
   2.548 +   // extension name instead of SGI_swap_control as it should.
   2.549 +   // but nonetheless the actual function provided is glXSwapIntervalSGI
   2.550 +
   2.551 +   PFNGLXSWAPINTERVALSGIPROC SwapInterval;
   2.552 +   SwapInterval = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddress((const GLubyte*)"glXSwapIntervalSGI");
   2.553 +
   2.554 +   if (SwapInterval)
   2.555 +      SwapInterval(1);
   2.556 +
   2.557 +   SetupRC();
   2.558 +   glutMainLoop();
   2.559 +   ShutDownRC();
   2.560 +
   2.561 +   return 0;
   2.562 +   }
   2.563 +
   2.564 +
   2.565 +
   2.566 +
   2.567 +
     3.1 Binary file textures/Marble.tga has changed
     4.1 Binary file textures/Marslike.tga has changed
     5.1 Binary file textures/MoonLike.tga has changed
     6.1 Binary file textures/earth.tga has changed
     7.1 Binary file textures/jupiter.png has changed
     8.1 Binary file textures/jupiter.tga has changed
     9.1 Binary file textures/jupiter.xcf has changed
    10.1 Binary file textures/marble.tga has changed
    11.1 Binary file textures/marslike.tga has changed
    12.1 Binary file textures/moon.tga has changed
    13.1 Binary file textures/moonlike.tga has changed
    14.1 Binary file textures/sun.tga has changed