modified: CMakeLists.txt
authorBenjamin Leduc <benjaminleduc@87.239.146.195.dynamic.adsl.abo.nordnet.fr>
Sat, 24 Aug 2013 15:36:17 +0000 (17:36 +0200)
committerBenjamin Leduc <benjaminleduc@87.239.146.195.dynamic.adsl.abo.nordnet.fr>
Sat, 24 Aug 2013 15:36:17 +0000 (17:36 +0200)
modified:   external/squirrel/squirrel/sqdebug.cpp
modified:   src/control/joystickkeyboardcontroller.cpp
modified:   src/control/joystickkeyboardcontroller.hpp
modified:   src/gui/button.cpp
modified:   src/gui/button.hpp
modified:   src/gui/button_group.cpp
modified:   src/main.cpp
modified:   src/physfs/physfs_sdl.cpp
modified:   src/scripting/functions.cpp
modified:   src/supertux/console.cpp
modified:   src/supertux/main.cpp
modified:   src/supertux/menu/joystick_menu.cpp
modified:   src/supertux/menu/keyboard_menu.cpp
modified:   src/supertux/menu/keyboard_menu.hpp
modified:   src/supertux/screen_manager.cpp
modified:   src/video/gl/gl_renderer.cpp
modified:   src/video/sdl/sdl_renderer.cpp
modified:   src/video/texture_manager.cpp
git add src/SDL2/

19 files changed:
CMakeLists.txt
external/squirrel/squirrel/sqdebug.cpp
src/control/joystickkeyboardcontroller.cpp
src/control/joystickkeyboardcontroller.hpp
src/gui/button.cpp
src/gui/button.hpp
src/gui/button_group.cpp
src/main.cpp
src/physfs/physfs_sdl.cpp
src/scripting/functions.cpp
src/supertux/console.cpp
src/supertux/main.cpp
src/supertux/menu/joystick_menu.cpp
src/supertux/menu/keyboard_menu.cpp
src/supertux/menu/keyboard_menu.hpp
src/supertux/screen_manager.cpp
src/video/gl/gl_renderer.cpp
src/video/sdl/sdl_renderer.cpp
src/video/texture_manager.cpp

index c443eea..ef54955 100644 (file)
@@ -66,12 +66,12 @@ FIND_PACKAGE(Boost REQUIRED)
 INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIR})
 LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
 
-FIND_PACKAGE(SDL REQUIRED)
-INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
+#FIND_PACKAGE(SDL REQUIRED)
+INCLUDE_DIRECTORIES("src/SDL2/")
 SET(HAVE_SDL TRUE)
 
-FIND_PACKAGE(SDL_image REQUIRED)
-INCLUDE_DIRECTORIES(${SDLIMAGE_INCLUDE_DIR})
+#FIND_PACKAGE(SDL_image REQUIRED)
+#INCLUDE_DIRECTORIES(${SDLIMAGE_INCLUDE_DIR})
 
 OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
 IF(ENABLE_OPENGL)
index 14f7f64..68cad62 100644 (file)
@@ -74,7 +74,7 @@ SQString *SQVM::PrintObjVal(const SQObject &o)
        switch(type(o)) {
        case OT_STRING: return _string(o);
        case OT_INTEGER:
-               scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%d"), _integer(o));
+               scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%ld"), _integer(o));
                return SQString::Create(_ss(this), _spval);
                break;
        case OT_FLOAT:
index 6c9e9c0..f225745 100644 (file)
@@ -28,6 +28,7 @@
 #include "supertux/menu/keyboard_menu.hpp"
 #include "util/gettext.hpp"
 #include "util/writer.hpp"
+//#include <SDL_keycode.h> // add by giby
 
 JoystickKeyboardController::JoystickKeyboardController() :
   controller(),
@@ -138,12 +139,12 @@ JoystickKeyboardController::updateAvailableJoysticks()
       SDL_Joystick* joystick = SDL_JoystickOpen(i);
       bool good = true;
       if(SDL_JoystickNumButtons(joystick) < 2) {
-        log_info << "Joystick " << i << ": " << SDL_JoystickName(i) << " has less than 2 buttons" << std::endl;
+        log_info << _("Joystick ") << i << ": " << SDL_JoystickID(i) << _(" has less than 2 buttons") << std::endl;
         good = false;
       }
       if(SDL_JoystickNumAxes(joystick) < 2
          && SDL_JoystickNumHats(joystick) == 0) {
-        log_info << "Joystick " << i << ": " << SDL_JoystickName(i) << " has less than 2 axes and no hat" << std::endl;
+        log_info << _("Joystick ") << i << ": " << SDL_JoystickID(i) << _(" has less than 2 axes and no hat") << std::endl;
         good = false;
       }
       if(!good) {
@@ -196,10 +197,10 @@ JoystickKeyboardController::read(const Reader& lisp)
         const lisp::Lisp* map = iter.lisp();
         map->get("key", key);
         map->get("control", control);
-        if(key < SDLK_FIRST || key >= SDLK_LAST) {
-          log_info << "Invalid key '" << key << "' in keymap" << std::endl;
-          continue;
-        }
+//        if(key < SDLK_FIRST || key >= SDLK_LAST) {
+//          log_info << "Invalid key '" << key << "' in keymap" << std::endl;
+//          continue;
+//        }
 
         int i = 0;
         for(i = 0; Controller::controlNames[i] != 0; ++i) {
@@ -210,18 +211,18 @@ JoystickKeyboardController::read(const Reader& lisp)
           log_info << "Invalid control '" << control << "' in keymap" << std::endl;
           continue;
         }
-        keymap[SDLKey(key)] = Control(i);
+        keymap[SDL_Keycode(key)] = Control(i);
       }
     }
   }
 
-  const lisp::Lisp* joystick_lisp = lisp.get_lisp("joystick");
+  const lisp::Lisp* joystick_lisp = lisp.get_lisp(_("joystick"));
   if(joystick_lisp) {
     joystick_lisp->get("dead-zone", dead_zone);
     joystick_lisp->get("jump-with-up", jump_with_up_joy);
     lisp::ListIterator iter(joystick_lisp);
     while(iter.next()) {
-      if(iter.item() == "map") {
+      if(iter.item() == _("map")) {
         int button = -1;
         int axis   = 0;
         int hat    = -1;
@@ -510,7 +511,7 @@ JoystickKeyboardController::process_key_event(const SDL_KeyboardEvent& event)
       process_menu_key_event(event);
     } else if(key_mapping == keymap.end()) {
       // default action: update controls
-      //log_debug << "Key " << event.key.keysym.sym << " is unbound" << std::endl;
+      //log_debug << "Key " << event.key.SDL_Keycode.sym << " is unbound" << std::endl;
     } else {
       Control control = key_mapping->second;
       bool value = (event.type == SDL_KEYDOWN);
@@ -562,10 +563,10 @@ JoystickKeyboardController::process_console_key_event(const SDL_KeyboardEvent& e
       Console::instance->move_cursor(+1);
       break;
     default:
-      int c = event.keysym.unicode;
-      if ((c >= 32) && (c <= 126)) {
-        Console::instance->input((char)c);
-      }
+   //   int c = SDL_GetScancodeName(event.keysym);
+ //     if ((c >= 32) && (c <= 126)) { <Xeek> you need to move that "unicode" source we were originaly talkinga bout into a new function that gets called from the SDL_TextInput event..... you'll be adding that event.
+   //     Console::instance->input((char)c);
+     // }
       break;
   }
 }
@@ -689,7 +690,7 @@ JoystickKeyboardController::bind_joybutton(JoyId joy_id, int button, Control con
 }
 
 void
-JoystickKeyboardController::bind_key(SDLKey key, Control control)
+JoystickKeyboardController::bind_key(SDL_Keycode key, Control control)
 {
   // remove all previous mappings for that control and for that key
   for(KeyMap::iterator i = keymap.begin();
@@ -714,7 +715,7 @@ JoystickKeyboardController::bind_key(SDLKey key, Control control)
 void
 JoystickKeyboardController::print_joystick_mappings()
 {
-  std::cout << "Joystick Mappings" << std::endl;
+  std::cout << _("Joystick Mappings") << std::endl;
   std::cout << "-----------------" << std::endl;
   for(AxisMap::iterator i = joy_axis_map.begin(); i != joy_axis_map.end(); ++i) {
     std::cout << "Axis: " << i->first.second << " -> " << i->second << std::endl;
@@ -730,7 +731,7 @@ JoystickKeyboardController::print_joystick_mappings()
   std::cout << std::endl;
 }
 
-SDLKey
+SDL_Keycode
 JoystickKeyboardController::reversemap_key(Control c)
 {
   for(KeyMap::iterator i = keymap.begin(); i != keymap.end(); ++i) {
index 00c4c2f..1c19360 100644 (file)
@@ -20,7 +20,7 @@
 #include "control/controller.hpp"
 
 #include <SDL.h>
-
+#include <SDL_keycode.h> // add by giby
 #include <map>
 #include <string>
 #include <vector>
@@ -33,7 +33,9 @@ class KeyboardMenu;
 class JoystickMenu;
 class Controller;
 
-class JoystickKeyboardController
+    //SDL_JoystickID myID = SDL_JoystickInstanceID(myOpenedStick);
+
+class JoystickKeyboardController // http://wiki.libsdl.org/moin.fcg/SDL_Joystick for info 
 {
 private:
   friend class KeyboardMenu;
@@ -42,7 +44,7 @@ private:
   typedef Controller::Control Control;
   typedef Uint8 JoyId;
 
-  typedef std::map<SDLKey, Control> KeyMap;
+  typedef std::map<SDL_Keycode, Control> KeyMap;
   typedef std::map<std::pair<JoyId, int>, Control> ButtonMap;
   typedef std::map<std::pair<JoyId, int>, Control> AxisMap;
   typedef std::map<std::pair<JoyId, int>, Control> HatMap;
@@ -74,7 +76,7 @@ private:
 
   void print_joystick_mappings();
 
-  SDLKey reversemap_key(Control c);
+  SDL_Keycode reversemap_key(Control c);
   int    reversemap_joybutton(Control c);
   int    reversemap_joyaxis(Control c);
   int    reversemap_joyhat(Control c);
@@ -84,9 +86,9 @@ private:
   void bind_joybutton(JoyId joy_id, int button, Control c);
   void bind_joyaxis(JoyId joy_id, int axis, Control c);
   void bind_joyhat(JoyId joy_id, int dir, Control c);
-  void bind_key(SDLKey key, Control c);
+  void bind_key(SDL_Keycode key, Control c);
 
-  void set_joy_controls(Control id, bool value);
+  void set_joy_controls(Control id, bool value); 
 
 private:
   Controller *controller;
index 587b1e3..8561dd4 100644 (file)
@@ -21,7 +21,7 @@
 
 FontPtr Button::info_font;
 
-Button::Button(SurfacePtr image_, std::string info_, SDLKey binding_) :
+Button::Button(SurfacePtr image_, std::string info_, SDL_Keycode binding_) :
   pos(),
   size(),
   image(),
index aeeb71c..e0229b4 100644 (file)
@@ -38,7 +38,7 @@ enum {
 class Button
 {
 public:
-  Button(SurfacePtr image_, std::string info_, SDLKey binding_);
+  Button(SurfacePtr image_, std::string info_, SDL_Keycode binding_);
   Button(const Button& rhs);
   ~Button();
 
@@ -57,7 +57,7 @@ private:
   Vector size;
 
   SurfacePtr image;
-  SDLKey binding;
+  SDL_Keycode binding;
 
   int id;
   int state;
index 0a2c7ed..2336489 100644 (file)
@@ -119,13 +119,13 @@ ButtonGroup::event(SDL_Event &event)
 
       caught_event = true;
 
-      if(event.button.button == SDL_BUTTON_WHEELUP)
+      if(event.button.button == SDL_MOUSEBUTTONUP)
       {
         row--;
         if(row < 0)
           row = 0;
       }
-      else if(event.button.button == SDL_BUTTON_WHEELDOWN)
+      else if(event.button.button == SDL_MOUSEBUTTONDOWN)
       {
         row++;
         if(row > (int)((buttons.size()-buttons_pair_nb)/buttons_box.x) - (int)buttons_box.y +
index 2b4bd21..6acebfd 100644 (file)
@@ -14,7 +14,7 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <SDL.h>
+#include "SDL2/SDL.h"
 
 #include "supertux/main.hpp"
 
index 82c7869..b751a8e 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "util/log.hpp"
 
-static int funcSeek(struct SDL_RWops* context, int offset, int whence)
+static Sint64 funcSeek(struct SDL_RWops* context, Sint64 offset, int whence)
 {
   PHYSFS_file* file = (PHYSFS_file*) context->hidden.unknown.data1;
   int res;
@@ -50,7 +50,7 @@ static int funcSeek(struct SDL_RWops* context, int offset, int whence)
   return (int) PHYSFS_tell(file);
 }
 
-static int funcRead(struct SDL_RWops* context, void* ptr, int size, int maxnum)
+static size_t  funcRead(struct SDL_RWops* context, void* ptr, size_t  size, size_t  maxnum)
 {
   PHYSFS_file* file = (PHYSFS_file*) context->hidden.unknown.data1;
 
index 5a03f37..cb4260e 100644 (file)
@@ -271,8 +271,10 @@ void camera()
   log_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl;
 }
 
-void set_gamma(float gamma) {
-  SDL_SetGamma(gamma, gamma, gamma);
+       SDL_Window *screen;  
+       
+void set_gamma(const Uint16 * gamma) {
+  SDL_SetWindowGammaRamp(screen,gamma, gamma, gamma);
 }
 
 void quit()
index 883ec09..000a978 100644 (file)
@@ -431,7 +431,7 @@ Console::show()
   focused = true;
   height = 256;
   alpha = 1.0;
-  SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+//  SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // Useless in SDL2 :  if you want to disable repeat, then you need to check if the key was repeated and ignore it.
 }
 
 void
@@ -451,7 +451,7 @@ Console::hide()
   // clear input buffer
   inputBuffer = "";
   inputBufferPosition = 0;
-  SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
// SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
 }
 
 void
index d89420f..9f0d8f2 100644 (file)
@@ -433,7 +433,9 @@ Main::init_sdl()
   // just to be sure
   atexit(SDL_Quit);
 
-  SDL_EnableUNICODE(1);
+ // SDL_EnableUNICODE(1); //old code, mofif by giby 
+ //   SDL_JoystickID myID = SDL_JoystickInstanceID(myOpenedStick);
+  
 
   // wait 100ms and clear SDL event queue because sometimes we have random
   // joystick events in the queue on startup...
@@ -460,13 +462,14 @@ Main::init_video()
   // FIXME: Add something here
   SCREEN_WIDTH  = 800;
   SCREEN_HEIGHT = 600;
-
+    
+/*    SDL_Window *window;        // Declare a pointer to an SDL_Window
   context_pointer->init_renderer();
-  g_screen = SDL_GetVideoSurface();
+  g_screen = SDL_GetWindowSurface(*window);*/
 
-  SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
// SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
 
-  // set icon
+ /* // set icon -- Original part B4 SDL2
 #ifdef MACOSX
   const char* icon_fname = "images/engine/icons/supertux-256x256.png";
 #else
@@ -480,12 +483,51 @@ Main::init_video()
     log_warning << "Couldn't load icon '" << icon_fname << "': " << err.what() << std::endl;
   }
   if(icon != 0) {
-    SDL_WM_SetIcon(icon, 0);
+    SDL_WM_SetIcon(icon, 0); //now  SDL_SetWindowIcon(window, surface);  if needed 
     SDL_FreeSurface(icon);
   }
   else {
     log_warning << "Couldn't load icon '" << icon_fname << "'" << std::endl;
   }
+    */
+    
+  //  SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
+    
+    // set icon
+#ifdef MACOSX
+    const char* icon_fname = "images/engine/icons/supertux-256x256.png";
+#else
+    const char* icon_fname = "images/engine/icons/supertux.xpm";
+#endif
+    SDL_Window* icon;
+    try {
+        //icon = IMG_Load_RW(get_physfs_SDLRWops(icon_fname), true);
+    } catch (const std::runtime_error& err) {
+        icon = 0;
+        log_warning << "Couldn't load icon '" << icon_fname << "': " << err.what() << std::endl;
+    }
+    if(icon != 0) {
+     //   SDL_SetWindowIcon(icon, 0); //now  SDL_SetWindowIcon(window, surface);  if needed
+      //  SDL_FreeSurface(icon);
+    }
+    else {
+        log_warning << "Couldn't load icon '" << icon_fname << "'" << std::endl;
+    }
+    
+    
+   /* // set icon
+#ifdef MACOSX
+    const char* icon_fname = "images/engine/icons/supertux-256x256.png";
+#else
+    const char* icon_fname = "images/engine/icons/supertux.xpm";
+#endif
+    
+    SDL_Window icon = SDL_CreateWindow(PACKAGE_NAME " " PACKAGE_VERSION,
+                                          SDL_WINDOWPOS_UNDEFINED,
+                                          SDL_WINDOWPOS_UNDEFINED,
+                                          640, 480,
+                                          SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
+   // not sure of that */
 
   SDL_ShowCursor(0);
 
index c6bacb3..38733ff 100644 (file)
@@ -59,12 +59,13 @@ JoystickMenu::recreateMenu()
   }
   add_inactive(-1,"");
   add_entry(SCAN_JOYSTICKS, _("Scan for Joysticks"));
-
-  //Show Joysticks currently activated:
+  //Show Joysticks currently activated: //edit by giby
+    joy = SDL_JoystickOpen(0)
+    if (SDL_NumJoysticks() > 0) {joy = SDL_JoystickOpen(0);
   for(std::vector<SDL_Joystick*>::iterator i = controller->joysticks.begin();
       i != controller->joysticks.end(); ++i) {
     if(*i != 0)
-      add_inactive(-1, SDL_JoystickName(SDL_JoystickIndex(*i)) );
+      add_inactive(-1, SDL_JoystickName(joy) );
   }
 
   add_hl();
@@ -73,7 +74,7 @@ JoystickMenu::recreateMenu()
 }
 
 std::string
-JoystickMenu::get_button_name(int button)
+/*JoystickMenu::get_button_name(int button)
 {
   if(button < 0)
     return _("None");
@@ -81,7 +82,7 @@ JoystickMenu::get_button_name(int button)
   std::ostringstream name;
   name << "Button " << button;
   return name.str();
-}
+}*/
 
 void
 JoystickMenu::menu_action(MenuItem* item)
index 883adef..bbdd1cf 100644 (file)
@@ -49,7 +49,7 @@ KeyboardMenu::~KeyboardMenu()
 {}
 
 std::string
-KeyboardMenu::get_key_name(SDLKey key)
+KeyboardMenu::get_key_name(SDL_Keycode key)
 {
   switch(key) {
     case SDLK_UNKNOWN:
@@ -79,7 +79,7 @@ KeyboardMenu::get_key_name(SDLKey key)
     case SDLK_LALT:
       return _("Left Alt");
     default:
-      return SDL_GetKeyName((SDLKey) key);
+      return SDL_GetKeyName((SDL_Keycode) key);
   }
 }
 
index f4435d1..c83cb4b 100644 (file)
@@ -28,7 +28,7 @@ public:
   ~KeyboardMenu();
 
   void update();
-  std::string get_key_name(SDLKey key);
+  std::string SDL_GetKeyName(SDL_Keycode* key);
   virtual void menu_action(MenuItem* item);
   JoystickKeyboardController* controller;
   void check_menu() {}
index ffd9599..98e8740 100644 (file)
@@ -190,7 +190,7 @@ void
 ScreenManager::process_events()
 {
   g_jk_controller->update();
-  Uint8* keystate = SDL_GetKeyState(NULL);
+const Uint8 *keystate =  SDL_GetKeyboardState(NULL); //edited by giby
   SDL_Event event;
   while(SDL_PollEvent(&event)) 
   {
@@ -205,10 +205,10 @@ ScreenManager::process_events()
         quit();
         break;
               
-      case SDL_VIDEORESIZE:
-        Renderer::instance()->resize(event.resize.w, event.resize.h);
-        MenuManager::recalc_pos();
-        break;
+    //  case SDL_ResizeEvent: //edit by giby
+    //    Renderer::instance()->resize(event.resize.w, event.resize.h);
+    //    MenuManager::recalc_pos();
+    //    break;
             
       case SDL_KEYDOWN:
         if (event.key.keysym.sym == SDLK_F10)
@@ -221,7 +221,7 @@ ScreenManager::process_events()
           Renderer::instance()->apply_config();
           MenuManager::recalc_pos();
         }
-        else if (event.key.keysym.sym == SDLK_PRINT ||
+        else if (event.key.keysym.sym == SDLK_PRINTSCREEN ||
                  event.key.keysym.sym == SDLK_F12)
         {
           take_screenshot();
index 0e66433..18e3874 100644 (file)
@@ -1,5 +1,6 @@
 //  SuperTux
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//     Updated by GiBy 2013 for SDL2 <giby_the_kid@yahoo.fr>
 //
 //  This program is free software: you can redistribute it and/or modify
 //  it under the terms of the GNU General Public License as published by
@@ -19,6 +20,9 @@
 #include <iomanip>
 #include <iostream>
 #include <physfs.h>
+#include "SDL2/SDL.h"
+//#include "SDL/SDL.h"
+//#include "SDL/SDL_opengl.h"
 
 #include "supertux/gameconfig.hpp"
 #include "supertux/globals.hpp"
@@ -56,16 +60,16 @@ GLRenderer::GLRenderer() :
 #ifdef SDL_GL_SWAP_CONTROL
   if(config->try_vsync) {
     /* we want vsync for smooth scrolling */
-    SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
+     SDL_GL_SetSwapInterval(1);
   }
 #endif
 
-  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+   SDL_GL_SetSwapInterval(SDL_GL_DOUBLEBUFFER, 1);
 
   // FIXME: Hu? 16bit rendering?
-  SDL_GL_SetAttribute(SDL_GL_RED_SIZE,   5);
-  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
-  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,  5);
+   SDL_GL_SetSwapInterval(5);
+   SDL_GL_SetSwapInterval(5);
+   SDL_GL_SetSwapInterval(5);
 
   if(g_config->use_fullscreen)
   {
@@ -442,7 +446,7 @@ void
 GLRenderer::flip()
 {
   assert_gl("drawing");
-  SDL_GL_SwapBuffers();
+  SDL_GL_SwapWindow(screen)();
 }
 
 void
@@ -450,7 +454,7 @@ GLRenderer::resize(int w, int h)
 {
   // This causes the screen to go black, which is annoying, but seems
   // unavoidable with SDL at the moment
-  SDL_SetVideoMode(w, h, 0, SDL_OPENGL | SDL_RESIZABLE);
+  SDL_CreateWindow(SDL_GL_CreateContext(w, h, 0, SDL_OPENGL | SDL_RESIZABLE));
 
   g_config->window_size = Size(w, h);
 
@@ -559,9 +563,9 @@ GLRenderer::apply_config()
 
     // Clear both buffers so that we get a clean black border without junk
     glClear(GL_COLOR_BUFFER_BIT);
-    SDL_GL_SwapBuffers();
+    SDL_GL_SwapWindow(screen);
     glClear(GL_COLOR_BUFFER_BIT);
-    SDL_GL_SwapBuffers();
+    SDL_GL_SwapWindow(screen);
 
     glViewport(std::max(0, (screen_size.width  - new_size.width)  / 2),
                std::max(0, (screen_size.height - new_size.height) / 2),
@@ -597,7 +601,7 @@ GLRenderer::apply_video_mode(const Size& size, bool fullscreen)
       flags |= SDL_RESIZABLE;
     }
 
-    if (SDL_Surface *screen = SDL_SetVideoMode(size.width, size.height, 0, flags))
+    if (SDL_Surface *screen = SDL_CreateWindow(SDL_GL_CreateContext( size.width, size.height, 0, flags)))
     {
       screen_size = Size(screen->w, screen->h);
       fullscreen_active = fullscreen; 
index 39e8860..ff95516 100644 (file)
@@ -1,5 +1,6 @@
 //  SuperTux
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//     Updated by GiBy 2013 for SDL2 <giby_the_kid@yahoo.fr>
 //
 //  This program is free software: you can redistribute it and/or modify
 //  it under the terms of the GNU General Public License as published by
 #include <physfs.h>
 #include <sstream>
 #include <stdexcept>
+#include "SDL2/SDL_video.h"
+//#include "SDL/SDL.h"
+//#include "SDL/SDL_opengl.h"
+
 
 namespace {
 
@@ -127,15 +132,21 @@ SDLRenderer::SDLRenderer() :
   log_info << "Software to hardware blits with alpha are " << (info->blit_sw_A ? "" : "not ") << "accelerated." << std::endl;
   log_info << "Color fills are " << (info->blit_fill ? "" : "not ") << "accelerated." << std::endl;
 
-  int flags = SDL_SWSURFACE | SDL_ANYFORMAT;
-  if(g_config->use_fullscreen)
-    flags |= SDL_FULLSCREEN;
// int flags = SDL_SWSURFACE | SDL_ANYFORMAT;
// if(g_config->use_fullscreen)
//   flags |= SDL_FULLSCREEN;
     
   int width  = 800; //FIXME: config->screenwidth;
   int height = 600; //FIXME: config->screenheight;
-
-  screen = SDL_SetVideoMode(width, height, 0, flags);
-  if(screen == 0) {
+       
+       SDL_Window *window;        // Declare a pointer to an SDL_Window
+       
+       SDL_Init(SDL_INIT_VIDEO);   // Initialize SDL2
+
+  window = SDL_CreateWindow("SuperTux",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,width, height, 0, SDL_WINDOW_OPENGL );
+         SDL_GLContext glcontext = SDL_GL_CreateContext(window);
+       
+  if(window == 0) {
     std::stringstream msg;
     msg << "Couldn't set video mode (" << width << "x" << height
         << "): " << SDL_GetError();
index 0c77a5a..b64fcee 100644 (file)
@@ -158,10 +158,10 @@ TextureManager::create_image_texture_raw(const std::string& filename, const Rect
     throw std::runtime_error("SDL_CreateRGBSurfaceFrom() call failed");
   }
 
-  if (image->format->palette)
/* if (image->format->palette)
   { // copy the image palette to subimage if present
-    SDL_SetColors(subimage.get(), image->format->palette->colors, 0, image->format->palette->ncolors);
-  }
+    SDL_SetSurfacePalette(subimage.get(), image->format->palette->colors); //edited by giby 
+  } */
 
   return VideoSystem::new_texture(subimage.get());
 }