From: Ingo Ruhnke Date: Tue, 13 Apr 2004 14:32:48 +0000 (+0000) Subject: - reenabled OpenGL menu entry X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8eb1a0b00803dc38bf3a42609f6475e6b49d3bd5;p=supertux.git - reenabled OpenGL menu entry - OpenGL menu entry is now disabled if no opengl support is compiled in - added handling for lost surfaces for modeswitch in win32 (needs testing) - fixed font-shadow issue SVN-Revision: 519 --- diff --git a/src/setup.cpp b/src/setup.cpp index b82c7ed09..ffd9e3f18 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -373,7 +373,11 @@ void st_menu(void) options_menu->additem(MN_LABEL,"Options",0,0); options_menu->additem(MN_HL,"",0,0); +#ifndef NOOPENGL options_menu->additem(MN_TOGGLE,"OpenGL",use_gl,0); +#else + options_menu->additem(MN_DEACTIVE,"OpenGL (not supported)",use_gl,0); +#endif options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0); if(audio_device) { @@ -510,20 +514,13 @@ void process_options_menu(void) switch (options_menu->check()) { case 2: - if(/*use_gl != */options_menu->item[2].toggled) - { #ifndef NOOPENGL -/* + if(use_gl != options_menu->item[2].toggled) + { use_gl = !use_gl; st_video_setup(); -*/ -options_menu->item[2].toggled = false; -printf("This feature has been temporarly disabled\n"); -#else - options_menu->item[2].toggled = false; - printf("OpenGL hasn't been enabled during compiling time.\n"); -#endif } +#endif break; case 3: if(use_fullscreen != options_menu->item[3].toggled) diff --git a/src/text.cpp b/src/text.cpp index ed873674a..5d5921029 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -46,7 +46,7 @@ Text::Text(const std::string& file, int kind_, int w_, int h_) chars = new Surface(file, USE_ALPHA); - /* Load shadow font. */ + // Load shadow font. conv = SDL_DisplayFormatAlpha(chars->impl->sdl_surface); pixels = conv->w * conv->h; SDL_LockSurface(conv); diff --git a/src/texture.cpp b/src/texture.cpp index b81d8eadd..59c8dce00 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -11,6 +11,7 @@ // #include +#include #include "SDL.h" #include "SDL_image.h" #include "texture.h" @@ -19,9 +20,20 @@ Surface::Surfaces Surface::surfaces; -SurfaceData::SurfaceData(SDL_Surface* surf, int use_alpha_) - : type(SURFACE), surface(surf), use_alpha(use_alpha_) -{ +SurfaceData::SurfaceData(SDL_Surface* temp, int use_alpha_) + : type(SURFACE), use_alpha(use_alpha_) +{ + // Copy the given surface and make sure that it is not stored in + // video memory + surface = SDL_CreateRGBSurface(temp->flags & (~SDL_HWSURFACE), + temp->w, temp->h, + temp->format->BitsPerPixel, + temp->format->Rmask, + temp->format->Gmask, + temp->format->Bmask, + temp->format->Amask); + SDL_SetAlpha(temp,0,0); + SDL_BlitSurface(temp, NULL, surface, NULL); } SurfaceData::SurfaceData(const std::string& file_, int use_alpha_) @@ -35,6 +47,11 @@ SurfaceData::SurfaceData(const std::string& file_, int x_, int y_, int w_, int h { } +SurfaceData::~SurfaceData() +{ + +} + SurfaceImpl* SurfaceData::create() { @@ -54,7 +71,7 @@ SurfaceData::create_SurfaceSDL() case LOAD_PART: return new SurfaceSDL(file, x, y, w, h, use_alpha); case SURFACE: - return 0; //new SurfaceSDL(surface, use_alpha); + return new SurfaceSDL(surface, use_alpha); } assert(0); } @@ -69,7 +86,7 @@ SurfaceData::create_SurfaceOpenGL() case LOAD_PART: return new SurfaceOpenGL(file, x, y, w, h, use_alpha); case SURFACE: - return 0; //new SurfaceOpenGL(surface, use_alpha); + return new SurfaceOpenGL(surface, use_alpha); } assert(0); } @@ -152,19 +169,31 @@ Surface::reload_all() void Surface::draw(float x, float y, Uint8 alpha, bool update) { - if (impl) impl->draw(x, y, alpha, update); + if (impl) + { + if (impl->draw(x, y, alpha, update) == -2) + reload(); + } } void Surface::draw_bg(Uint8 alpha, bool update) { - if (impl) impl->draw_bg(alpha, update); + if (impl) + { + if (impl->draw_bg(alpha, update) == -2) + reload(); + } } void Surface::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) { - if (impl) impl->draw_part(sx, sy, x, y, w, h, alpha, update); + if (impl) + { + if (impl->draw_part(sx, sy, x, y, w, h, alpha, update) == -2) + reload(); + } } SDL_Surface* @@ -368,7 +397,7 @@ SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex) SDL_FreeSurface(conv); } -void +int SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool update) { float pw = power_of_two(w); @@ -398,9 +427,11 @@ SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool update) /* Avoid compiler warnings */ if(update) {} + + return 0; } -void +int SurfaceOpenGL::draw_bg(Uint8 alpha, bool update) { float pw = power_of_two(w); @@ -427,9 +458,11 @@ SurfaceOpenGL::draw_bg(Uint8 alpha, bool update) /* Avoid compiler warnings */ if(update) {} + + return 0; } -void +int SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) { float pw = power_of_two(int(this->w)); @@ -462,6 +495,7 @@ SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, /* Avoid compiler warnings */ if(update) {} + return 0; } #endif @@ -486,7 +520,7 @@ SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int w, int h, int h = sdl_surface->h; } -void +int SurfaceSDL::draw(float x, float y, Uint8 alpha, bool update) { SDL_Rect dest; @@ -497,16 +531,18 @@ SurfaceSDL::draw(float x, float y, Uint8 alpha, bool update) dest.h = h; if(alpha != 255) /* SDL isn't capable of this kind of alpha :( therefore we'll leave now. */ - return; + return -1; SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha); - SDL_BlitSurface(sdl_surface, NULL, screen, &dest); + int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest); if (update == UPDATE) SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h); + + return ret; } -void +int SurfaceSDL::draw_bg(Uint8 alpha, bool update) { SDL_Rect dest; @@ -518,13 +554,16 @@ SurfaceSDL::draw_bg(Uint8 alpha, bool update) if(alpha != 255) SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha); - SDL_SoftStretch(sdl_surface, NULL, screen, &dest); + + int ret = SDL_SoftStretch(sdl_surface, NULL, screen, &dest); if (update == UPDATE) SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h); + + return ret; } -void +int SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) { SDL_Rect src, dest; @@ -542,10 +581,12 @@ SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Ui if(alpha != 255) SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha); - SDL_BlitSurface(sdl_surface, &src, screen, &dest); + int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest); if (update == UPDATE) update_rect(screen, dest.x, dest.y, dest.w, dest.h); + + return ret; } SurfaceSDL::~SurfaceSDL() diff --git a/src/texture.h b/src/texture.h index 3b5335701..459461215 100644 --- a/src/texture.h +++ b/src/texture.h @@ -43,6 +43,7 @@ public: SurfaceData(SDL_Surface* surf, int use_alpha_); SurfaceData(const std::string& file_, int use_alpha_); SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_); + ~SurfaceData(); SurfaceSDL* create_SurfaceSDL(); SurfaceOpenGL* create_SurfaceOpenGL(); @@ -87,9 +88,10 @@ public: int h; public: - virtual void draw(float x, float y, Uint8 alpha, bool update) = 0; - virtual void draw_bg(Uint8 alpha, bool update) = 0; - virtual void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0; + /** Return 0 on success, -2 if surface needs to be reloaded */ + virtual int draw(float x, float y, Uint8 alpha, bool update) = 0; + virtual int draw_bg(Uint8 alpha, bool update) = 0; + virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0; }; class SurfaceSDL : public SurfaceImpl @@ -102,9 +104,9 @@ public: SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha); virtual ~SurfaceSDL(); - void draw(float x, float y, Uint8 alpha, bool update); - void draw_bg(Uint8 alpha, bool update); - void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); + int draw(float x, float y, Uint8 alpha, bool update); + int draw_bg(Uint8 alpha, bool update); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); }; class SurfaceOpenGL : public SurfaceImpl @@ -118,9 +120,9 @@ public: SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha); virtual ~SurfaceOpenGL(); - void draw(float x, float y, Uint8 alpha, bool update); - void draw_bg(Uint8 alpha, bool update); - void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); + int draw(float x, float y, Uint8 alpha, bool update); + int draw_bg(Uint8 alpha, bool update); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update); private: void create_gl(SDL_Surface * surf, GLuint * tex);