+TexturePtr
+TextureManager::create_image_texture(const std::string& filename)
+{
+ try
+ {
+ return create_image_texture_raw(filename);
+ }
+ catch (const std::exception& err)
+ {
+ log_warning << "Couldn't load texture '" << filename << "' (now using dummy texture): " << err.what() << std::endl;
+ TexturePtr texture = create_dummy_texture();
+ return texture;
+ }
+}
+
+TexturePtr
+TextureManager::create_image_texture_raw(const std::string& filename)
+{
+ SDLSurfacePtr image(IMG_Load_RW(get_physfs_SDLRWops(filename), 1));
+ if (!image)
+ {
+ std::ostringstream msg;
+ msg << "Couldn't load image '" << filename << "' :" << SDL_GetError();
+ throw std::runtime_error(msg.str());
+ }
+ else
+ {
+ TexturePtr result = VideoSystem::new_texture(image.get());
+ result->set_filename(filename);
+ return result;
+ }
+}
+
+TexturePtr
+TextureManager::create_dummy_texture()
+{
+ const std::string dummy_texture_fname = "images/engine/missing.png";
+
+ // on error, try loading placeholder file
+ try
+ {
+ TexturePtr tex = create_image_texture_raw(dummy_texture_fname);
+ return tex;
+ }
+ catch (const std::exception& err)
+ {
+ // on error (when loading placeholder), try using empty surface,
+ // when that fails to, just give up
+ SDLSurfacePtr image(SDL_CreateRGBSurface(0, 1024, 1024, 8, 0, 0, 0, 0));
+ if (!image)
+ {
+ throw err;
+ }
+ else
+ {
+ TexturePtr result = VideoSystem::new_texture(image.get());
+ result->set_filename("-dummy-texture-.png");
+ log_warning << "Couldn't load texture '" << dummy_texture_fname << "' (now using empty one): " << err.what() << std::endl;
+ return result;
+ }
+ }
+}
+
+#ifdef HAVE_OPENGL