From: Ricardo Cruz Date: Mon, 12 Apr 2004 21:14:17 +0000 (+0000) Subject: A first attempt to make a simple and clean way of an on the fly videomode change. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c0f792760991950d94443a09cacf777db4a617e8;p=supertux.git A first attempt to make a simple and clean way of an on the fly videomode change. But there is this problem: it seems to work on the first transition from SDL to OpenGL, but doesn't work well in the following transitions to OpenGL. I think it is not really related with the texture code, but with the st_video_setup_gl(). The way OpenGL is initialized. Ingo/Tobias, please give a look at this ;) SVN-Revision: 507 --- diff --git a/src/setup.cpp b/src/setup.cpp index a1c8af96c..dba7cf02e 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -373,6 +373,7 @@ void st_menu(void) options_menu->additem(MN_LABEL,"Options",0,0); options_menu->additem(MN_HL,"",0,0); + options_menu->additem(MN_TOGGLE,"OpenGL",use_gl,0); options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0); if(audio_device) { @@ -509,18 +510,27 @@ void process_options_menu(void) switch (options_menu->check()) { case 2: - if(use_fullscreen != options_menu->item[2].toggled) + if(use_gl != options_menu->item[2].toggled) { - use_fullscreen = !use_fullscreen; +#ifndef NOOPENGL + use_gl = !use_gl; st_video_setup(); +#endif } break; case 3: - if(use_sound != options_menu->item[3].toggled) - use_sound = !use_sound; + if(use_fullscreen != options_menu->item[3].toggled) + { + use_fullscreen = !use_fullscreen; + st_video_setup(); + } break; case 4: - if(use_music != options_menu->item[4].toggled) + if(use_sound != options_menu->item[4].toggled) + use_sound = !use_sound; + break; + case 5: + if(use_music != options_menu->item[5].toggled) { if(use_music) { @@ -540,8 +550,8 @@ void process_options_menu(void) } } break; - case 5: - if(show_fps != options_menu->item[5].toggled) + case 6: + if(show_fps != options_menu->item[6].toggled) show_fps = !show_fps; break; } diff --git a/src/texture.cpp b/src/texture.cpp index ef22a3e77..ea6ce13ba 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -17,6 +17,8 @@ #include "setup.h" #include "texture.h" +#define NO_TEXTURE 0 + void (*texture_load) (texture_type* ptexture, const std::string& file, int use_alpha); void (*texture_load_part)(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha); void (*texture_free) (texture_type* ptexture); @@ -137,6 +139,9 @@ void texture_free_gl(texture_type* ptexture) void texture_draw_gl(texture_type* ptexture, float x, float y, Uint8 alpha, bool update) { +if(ptexture->gl_texture == NO_TEXTURE) + texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); + float pw = power_of_two(ptexture->w); float ph = power_of_two(ptexture->h); @@ -168,6 +173,9 @@ if(update) void texture_draw_bg_gl(texture_type* ptexture, Uint8 alpha, bool update) { +if(ptexture->gl_texture == NO_TEXTURE) + texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); + float pw = power_of_two(ptexture->w); float ph = power_of_two(ptexture->h); @@ -196,6 +204,9 @@ if(update) void texture_draw_part_gl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) { +if(ptexture->gl_texture == NO_TEXTURE) + texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); + float pw = power_of_two(ptexture->w); float ph = power_of_two(ptexture->h); @@ -254,6 +265,7 @@ void texture_load_sdl(texture_type* ptexture, const std::string& file, int use_a ptexture->w = ptexture->sdl_surface->w; ptexture->h = ptexture->sdl_surface->h; + ptexture->gl_texture = NO_TEXTURE; } void texture_load_part_sdl(texture_type* ptexture, const std::string& file, int x, int y, int w, int h, int use_alpha) @@ -416,5 +428,9 @@ void texture_draw_part_sdl(texture_type* ptexture, float sx, float sy, float x, void texture_free_sdl(texture_type* ptexture) { SDL_FreeSurface(ptexture->sdl_surface); +#ifndef NOOPENGL + if(ptexture->gl_texture != NO_TEXTURE) + glDeleteTextures(1, &ptexture->gl_texture); +#endif }