c++ - Changing resolution in OpenGL doesn't change the actual size of textures drawn -
i have opengl application using sdl, , i'm experiencing strange behavior when resizing window. example, here normal looking window @ 1400x900: 
if increase resolution 1600x900, black bars screen size being same: 
if reduce resolution 1280x1024, part of image: 
however, if exit application , restart manually, application behaves normal image being drawn @ correct size. numbers here examples, problem remains no matter initial , final resolutions.
void app :: load() { int music = 100, effects = 100; xmldoc settings("res/settings.xml"); if(settings.ready()) { rapidxml::xml_node<char> *node = settings.doc()->first_node("settings"); if(nodevalid(node)) { if(nodevalid("screen",node)) gscreensettings.load(node->first_node("screen")); if(nodevalid("volume",node)) { rapidxml::xml_node<char> *volnode = node->first_node("volume"); loadnum(music,"music",volnode); loadnum(effects,"effects",volnode); } gfilepath.load(node->first_node("paths")); } } //start sound subsystem pyrodactyl::music::gmusicmanager.init(music, effects); } bool app :: init(bool load) { //load sdl subsystems , truetype font subsystem if( sdl_init( sdl_init_timer | sdl_init_audio | sdl_init_video | sdl_init_joystick ) == -1 || ttf_init() == -1) { fprintf(stderr,"couldn't initialize sdl :("); return false; } if(load) load(); //set window caption sdl_wm_setcaption("unrest", "unrest"); //set window icon sdl_surface *iconimage = sdl_loadbmp(gfilepath.icon.c_str()); uint32 colorkey = sdl_maprgb(iconimage->format, 255, 0, 255); sdl_setcolorkey(iconimage, sdl_srccolorkey, colorkey); sdl_wm_seticon(iconimage,null); //initialize music thread if(music == null) music = sdl_createthread(musicthread, null); sdl_gl_setattribute(sdl_gl_doublebuffer, 1); sdl_gl_setattribute(sdl_gl_stencil_size,4); sdl_gl_setattribute(sdl_gl_accelerated_visual,1); //set keyboard repeat rate sdl_enablekeyrepeat(sdl_default_repeat_delay/4, sdl_default_repeat_interval); //store default desktop values before starting our own screen gscreensettings.desktop.w = sdl_getvideoinfo()->current_w; gscreensettings.desktop.h = sdl_getvideoinfo()->current_h; //set screen screen = sdl_setvideomode(gscreensettings.cur.w, gscreensettings.cur.h, gscreensettings.bpp, gscreensettings.videoflags); if(screen == null) return false; // initialize glew glenum status = glewinit(); if (status != glew_no_error) { fprintf(stderr, "failed initialize glew %d: %s\n", status, glewgeterrorstring(status)); return false; } //initialize , load input pyrodactyl::input::ginput.init(); pyrodactyl::input::ginput.load(gfilepath.controls); //enable 2d textures glenable(gl_texture_2d); glenable(gl_arb_texture_non_power_of_two); //enable transparency in textures, set blend function glenable(gl_blend); glblendfunc(gl_src_alpha,gl_one_minus_src_alpha); glstencilop(gl_keep,gl_replace,gl_replace); glclearcolor(0.0f, 0.0f, 0.0f, 0.0f); glclearstencil(0); glclear(gl_color_buffer_bit | gl_stencil_buffer_bit); glmatrixmode(gl_projection); glloadidentity(); glortho(0.0f, gscreensettings.cur.w, gscreensettings.cur.h, 0.0f, -1.0f, 1.0f); glmatrixmode(gl_modelview); glloadidentity(); glenableclientstate(gl_vertex_array); glenableclientstate(gl_texture_coord_array); //disable sdl stock cursor sdl_showcursor(sdl_disable); //enable unicode text input in text area sdl_enableunicode( sdl_enable ); //seed random function srand(static_cast<unsigned int>(time(null))); //apply vsync settings gscreensettings.vsync(); return true; } void app :: reset(bool load) { using namespace pyrodactyl::image; //delete stuff gimagemanager.quit(); pyrodactyl::text::gtextmanager.reset(); gloadscreen.quit(); //reload stuff init(load); gloadscreen.load(); gimagemanager.init(); gimagemanager.tileset.reload(); } the reset() function called whenever need change resolution. please me solve problem.
my guess need glviewport in reset function.
Comments
Post a Comment