if(mouse_left_button)
{
+#ifdef OLD_SDL1
pos.x += int(event.motion.xrel * float(SCREEN_WIDTH)/g_screen->w);
pos.y += int(event.motion.yrel * float(SCREEN_HEIGHT)/g_screen->h);
caught_event = true;
+#endif
}
if(event.button.x > pos.x-12 && event.button.x < pos.x+16 + buttons_box.x*buttons_size.x &&
event.button.y > pos.y-4 && event.button.y < pos.y+8 + buttons_box.y*buttons_size.y)
caught_event = true;
+#ifdef OLD_SDL1
if(event.button.button == SDL_MOUSEBUTTONUP)
{
row--;
mouse_left_button = true;
else
caught_event = false;
+#endif
break;
case SDL_MOUSEBUTTONUP:
mouse_left_button = false;
case SDL_MOUSEBUTTONDOWN:
if(event.button.button == SDL_BUTTON_LEFT)
{
+#ifdef OLD_SDL1
int x = int(event.motion.x * float(SCREEN_WIDTH)/g_screen->w);
int y = int(event.motion.y * float(SCREEN_HEIGHT)/g_screen->h);
{
menuaction = MENU_ACTION_HIT;
}
+#endif
}
break;
case SDL_MOUSEMOTION:
{
+#ifdef OLD_SDL1
float x = event.motion.x * SCREEN_WIDTH/g_screen->w;
float y = event.motion.y * SCREEN_HEIGHT/g_screen->h;
if(MouseCursor::current())
MouseCursor::current()->set_state(MC_NORMAL);
}
+#endif
}
break;
void MouseCursor::draw(DrawingContext& context)
{
+#ifdef OLD_SDL1
if(cur_state == MC_HIDE)
return;
context.draw_surface_part(cursor, Vector(0, h*cur_state),
Vector(w, h), Vector(x-mid_x, y-mid_y), LAYER_GUI+100);
+#endif
}
/* EOF */
log_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl;
}
- SDL_Window *screen;
-
-void set_gamma(float gamma) {
+void set_gamma(float /*gamma*/) {
#ifdef OLD_SDL1
SDL_SetWindowGammaRamp(screen,gamma, gamma, gamma);
#endif
#include "supertux/globals.hpp"
#include <tinygettext/tinygettext.hpp>
-SDL_Surface* g_screen;
JoystickKeyboardController* g_jk_controller = 0;
tinygettext::DictionaryManager* dictionary_manager = 0;
// global variables
extern JoystickKeyboardController* g_jk_controller;
-extern SDL_Surface* g_screen;
-
extern ScreenManager* g_screen_manager;
extern TextureManager* texture_manager;
SCREEN_WIDTH = 800;
SCREEN_HEIGHT = 600;
-/* SDL_Window *window; // Declare a pointer to an SDL_Window
context_pointer->init_renderer();
- g_screen = SDL_GetWindowSurface(*window);*/
+#ifdef OLD_SDL1
// SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
/* // set icon -- Original part B4 SDL2
640, 480,
SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
// not sure of that */
-
+#endif
SDL_ShowCursor(0);
log_info << (g_config->use_fullscreen?"fullscreen ":"window ")
for(int disp_mode_ctr = 0; disp_mode_ctr < SDL_GetNumDisplayModes(0); disp_mode_ctr++)
{
+#ifdef OLD_SDL1
SDL_DisplayMode* current = NULL;
int disp_retval = SDL_GetDisplayMode(0, // Display Index
disp_mode_ctr, // Mode index (default to first)
else
{
}
+#endif
}
// On Ubuntu/Linux resolutions are returned from highest to
// lowest, so reverse them
#include "video/sdl/sdl_texture.hpp"
SDLLightmap::SDLLightmap() :
- screen(),
red_channel(),
blue_channel(),
green_channel(),
denominator(),
LIGHTMAP_DIV()
{
- screen = SDL_GetWindowSurface(SDL_GetMouseFocus());
-
//float xfactor = 1.0f; // FIXME: (float) config->screenwidth / SCREEN_WIDTH;
//float yfactor = 1.0f; // FIXME: (float) config->screenheight / SCREEN_HEIGHT;
}
*/
+#ifdef OLD_SDL1
LIGHTMAP_DIV = 8 * numerator / denominator;
width = screen->w / LIGHTMAP_DIV;
red_channel = (Uint8 *)malloc(width * height * sizeof(Uint8));
green_channel = (Uint8 *)malloc(width * height * sizeof(Uint8));
blue_channel = (Uint8 *)malloc(width * height * sizeof(Uint8));
+#endif
}
SDLLightmap::~SDLLightmap()
void
SDLLightmap::do_draw()
{
+#ifdef OLD_SDL1
// FIXME: This is really slow
if(LIGHTMAP_DIV == 1)
{
SDL_UnlockSurface(screen);
}
}
+#endif
}
void
void
SDLLightmap::draw_surface(const DrawingRequest& request)
{
+#ifdef OLD_SDL1
if((request.color.red == 0.0 && request.color.green == 0.0 && request.color.blue == 0.0) || request.color.alpha == 0.0 || request.alpha == 0.0)
{
return;
int dstx = (int) request.pos.x * numerator / denominator;
int dsty = (int) request.pos.y * numerator / denominator;
light_blit(transform, src_rect, dstx, dsty);
+#endif
}
void
SDLLightmap::draw_surface_part(const DrawingRequest& request)
{
+#ifdef OLD_SDL1
const SurfacePartRequest* surfacepartrequest
= (SurfacePartRequest*) request.request_data;
int dstx = (int) request.pos.x * numerator / denominator;
int dsty = (int) request.pos.y * numerator / denominator;
light_blit(transform, &src_rect, dstx, dsty);
+#endif
}
void
void get_light(const DrawingRequest& request) const;
private:
- SDL_Surface* screen;
Uint8 *red_channel;
Uint8 *blue_channel;
Uint8 *green_channel;
#include "video/sdl/sdl_renderer.hpp"
+#include "util/log.hpp"
#include "video/drawing_request.hpp"
#include "video/sdl/sdl_surface_data.hpp"
#include "video/sdl/sdl_texture.hpp"
#include <sstream>
#include <stdexcept>
#include "SDL2/SDL_video.h"
-//#include "SDL/SDL.h"
-//#include "SDL/SDL_opengl.h"
-
namespace {
} // namespace
SDLRenderer::SDLRenderer() :
- screen(),
+ window(),
+ renderer(),
numerator(),
denominator()
{
// if(g_config->use_fullscreen)
// flags |= SDL_FULLSCREEN;
+ log_info << "creating SDLRenderer" << std::endl;
int width = 800; //FIXME: config->screenwidth;
int height = 600; //FIXME: config->screenheight;
-
- SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
-
- window = SDL_CreateWindow(
- "SuperTux",
- SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED,
- width, height,
- SDL_WINDOW_OPENGL );
- SDL_GLContext glcontext = SDL_GL_CreateContext(window);
- renderer = SDL_CreateRenderer(window, -1, 0);
-
-
- if(window == 0) {
+ int flags = 0;
+ int ret = SDL_CreateWindowAndRenderer(width, height, flags,
+ &window, &renderer);
+
+ if(ret != 0) {
std::stringstream msg;
msg << "Couldn't set video mode (" << width << "x" << height
<< "): " << SDL_GetError();
throw std::runtime_error(msg.str());
}
+ SDL_SetWindowTitle(window, "SuperTux");
+ if(texture_manager == 0)
+ texture_manager = new TextureManager();
+#ifdef OLD_SDL1
numerator = 1;
denominator = 1;
/* FIXME:
denominator = SCREEN_HEIGHT;
}
*/
- if(texture_manager == 0)
- texture_manager = new TextureManager();
+#endif
}
SDLRenderer::~SDLRenderer()
{
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
}
void
SDLRenderer::draw_surface(const DrawingRequest& request)
{
+#ifdef OLD_SDL1
//FIXME: support parameters request.alpha, request.angle, request.blend
const Surface* surface = (const Surface*) request.request_data;
boost::shared_ptr<SDLTexture> sdltexture = boost::dynamic_pointer_cast<SDLTexture>(surface->get_texture());
dst_rect.y = (int) request.pos.y * numerator / denominator;
Uint8 alpha = 0;
-#ifdef OLD_SDL1
if(request.alpha != 1.0)
{
if(!transform->format->Amask)
transform = apply_alpha(transform, request.alpha);
}*/
}
-#endif
SDL_BlitSurface(transform, src_rect, screen, &dst_rect);
SDL_FreeSurface(transform);
}*/
}
+#endif
}
void
SDLRenderer::draw_surface_part(const DrawingRequest& request)
{
+#ifdef OLD_SDL1
const SurfacePartRequest* surfacepartrequest
= (SurfacePartRequest*) request.request_data;
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)
{
}
#endif
+#ifdef OLD_SDL1
SDL_BlitSurface(transform, &src_rect, screen, &dst_rect);
+#endif
+#ifdef OLD_SDL1
if(request.alpha != 1.0)
{
if(!transform->format->Amask)
{
-#ifdef OLD_SDL1
if(alpha == 255)
{
SDL_SetSurfaceAlphaMod(transform, 0);
{
SDL_SetSurfaceAlphaMod(transform, alpha);
}
-#endif
}
/*else
{
SDL_FreeSurface(transform);
}*/
}
+#endif
}
void
SDLRenderer::draw_gradient(const DrawingRequest& request)
{
+#ifdef OLD_SDL1
const GradientRequest* gradientrequest
= (GradientRequest*) request.request_data;
const Color& top = gradientrequest->top;
SDL_FreeSurface(temp);
}
}
+#endif
}
void
SDLRenderer::draw_filled_rect(const DrawingRequest& request)
{
+#ifdef OLD_SDL1
const FillRectRequest* fillrectrequest
= (FillRectRequest*) request.request_data;
SDL_BlitSurface(temp, 0, screen, &rect);
SDL_FreeSurface(temp);
}
+#endif
}
void
void resize(int w, int h);
void apply_config() {}
+ SDL_Renderer* get_sdl_renderer() const { return renderer; };
+
private:
- SDL_Surface *screen;
- SDL_Window *window;
- SDL_Renderer *renderer;
+ SDL_Window* window;
+ SDL_Renderer* renderer;
int numerator;
int denominator;
#include "supertux/globals.hpp"
#include "video/color.hpp"
#include "video/sdl/sdl_texture.hpp"
+#include "video/sdl/sdl_renderer.hpp"
#include "util/log.hpp"
#include "math/random_generator.hpp"
namespace {
#define BILINEAR
-
+#ifdef OLD_SDL1
static Uint32 get_pixel_mapping (SDL_Surface *src, void *pixel)
{
Uint32 mapped = 0;
return (random_color);
} /* Uint32 get_unused_color */
+#endif
#ifdef NAIVE
SDL_Surface *scale(SDL_Surface *src, int numerator, int denominator)
#endif
#ifdef BILINEAR
+#ifdef OLD_SDL1
void getpixel(SDL_Surface *src, int srcx, int srcy, Uint8 color[4])
{
int bpp = src->format->BytesPerPixel;
SDL_Surface *colorize(SDL_Surface *src, const Color &color)
{
// FIXME: This is really slow
- assert(color.red != 1.0 || color.green != 1.0 || color.blue != 1.0);
- int red = (int) (color.red * 256);
- int green = (int) (color.green * 256);
- int blue = (int) (color.blue * 256);
SDL_Surface *dst = SDL_CreateRGBSurface(src->flags, src->w, src->h, src->format->BitsPerPixel, src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask);
int bpp = dst->format->BytesPerPixel;
if(SDL_MUSTLOCK(src))
#ifdef OLD_SDL1
if(src->format->Amask || !(src->flags & SDL_SRCCOLORKEY) || mapped != src->format->colorkey)
{
+ assert(color.red != 1.0 || color.green != 1.0 || color.blue != 1.0);
+ int red = (int) (color.red * 256);
+ int green = (int) (color.green * 256);
+ int blue = (int) (color.blue * 256);
+
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);
}
return dst;
}
+#endif
/** Optimizes a SDL_Surface surface and returns it in the "display format". If
* the surface does not have an alpha channel, simply calls
SDLTexture::SDLTexture(SDL_Surface* image) :
texture()
{
- texture = optimize(image);
- //width = texture->w;
- //height = texture->h;
+ texture = SDL_CreateTextureFromSurface(static_cast<SDLRenderer*>(Renderer::instance())->get_sdl_renderer(),
+ image);
+ if (!texture)
+ {
+ std::ostringstream msg;
+ msg << "couldn't create texture: " << SDL_GetError();
+ throw std::runtime_error(msg.str());
+ }
+
+ width = image->w;
+ height = image->h;
+
+#ifdef OLD_SDL1
int numerator = 1;
int denominator = 1;
//FIXME: float xfactor = (float) config->screenwidth / SCREEN_WIDTH;
}
*/
cache[NO_EFFECT][Color::WHITE] = scale(texture, numerator, denominator);
+#endif
}
SDLTexture::~SDLTexture()
{
- SDL_FreeSurface(texture);
+ SDL_DestroyTexture(texture);
}
+#ifdef OLD_SDL1
SDL_Surface*
SDLTexture::get_transform(const Color &color, DrawingEffect effect)
{
}
return cache[effect][color];
}
+#endif
/* vim: set sw=2 sts=2 et : */
/* EOF */
class SDLTexture : public Texture
{
protected:
- SDL_Surface *texture;
- //unsigned int width;
- //unsigned int height;
+ SDL_Texture* texture;
+ int width;
+ int height;
+#ifdef OLD_SDL1
struct ColorCache
{
static const int HASHED_BITS = 3;
};
//typedef std::map<Color, SDL_Surface *> ColorCache;
ColorCache cache[NUM_EFFECTS];
+#endif
public:
SDLTexture(SDL_Surface* sdlsurface);
virtual ~SDLTexture();
+#ifdef OLD_SDL1
SDL_Surface *get_transform(const Color &color, DrawingEffect effect);
+#endif
- SDL_Surface *get_texture() const
+ SDL_Texture *get_texture() const
{
return texture;
}
unsigned int get_texture_width() const
{
- return texture->w;
+ return width;
}
unsigned int get_texture_height() const
{
- return texture->h;
+ return height;
}
unsigned int get_image_width() const
{
- return texture->w;
+ return width;
}
unsigned int get_image_height() const
{
- return texture->h;
- }
-
- /*unsigned int get_texture_width() const
- {
- return width;
- }
-
- unsigned int get_texture_height() const
- {
- return height;
- }
-
- unsigned int get_image_width() const
- {
- return width;
- }
-
- unsigned int get_image_height() const
- {
return height;
- }*/
+ }
private:
SDLTexture(const SDLTexture&);