Fixed the scrolling issue. Forgot that the DrawingContext used by gradient was global...
[supertux.git] / src / background.cpp
index 1effc16..fcf91f5 100644 (file)
@@ -16,8 +16,8 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#include "background.h"
 
+#include "background.h"
 #include "globals.h"
 #include "camera.h"
 #include "screen/drawing_context.h"
@@ -95,13 +95,26 @@ Background::set_gradient(Color top, Color bottom)
   type = GRADIENT;
   gradient_top = top;
   gradient_bottom = bottom;
+
+  delete image;
+  image = new Surface(top, bottom, screen->w, screen->h);
 }
 
 void
 Background::draw(DrawingContext& context)
 {
   if(type == GRADIENT) {
-    context.draw_gradient(gradient_top, gradient_bottom, LAYER_BACKGROUND0);
+    /* In case we are using OpenGL just draw the gradient, else (software mode)
+        use the cache. */
+    if(use_gl)
+      context.draw_gradient(gradient_top, gradient_bottom, LAYER_BACKGROUND0);
+    else
+      {
+      context.push_transform();
+      context.set_translation(Vector(0, 0));
+      context.draw_surface(image, Vector(0, 0), LAYER_BACKGROUND0);
+      context.pop_transform();
+      }
   } else if(type == IMAGE) {
     int sx = int(-context.get_translation().x * speed)
       % image->w - image->w;