]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/clouds3d/SkySceneLoader.cpp
Clouds3D crashes because there is no Light
[simgear.git] / simgear / scene / sky / clouds3d / SkySceneLoader.cpp
index 1737622e1c566cf90fa84617fbef80effefbc5bc..efd5f7aadcc7fa0d13a12b13a8a7c00be3879a14 100644 (file)
@@ -49,7 +49,7 @@ Point3D origin;
 Camera *pCam = new Camera();
 // Need to add a light here until we figure out how to use the sun position and color
 SkyLight::SkyLightType eType = SkyLight::SKY_LIGHT_DIRECTIONAL;
-SkyLight *pLight = new SkyLight(eType);
+SkyLight *pLight = 0;
 
 // hack
 sgMat4 my_copy_of_ssgOpenGLAxisSwapMatrix =
@@ -89,6 +89,55 @@ SkySceneLoader::~SkySceneLoader()
 }
 
 
+
+//------------------------------------------------------------------------------
+// Function               : SkySceneLoader::Load
+// Description      :
+//------------------------------------------------------------------------------
+/**
+ * @fn SkySceneLoader::Load(std::string filename)
+ * @brief Loads a SkyWorks scene.
+ *
+ * This is a temporary fix, as it loads only limited scenes
+ *  It can however, load any number of Cloud
+ +
+ */
+//bool SkySceneLoader::Load(std::string filepath)
+bool SkySceneLoader::Load( unsigned char *data, unsigned int size, double latitude, double longitude )
+{
+    if( !pLight)
+       pLight = new SkyLight(eType);
+
+  // Need to create the managers
+  cout << "GraphicsContext::Instantiate();" << endl;
+  GraphicsContext::Instantiate();
+  cout << "  TextureManager::Instantiate();" << endl;
+  TextureManager::Instantiate();
+  cout << "  DynamicTextureManager::Instantiate();" << endl;
+  DynamicTextureManager::Instantiate();
+  cout << "  SceneManager::Instantiate();" << endl;
+  SceneManager::Instantiate();
+
+  float rScale = 40.0;
+  FAIL_RETURN(SceneManager::InstancePtr()->LoadClouds(data, size, rScale, latitude, longitude));
+
+  Vec3f dir(0, 0, 1);
+  pLight->SetPosition(Vec3f(0, 0, 17000));
+  pLight->SetDirection(dir);
+  pLight->SetAmbient(Vec4f( 0.0f, 0.0f, 0.0f, 0.0f));
+  pLight->SetDiffuse(Vec4f(1.0f, 1.0f, 1.0f, 0.0f));
+  //pLight->SetDiffuse(Vec4f(0.0f, 0.0f, 0.0f, 0.0f));
+  //pLight->SetSpecular(Vec4f(1.0f, 1.0f, 1.0f, 0.0f));
+   // No attenuation
+  pLight->SetAttenuation(1.0f, 0.0f, 0.0f);
+  SceneManager::InstancePtr()->AddLight(pLight);
+  SceneManager::InstancePtr()->ShadeClouds();
+
+  return true;
+}
+
 //------------------------------------------------------------------------------
 // Function              : SkySceneLoader::Load
 // Description     : 
@@ -128,7 +177,7 @@ bool SkySceneLoader::Load( SGPath filename, double latitude, double longitude )
   unsigned int iNumFiles;
   if (!SKYFAILED(archive.GetInfo("CloudFile", STRING_TYPE, &iNumFiles)))
   {
-    _ulEndianSwap(&iNumFiles);
+    iNumFiles = ulEndianLittle32(iNumFiles);
     for (unsigned int i = 0; i < iNumFiles; ++i)
     {
       FAIL_RETURN(archive.FindString("CloudFile", &pFilename, i));
@@ -140,12 +189,18 @@ bool SkySceneLoader::Load( SGPath filename, double latitude, double longitude )
       //FAIL_RETURN(archive.FindFloat32("CloudScale", &rScale, i));
       float rScale = 40.0;
       SkyArchive cloudArchive;
+      cout << "Calling cloudArchive.Load(FilePath)" << endl;
       FAIL_RETURN(cloudArchive.Load(FilePath));
+      cout << "Calling SceneManager::InstancePtr()->LoadClouds" << endl;
       FAIL_RETURN(SceneManager::InstancePtr()->LoadClouds(cloudArchive, rScale, latitude, longitude)); 
     }
   }
+  cout << "After Load Clouds" << endl;
   
   Vec3f dir(0, 0, 1);
+  if( !pLight)
+      pLight = new SkyLight(eType);
+
   pLight->SetPosition(Vec3f(0, 0, 17000));
   pLight->SetDirection(dir);
   pLight->SetAmbient(Vec4f( 0.0f, 0.0f, 0.0f, 0.0f));
@@ -155,9 +210,12 @@ bool SkySceneLoader::Load( SGPath filename, double latitude, double longitude )
   
    // No attenuation
   pLight->SetAttenuation(1.0f, 0.0f, 0.0f);
+  cout << "Before SceneManager::InstancePtr()->AddLight(pLight)" << endl;
   SceneManager::InstancePtr()->AddLight(pLight);
   
+  cout << "Before SceneManager::InstancePtr()->ShadeClouds()" << endl;
   SceneManager::InstancePtr()->ShadeClouds();
+  cout << "After SceneManager::InstancePtr()->ShadeClouds()" << endl;
  
   return true;
 }