fix
[supertux.git] / src / video / surface.cpp
index fb3e8a0..a650b4f 100644 (file)
 #include <SDL_image.h>
 
 #include "gameconfig.h"
+#include "physfs/physfs_sdl.h"
 #include "video/surface.h"
 #include "video/screen.h"
-#include "app/globals.h"
-#include "app/setup.h"
-
-using namespace SuperTux;
 
 Surface::Surfaces Surface::surfaces;
 
@@ -141,7 +138,7 @@ static int power_of_two(int input)
 }
 
 Surface::Surface(SDL_Surface* surf, bool use_alpha)
-    : data(surf, use_alpha), w(0), h(0)
+    : impl(0), data(surf, use_alpha), w(0), h(0)
 {
   impl = data.create();
   if (impl)
@@ -153,7 +150,7 @@ Surface::Surface(SDL_Surface* surf, bool use_alpha)
 }
 
 Surface::Surface(const std::string& file, bool use_alpha)
-    : data(file, use_alpha), w(0), h(0)
+    : impl(0), data(file, use_alpha), w(0), h(0)
 {
   impl = data.create();
   if (impl)
@@ -165,7 +162,7 @@ Surface::Surface(const std::string& file, bool use_alpha)
 }
 
 Surface::Surface(const std::string& file, int x, int y, int w_, int h_, bool use_alpha)
-    : data(file, x, y, w_, h_, use_alpha), w(0), h(0)
+    : impl(0), data(file, x, y, w_, h_, use_alpha), w(0), h(0)
 {
   impl = data.create();
   if (impl)
@@ -177,7 +174,7 @@ Surface::Surface(const std::string& file, int x, int y, int w_, int h_, bool use
 }
 
 Surface::Surface(Color top_background, Color bottom_background, int w_, int h_)
-    : data(top_background, bottom_background, w_, h_), w(0), h(0)
+    : impl(0), data(top_background, bottom_background, w_, h_), w(0), h(0)
 {
   impl = data.create();
   if (impl)
@@ -299,9 +296,8 @@ sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h,
   SDL_Surface * temp;
   SDL_Surface * conv;
 
-  temp = IMG_Load(file.c_str());
-
-  if (temp == NULL) {
+  temp = IMG_Load_RW(get_physfs_SDLRWops(file), true);
+  if (temp == 0) {
     std::stringstream msg;
     msg << "Couldn't load '" << file << "': " << SDL_GetError();
     throw std::runtime_error(msg.str());
@@ -349,9 +345,8 @@ sdl_surface_from_file(const std::string& file, bool use_alpha)
   SDL_Surface* sdl_surface;
   SDL_Surface* temp;
 
-  temp = IMG_Load(file.c_str());
-
-  if (temp == NULL) {
+  temp = IMG_Load_RW(get_physfs_SDLRWops(file), true);
+  if (temp == 0) {
     std::stringstream msg;
     msg << "Couldn't load file '" << file << "': " << SDL_GetError();
     throw std::runtime_error(msg.str());
@@ -458,11 +453,13 @@ sdl_surface_from_gradient(Color top, Color bottom, int w, int h)
 //---------------------------------------------------------------------------
 
 SurfaceImpl::SurfaceImpl()
+  : sdl_surface(0)
 {}
 
 SurfaceImpl::~SurfaceImpl()
 {
-  SDL_FreeSurface(sdl_surface);
+  if(sdl_surface != 0)
+    SDL_FreeSurface(sdl_surface);
 }
 
 SDL_Surface* SurfaceImpl::get_sdl_surface() const
@@ -554,7 +551,7 @@ SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex)
   // is present store in RGB instead of RGBA, this saves a few bytes
   // of memory, but much more importantly it makes the game look
   // *much* better in 16bit color mode
-  int internal_format = GL_RGB10_A2;
+  int internal_format = GL_RGBA;
   bool has_alpha = false;
 
   unsigned char* buf = static_cast<unsigned char*>(conv->pixels);