From a5e96e2c986da8851ba03f1eed359fa8becad804 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Wed, 30 Jul 2014 03:28:59 +0200 Subject: [PATCH] Made code compile, not work, with SDL2, old code that needs work is disabled and marked with "#ifdef OLD_SDL1" --- src/scripting/functions.cpp | 4 +++- src/supertux/main.cpp | 3 +-- src/supertux/menu/joystick_menu.cpp | 3 +-- src/video/gl/gl_lightmap.cpp | 2 ++ src/video/gl/gl_renderer.cpp | 29 +++++++++++++++++++++-------- src/video/gl/gl_texture.cpp | 2 +- src/video/sdl/sdl_renderer.cpp | 6 ++++++ src/video/sdl/sdl_texture.cpp | 14 ++++++++++++++ 8 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index cb4260e051e..689275f7866 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -273,8 +273,10 @@ void camera() SDL_Window *screen; -void set_gamma(const Uint16 * gamma) { +void set_gamma(float gamma) { +#ifdef OLD_SDL1 SDL_SetWindowGammaRamp(screen,gamma, gamma, gamma); +#endif } void quit() diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index c96690b3841..70454661950 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -503,11 +503,10 @@ Main::init_video() #else const char* icon_fname = "images/engine/icons/supertux.xpm"; #endif - SDL_Window* icon; + SDL_Window* icon = 0; 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) { diff --git a/src/supertux/menu/joystick_menu.cpp b/src/supertux/menu/joystick_menu.cpp index 9c454a0e767..e4e1dcb243d 100644 --- a/src/supertux/menu/joystick_menu.cpp +++ b/src/supertux/menu/joystick_menu.cpp @@ -76,7 +76,6 @@ JoystickMenu::recreateMenu() update(); } -/* std::string JoystickMenu::get_button_name(int button) { @@ -86,7 +85,7 @@ JoystickMenu::get_button_name(int button) std::ostringstream name; name << "Button " << button; return name.str(); -}*/ +} void JoystickMenu::menu_action(MenuItem* item) diff --git a/src/video/gl/gl_lightmap.cpp b/src/video/gl/gl_lightmap.cpp index f8a67358d61..21412e7b9c3 100644 --- a/src/video/gl/gl_lightmap.cpp +++ b/src/video/gl/gl_lightmap.cpp @@ -49,7 +49,9 @@ GLLightmap::GLLightmap() : lightmap_uv_right(), lightmap_uv_bottom() { +#ifdef OLD_SDL1 screen = SDL_GetVideoSurface(); +#endif lightmap_width = SCREEN_WIDTH / LIGHTMAP_DIV; lightmap_height = SCREEN_HEIGHT / LIGHTMAP_DIV; diff --git a/src/video/gl/gl_renderer.cpp b/src/video/gl/gl_renderer.cpp index f2cec7e5d79..41575c05e34 100644 --- a/src/video/gl/gl_renderer.cpp +++ b/src/video/gl/gl_renderer.cpp @@ -47,11 +47,15 @@ GLRenderer::GLRenderer() : // unfortunately only newer SDLs have these infos. // This must be called before SDL_SetVideoMode() or it will return // the window size instead of the desktop size. +#ifdef OLD_SDL1 const SDL_VideoInfo *info = SDL_GetVideoInfo(); if (info) { - desktop_size = Size(info->current_w, info->current_h); + desktop_size = Size(info->current_w, info->current_h); } +#else + desktop_size = Size(1920, 1080); +#endif #endif if(texture_manager != 0) @@ -64,12 +68,14 @@ GLRenderer::GLRenderer() : } #endif +#ifdef OLD_SDL1 SDL_GL_SetSwapInterval(SDL_GL_DOUBLEBUFFER, 1); // FIXME: Hu? 16bit rendering? SDL_GL_SetSwapInterval(5); SDL_GL_SetSwapInterval(5); SDL_GL_SetSwapInterval(5); +#endif if(g_config->use_fullscreen) { @@ -458,15 +464,17 @@ void GLRenderer::flip() { assert_gl("drawing"); +#ifdef OLD_SDL1 SDL_GL_SwapWindow(screen)(); +#endif } void 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_CreateWindow(SDL_GL_CreateContext(w, h, 0, SDL_OPENGL | SDL_RESIZABLE)); +#ifdef OLD_SDL1 + SDL_CreateWindow(SDL_GL_CreateContext(w, h, 0, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE)); +#endif g_config->window_size = Size(w, h); @@ -573,11 +581,13 @@ GLRenderer::apply_config() SCREEN_HEIGHT = static_cast(max_size.height); } +#ifdef OLD_SDL1 // Clear both buffers so that we get a clean black border without junk glClear(GL_COLOR_BUFFER_BIT); SDL_GL_SwapWindow(screen); glClear(GL_COLOR_BUFFER_BIT); SDL_GL_SwapWindow(screen); +#endif glViewport(std::max(0, (screen_size.width - new_size.width) / 2), std::max(0, (screen_size.height - new_size.height) / 2), @@ -602,19 +612,21 @@ GLRenderer::apply_video_mode(const Size& size, bool fullscreen) // Only change video mode when its different from the current one if (screen_size != size || fullscreen_active != fullscreen) { - int flags = SDL_OPENGL; + int flags = SDL_WINDOW_OPENGL; if (fullscreen) { - flags |= SDL_FULLSCREEN; + flags |= SDL_WINDOW_FULLSCREEN; } else { - flags |= SDL_RESIZABLE; + flags |= SDL_WINDOW_RESIZABLE; } - if (SDL_Surface *screen = SDL_CreateWindow(SDL_GL_CreateContext( size.width, size.height, 0, flags))) +#ifdef OLD_SDL1 + if (SDL_Surface *screen = SDL_CreateWindow(size.width, size.height, 0, flags)) { + SDL_GL_CreateContext(screen); screen_size = Size(screen->w, screen->h); fullscreen_active = fullscreen; } @@ -624,6 +636,7 @@ GLRenderer::apply_video_mode(const Size& size, bool fullscreen) msg << "Couldn't set video mode " << size.width << "x" << size.height << ": " << SDL_GetError(); throw std::runtime_error(msg.str()); } +#endif } } diff --git a/src/video/gl/gl_texture.cpp b/src/video/gl/gl_texture.cpp index 9e2b70ddadd..edc8751846c 100644 --- a/src/video/gl/gl_texture.cpp +++ b/src/video/gl/gl_texture.cpp @@ -106,7 +106,7 @@ GLTexture::GLTexture(SDL_Surface* image) : throw std::runtime_error("Couldn't create texture: out of memory"); } - SDL_SetAlpha(image, 0, 0); + //SDL_SetAlpha(image, 0, 0); SDL_BlitSurface(image, 0, convert, 0); assert_gl("before creating texture"); diff --git a/src/video/sdl/sdl_renderer.cpp b/src/video/sdl/sdl_renderer.cpp index a929a353f87..ee05efc12d6 100644 --- a/src/video/sdl/sdl_renderer.cpp +++ b/src/video/sdl/sdl_renderer.cpp @@ -208,6 +208,7 @@ SDLRenderer::draw_surface(const DrawingRequest& request) dst_rect.y = (int) request.pos.y * numerator / denominator; Uint8 alpha = 0; +#ifdef OLD_SDL1 if(request.alpha != 1.0) { if(!transform->format->Amask) @@ -227,6 +228,7 @@ SDLRenderer::draw_surface(const DrawingRequest& request) transform = apply_alpha(transform, request.alpha); }*/ } +#endif SDL_BlitSurface(transform, src_rect, screen, &dst_rect); @@ -298,6 +300,7 @@ SDLRenderer::draw_surface_part(const DrawingRequest& request) dst_rect.x = (int) request.pos.x * numerator / denominator; dst_rect.y = (int) request.pos.y * numerator / denominator; +#ifdef OLD_SDL1 Uint8 alpha = 0; if(request.alpha != 1.0) { @@ -318,6 +321,7 @@ SDLRenderer::draw_surface_part(const DrawingRequest& request) transform = apply_alpha(transform, request.alpha); }*/ } +#endif SDL_BlitSurface(transform, &src_rect, screen, &dst_rect); @@ -325,6 +329,7 @@ SDLRenderer::draw_surface_part(const DrawingRequest& request) { if(!transform->format->Amask) { +#ifdef OLD_SDL1 if(alpha == 255) { SDL_SetSurfaceAlphaMod(transform, 0); @@ -333,6 +338,7 @@ SDLRenderer::draw_surface_part(const DrawingRequest& request) { SDL_SetSurfaceAlphaMod(transform, alpha); } +#endif } /*else { diff --git a/src/video/sdl/sdl_texture.cpp b/src/video/sdl/sdl_texture.cpp index b58f7cc57e2..978531f5230 100644 --- a/src/video/sdl/sdl_texture.cpp +++ b/src/video/sdl/sdl_texture.cpp @@ -282,6 +282,7 @@ SDL_Surface *scale(SDL_Surface *src, int numerator, int denominator) } if(!src->format->Amask) { +#ifdef OLD_SDL1 if(src->flags & SDL_SRCALPHA) { SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha); @@ -290,6 +291,7 @@ SDL_Surface *scale(SDL_Surface *src, int numerator, int denominator) { SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey); } +#endif } return dst; } @@ -334,6 +336,7 @@ SDL_Surface *horz_flip(SDL_Surface *src) } if(!src->format->Amask) { +#ifdef OLD_SDL1 if(src->flags & SDL_SRCALPHA) { SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha); @@ -342,6 +345,7 @@ SDL_Surface *horz_flip(SDL_Surface *src) { SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey); } +#endif } return dst; } @@ -382,6 +386,7 @@ SDL_Surface *vert_flip(SDL_Surface *src) { SDL_UnlockSurface(src); } +#ifdef OLD_SDL1 if(!src->format->Amask) { if(src->flags & SDL_SRCALPHA) @@ -393,6 +398,7 @@ SDL_Surface *vert_flip(SDL_Surface *src) SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey); } } +#endif return dst; } @@ -440,12 +446,14 @@ SDL_Surface *colorize(SDL_Surface *src, const Color &color) mapped = *(Uint32 *)srcpixel; break; } +#ifdef OLD_SDL1 if(src->format->Amask || !(src->flags & SDL_SRCCOLORKEY) || mapped != src->format->colorkey) { Uint8 r, g, b, a; SDL_GetRGBA(mapped, src->format, &r, &g, &b, &a); mapped = SDL_MapRGBA(dst->format, (r * red) >> 8, (g * green) >> 8, (b * blue) >> 8, a); } +#endif switch(bpp) { case 1: *dstpixel = mapped; @@ -480,6 +488,7 @@ SDL_Surface *colorize(SDL_Surface *src, const Color &color) } if(!src->format->Amask) { +#ifdef OLD_SDL1 if(src->flags & SDL_SRCALPHA) { SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha); @@ -488,6 +497,7 @@ SDL_Surface *colorize(SDL_Surface *src, const Color &color) { SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey); } +#endif } return dst; } @@ -501,6 +511,7 @@ SDL_Surface *colorize(SDL_Surface *src, const Color &color) * "SDL_SetColorKey". */ SDL_Surface *optimize(SDL_Surface *src) { +#ifdef OLD_SDL1 bool have_transparent = false; bool have_semi_trans = false; bool have_opaque = false; @@ -620,6 +631,9 @@ SDL_Surface *optimize(SDL_Surface *src) SDL_Surface *convert = SDL_DisplayFormat(dst); SDL_FreeSurface(dst); return convert; +#else + return 0; +#endif } /* SDL_Surface *optimize */ } /* namespace */