// 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 "video/sdl/sdl_renderer.hpp"
+#include "video/drawing_request.hpp"
+#include "video/sdl/sdl_surface_data.hpp"
+#include "video/sdl/sdl_texture.hpp"
+
#include <iomanip>
#include <iostream>
#include <physfs.h>
+#include <sstream>
+#include <stdexcept>
+#include "SDL2/SDL_video.h"
+//#include "SDL/SDL.h"
+//#include "SDL/SDL_opengl.h"
-#include "video/drawing_request.hpp"
-#include "video/sdl/sdl_surface_data.hpp"
-#include "video/sdl/sdl_texture.hpp"
namespace {
} // namespace
-SDLRenderer::SDLRenderer()
+SDLRenderer::SDLRenderer() :
+ screen(),
+ numerator(),
+ denominator()
{
- ::Renderer::instance_ = this;
+ Renderer::instance_ = this;
const SDL_VideoInfo *info = SDL_GetVideoInfo();
log_info << "Hardware surfaces are " << (info->hw_available ? "" : "not ") << "available." << std::endl;
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();
{
//FIXME: support parameters request.alpha, request.angle, request.blend
const Surface* surface = (const Surface*) request.request_data;
- SDLTexture *sdltexture = dynamic_cast<SDLTexture *>(surface->get_texture());
+ boost::shared_ptr<SDLTexture> sdltexture = boost::dynamic_pointer_cast<SDLTexture>(surface->get_texture());
SDLSurfaceData *surface_data = reinterpret_cast<SDLSurfaceData *>(surface->get_surface_data());
DrawingEffect effect = request.drawing_effect;
= (SurfacePartRequest*) request.request_data;
const Surface* surface = surfacepartrequest->surface;
- SDLTexture *sdltexture = dynamic_cast<SDLTexture*>(surface->get_texture());
+ boost::shared_ptr<SDLTexture> sdltexture = boost::dynamic_pointer_cast<SDLTexture>(surface->get_texture());
DrawingEffect effect = request.drawing_effect;
if (surface->get_flipx()) effect = HORIZONTAL_FLIP;
rect.y = (Sint16)request.pos.y * screen->h / SCREEN_HEIGHT;
rect.w = (Uint16)fillrectrequest->size.x * screen->w / SCREEN_WIDTH;
rect.h = (Uint16)fillrectrequest->size.y * screen->h / SCREEN_HEIGHT;
+ if((rect.w == 0) || (rect.h == 0)) {
+ return;
+ }
Uint8 r = static_cast<Uint8>(fillrectrequest->color.red * 255);
Uint8 g = static_cast<Uint8>(fillrectrequest->color.green * 255);
Uint8 b = static_cast<Uint8>(fillrectrequest->color.blue * 255);