From 0b1e73663a7c8a9199e84d74bcb4d30866b0b862 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Wed, 30 Jul 2014 05:10:28 +0200 Subject: [PATCH] Disabled some more code, game now starts up and plays music, no graphics yet, just a black screen --- src/gui/button_group.cpp | 4 +++ src/gui/menu.cpp | 4 +++ src/gui/mousecursor.cpp | 2 ++ src/scripting/functions.cpp | 4 +-- src/supertux/globals.cpp | 1 - src/supertux/globals.hpp | 2 -- src/supertux/main.cpp | 5 ++-- src/supertux/menu/options_menu.cpp | 2 ++ src/video/sdl/sdl_lightmap.cpp | 11 +++++--- src/video/sdl/sdl_lightmap.hpp | 1 - src/video/sdl/sdl_renderer.cpp | 52 ++++++++++++++++++++------------------ src/video/sdl/sdl_renderer.hpp | 7 ++--- src/video/sdl/sdl_texture.cpp | 36 +++++++++++++++++++------- src/video/sdl/sdl_texture.hpp | 40 +++++++++-------------------- 14 files changed, 93 insertions(+), 78 deletions(-) diff --git a/src/gui/button_group.cpp b/src/gui/button_group.cpp index 233648947..fcc31acda 100644 --- a/src/gui/button_group.cpp +++ b/src/gui/button_group.cpp @@ -103,9 +103,11 @@ ButtonGroup::event(SDL_Event &event) 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) @@ -119,6 +121,7 @@ ButtonGroup::event(SDL_Event &event) caught_event = true; +#ifdef OLD_SDL1 if(event.button.button == SDL_MOUSEBUTTONUP) { row--; @@ -137,6 +140,7 @@ ButtonGroup::event(SDL_Event &event) mouse_left_button = true; else caught_event = false; +#endif break; case SDL_MOUSEBUTTONUP: mouse_left_button = false; diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 2c6f81cdd..a777972a4 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -770,6 +770,7 @@ Menu::event(const SDL_Event& event) 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); @@ -780,11 +781,13 @@ Menu::event(const SDL_Event& event) { 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; @@ -810,6 +813,7 @@ Menu::event(const SDL_Event& event) if(MouseCursor::current()) MouseCursor::current()->set_state(MC_NORMAL); } +#endif } break; diff --git a/src/gui/mousecursor.cpp b/src/gui/mousecursor.cpp index 599400332..8bfdfa0bd 100644 --- a/src/gui/mousecursor.cpp +++ b/src/gui/mousecursor.cpp @@ -57,6 +57,7 @@ void MouseCursor::set_mid(int x, int y) void MouseCursor::draw(DrawingContext& context) { +#ifdef OLD_SDL1 if(cur_state == MC_HIDE) return; @@ -80,6 +81,7 @@ void MouseCursor::draw(DrawingContext& context) 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 */ diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 689275f78..e82191b7a 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -271,9 +271,7 @@ void camera() 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 diff --git a/src/supertux/globals.cpp b/src/supertux/globals.cpp index e67c243f8..207c119d8 100644 --- a/src/supertux/globals.cpp +++ b/src/supertux/globals.cpp @@ -17,7 +17,6 @@ #include "supertux/globals.hpp" #include -SDL_Surface* g_screen; JoystickKeyboardController* g_jk_controller = 0; tinygettext::DictionaryManager* dictionary_manager = 0; diff --git a/src/supertux/globals.hpp b/src/supertux/globals.hpp index 8f21b1388..890261947 100644 --- a/src/supertux/globals.hpp +++ b/src/supertux/globals.hpp @@ -42,8 +42,6 @@ extern int SCREEN_HEIGHT; // global variables extern JoystickKeyboardController* g_jk_controller; -extern SDL_Surface* g_screen; - extern ScreenManager* g_screen_manager; extern TextureManager* texture_manager; diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 704546619..d36c82388 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -467,10 +467,9 @@ Main::init_video() 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 @@ -531,7 +530,7 @@ Main::init_video() 640, 480, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL); // not sure of that */ - +#endif SDL_ShowCursor(0); log_info << (g_config->use_fullscreen?"fullscreen ":"window ") diff --git a/src/supertux/menu/options_menu.cpp b/src/supertux/menu/options_menu.cpp index 13d6c3058..f1f96d4d4 100644 --- a/src/supertux/menu/options_menu.cpp +++ b/src/supertux/menu/options_menu.cpp @@ -109,6 +109,7 @@ OptionsMenu::OptionsMenu() : 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) @@ -127,6 +128,7 @@ OptionsMenu::OptionsMenu() : else { } +#endif } // On Ubuntu/Linux resolutions are returned from highest to // lowest, so reverse them diff --git a/src/video/sdl/sdl_lightmap.cpp b/src/video/sdl/sdl_lightmap.cpp index 793781869..bb1284bcb 100644 --- a/src/video/sdl/sdl_lightmap.cpp +++ b/src/video/sdl/sdl_lightmap.cpp @@ -21,7 +21,6 @@ #include "video/sdl/sdl_texture.hpp" SDLLightmap::SDLLightmap() : - screen(), red_channel(), blue_channel(), green_channel(), @@ -31,8 +30,6 @@ SDLLightmap::SDLLightmap() : 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; @@ -52,6 +49,7 @@ SDLLightmap::SDLLightmap() : } */ +#ifdef OLD_SDL1 LIGHTMAP_DIV = 8 * numerator / denominator; width = screen->w / LIGHTMAP_DIV; @@ -60,6 +58,7 @@ SDLLightmap::SDLLightmap() : 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() @@ -100,6 +99,7 @@ void merge(Uint8 color[3], Uint8 color0[3], Uint8 color1[3], int rem, int total) void SDLLightmap::do_draw() { +#ifdef OLD_SDL1 // FIXME: This is really slow if(LIGHTMAP_DIV == 1) { @@ -290,6 +290,7 @@ SDLLightmap::do_draw() SDL_UnlockSurface(screen); } } +#endif } void @@ -444,6 +445,7 @@ SDLLightmap::light_blit(SDL_Surface *src, SDL_Rect *src_rect, int dstx, int dsty 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; @@ -469,11 +471,13 @@ SDLLightmap::draw_surface(const DrawingRequest& request) 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; @@ -517,6 +521,7 @@ SDLLightmap::draw_surface_part(const DrawingRequest& request) 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 diff --git a/src/video/sdl/sdl_lightmap.hpp b/src/video/sdl/sdl_lightmap.hpp index 4719c38b3..aa3643938 100644 --- a/src/video/sdl/sdl_lightmap.hpp +++ b/src/video/sdl/sdl_lightmap.hpp @@ -39,7 +39,6 @@ public: void get_light(const DrawingRequest& request) const; private: - SDL_Surface* screen; Uint8 *red_channel; Uint8 *blue_channel; Uint8 *green_channel; diff --git a/src/video/sdl/sdl_renderer.cpp b/src/video/sdl/sdl_renderer.cpp index ee05efc12..a8086cffc 100644 --- a/src/video/sdl/sdl_renderer.cpp +++ b/src/video/sdl/sdl_renderer.cpp @@ -17,6 +17,7 @@ #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" @@ -27,9 +28,6 @@ #include #include #include "SDL2/SDL_video.h" -//#include "SDL/SDL.h" -//#include "SDL/SDL_opengl.h" - namespace { @@ -116,7 +114,8 @@ SDL_Surface *apply_alpha(SDL_Surface *src, float alpha_factor) } // namespace SDLRenderer::SDLRenderer() : - screen(), + window(), + renderer(), numerator(), denominator() { @@ -137,28 +136,24 @@ SDLRenderer::SDLRenderer() : // 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: @@ -175,17 +170,19 @@ SDLRenderer::SDLRenderer() : 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 = boost::dynamic_pointer_cast(surface->get_texture()); @@ -208,7 +205,6 @@ 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) @@ -228,7 +224,6 @@ SDLRenderer::draw_surface(const DrawingRequest& request) transform = apply_alpha(transform, request.alpha); }*/ } -#endif SDL_BlitSurface(transform, src_rect, screen, &dst_rect); @@ -250,11 +245,13 @@ SDLRenderer::draw_surface(const DrawingRequest& request) SDL_FreeSurface(transform); }*/ } +#endif } void SDLRenderer::draw_surface_part(const DrawingRequest& request) { +#ifdef OLD_SDL1 const SurfacePartRequest* surfacepartrequest = (SurfacePartRequest*) request.request_data; @@ -300,7 +297,6 @@ 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) { @@ -323,13 +319,15 @@ SDLRenderer::draw_surface_part(const DrawingRequest& request) } #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); @@ -338,18 +336,19 @@ SDLRenderer::draw_surface_part(const DrawingRequest& request) { 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; @@ -380,11 +379,13 @@ SDLRenderer::draw_gradient(const DrawingRequest& request) SDL_FreeSurface(temp); } } +#endif } void SDLRenderer::draw_filled_rect(const DrawingRequest& request) { +#ifdef OLD_SDL1 const FillRectRequest* fillrectrequest = (FillRectRequest*) request.request_data; @@ -411,6 +412,7 @@ SDLRenderer::draw_filled_rect(const DrawingRequest& request) SDL_BlitSurface(temp, 0, screen, &rect); SDL_FreeSurface(temp); } +#endif } void diff --git a/src/video/sdl/sdl_renderer.hpp b/src/video/sdl/sdl_renderer.hpp index 8e3cd23ec..9f2ccb62f 100644 --- a/src/video/sdl/sdl_renderer.hpp +++ b/src/video/sdl/sdl_renderer.hpp @@ -37,10 +37,11 @@ public: 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; diff --git a/src/video/sdl/sdl_texture.cpp b/src/video/sdl/sdl_texture.cpp index 978531f52..2b22ef1e4 100644 --- a/src/video/sdl/sdl_texture.cpp +++ b/src/video/sdl/sdl_texture.cpp @@ -20,6 +20,7 @@ #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" @@ -29,7 +30,7 @@ namespace { #define BILINEAR - +#ifdef OLD_SDL1 static Uint32 get_pixel_mapping (SDL_Surface *src, void *pixel) { Uint32 mapped = 0; @@ -126,6 +127,7 @@ static Uint32 get_unused_color (SDL_Surface *src) return (random_color); } /* Uint32 get_unused_color */ +#endif #ifdef NAIVE SDL_Surface *scale(SDL_Surface *src, int numerator, int denominator) @@ -188,6 +190,7 @@ 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; @@ -405,10 +408,6 @@ SDL_Surface *vert_flip(SDL_Surface *src) 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)) @@ -449,6 +448,11 @@ SDL_Surface *colorize(SDL_Surface *src, const Color &color) #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); @@ -501,6 +505,7 @@ SDL_Surface *colorize(SDL_Surface *src, const Color &color) } 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 @@ -641,9 +646,19 @@ SDL_Surface *optimize(SDL_Surface *src) SDLTexture::SDLTexture(SDL_Surface* image) : texture() { - texture = optimize(image); - //width = texture->w; - //height = texture->h; + texture = SDL_CreateTextureFromSurface(static_cast(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; @@ -661,13 +676,15 @@ SDLTexture::SDLTexture(SDL_Surface* image) : } */ 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) { @@ -692,6 +709,7 @@ SDLTexture::get_transform(const Color &color, DrawingEffect effect) } return cache[effect][color]; } +#endif /* vim: set sw=2 sts=2 et : */ /* EOF */ diff --git a/src/video/sdl/sdl_texture.hpp b/src/video/sdl/sdl_texture.hpp index 97c38cb95..1fa1f1920 100644 --- a/src/video/sdl/sdl_texture.hpp +++ b/src/video/sdl/sdl_texture.hpp @@ -28,10 +28,11 @@ 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; @@ -85,57 +86,40 @@ protected: }; //typedef std::map 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&); -- 2.11.0