Skip to content

Commit

Permalink
Made code compile, not work, with SDL2, old code that needs work is d…
Browse files Browse the repository at this point in the history
…isabled and marked with "#ifdef OLD_SDL1"
  • Loading branch information
Grumbel committed Jul 30, 2014
1 parent 6ae5258 commit a5e96e2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/scripting/functions.cpp
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions src/supertux/main.cpp
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/supertux/menu/joystick_menu.cpp
Expand Up @@ -76,7 +76,6 @@ JoystickMenu::recreateMenu()
update();
}

/*
std::string
JoystickMenu::get_button_name(int button)
{
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/video/gl/gl_lightmap.cpp
Expand Up @@ -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;
Expand Down
29 changes: 21 additions & 8 deletions src/video/gl/gl_renderer.cpp
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -573,11 +581,13 @@ GLRenderer::apply_config()
SCREEN_HEIGHT = static_cast<int>(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),
Expand All @@ -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;
}
Expand All @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/video/gl/gl_texture.cpp
Expand Up @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions src/video/sdl/sdl_renderer.cpp
Expand Up @@ -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)
Expand All @@ -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);

Expand Down Expand Up @@ -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)
{
Expand All @@ -318,13 +321,15 @@ SDLRenderer::draw_surface_part(const DrawingRequest& request)
transform = apply_alpha(transform, request.alpha);
}*/
}
#endif

SDL_BlitSurface(transform, &src_rect, screen, &dst_rect);

if(request.alpha != 1.0)
{
if(!transform->format->Amask)
{
#ifdef OLD_SDL1
if(alpha == 255)
{
SDL_SetSurfaceAlphaMod(transform, 0);
Expand All @@ -333,6 +338,7 @@ SDLRenderer::draw_surface_part(const DrawingRequest& request)
{
SDL_SetSurfaceAlphaMod(transform, alpha);
}
#endif
}
/*else
{
Expand Down
14 changes: 14 additions & 0 deletions src/video/sdl/sdl_texture.cpp
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -342,6 +345,7 @@ SDL_Surface *horz_flip(SDL_Surface *src)
{
SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
}
#endif
}
return dst;
}
Expand Down Expand Up @@ -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)
Expand All @@ -393,6 +398,7 @@ SDL_Surface *vert_flip(SDL_Surface *src)
SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
}
}
#endif
return dst;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit a5e96e2

Please sign in to comment.