• Advertisement
Sign in to follow this  

[SOLVED] SDL Window Resize question

This topic is 3316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to make an SDL window resizable, however, whenever I stretch the width, the height seems to randomly increase on its own. If I verify the resulting height value in resizeWindow its usually a number with more than 6 digits. Even if I "diagonally stretch" the window the result is the same. This does not happen if I only stretch the height. The event code:
            case SDL_VIDEORESIZE:
                    engine.graphics->resizeWindow(event.resize.w, event.resize.h);
                    engine.screenW = engine.graphics->getScreenW();
                    engine.screenH = engine.graphics->getScreenH();
                    resetWindowDependantValues();
                break;
As a side question: is it better to let the user drag&drop to a desired size and use that resolution when he goes fullscreen or limit the fullscreen resolutions to a set list (800x600, 1024x768, etc)? Also, I had a question about the resizing of the window itself. Is it possible to *test* the selected window settings? For example:
    SDL_Surface* tempScreen;
    tempScreen = SDL_SetVideoMode(screenW, screenH, screenBPP, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE|SDL_FULLSCREEN);

    if(tempScreen) screen = tempScreen;
That won't work since doing SetVideoMode would release the old screen value possibly leaving the application without a valid screen. Is the only way to do this storing the working settings and reinitializing in case the new settings don't work? [Edited by - Bahdom on January 26, 2009 1:12:07 PM]

Share this post


Link to post
Share on other sites
Advertisement
A couple of quick questions/suggestions:

1. Have you tried setting a breakpoint in the debugger, and stepping through the code to see where the 'height' value is becoming corrupted?

2. To test whether a video mode is supported, take a look at SDL_VideoModeOK().

3. For fullscreen, you typically want to allow the user to select from the resolutions that are supported on his or her system. To get a list of these resolutions, use SDL_ListModes().

Share this post


Link to post
Share on other sites
You can use SDL_VideoModeOK() to test the settings.

I cannot reproduce your issue. Here is the full test code:

#include "SDL.h"
#include <sstream>

int main(int, char **)
{
SDL_Init(SDL_INIT_VIDEO);

SDL_SetVideoMode(800,600,0,SDL_ANYFORMAT | SDL_RESIZABLE);

bool running = true;
while(running)
{
SDL_Event event;
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
running = false;
break;
case SDL_VIDEORESIZE:
{
SDL_Surface *screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_ANYFORMAT | SDL_RESIZABLE);
std::stringstream message;
message << "event: " << event.resize.w << ' ' << event.resize.h
<< " screen: " << screen->w << ' ' << screen->h;
SDL_WM_SetCaption(message.str().c_str(),0);
}
break;
}
}

SDL_Quit();

return 0;
}

Share this post


Link to post
Share on other sites
I made a testScreenSettings method to verify the validity of w/h/bpp/etc to test the settings before applying them and now everything seems to work fine (even the random height issues).

Thanks alot =]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement