Sign in to follow this  

SDL on Windows - Easier way to resize?

This topic is 4813 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

Ok, sorry if this has already been asked a hundred times already, just, uh...delete it and PM me with a link if it has, I guess. Is there an easy way to resize the window on...windows? I know Linux got the SDL_WM_blahblah() whatever it was that doesn't work, and I ended up using
case SDLK_F1:
   flags ^= SDL_FULLSCREEN;
   screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,flags);
   if(screen == NULL)
   {
      cerr << "SDL_SetVideoMode() Failed: " << SDL_GetError() << endl;
      quit(1);
   }
   initialize_opengl(WINDOW_WIDTH,WINDOW_HEIGHT);
   break;
And uh...it didn't take too long to figure out (re-setup everything after resizing), but I'm just wondering if there was an easier way or if I wasted 10 minutes of my life. Thanks.

Share this post


Link to post
Share on other sites
You can't keep the OpenGL context on Windows when changing pixel formats, so switching between windowed and fullscreen modes usually requires everything to be reinitialised. However, I use an Evil Hack for resizing in windowed modes:


SDL_Surface * SDL_SetVideoMode_Win32Hack(int width, int height, int bpp, Uint32 flags)
{
SDL_Surface *window = SDL_GetVideoSurface();

if (window && !(window->flags & SDL_FULLSCREEN) && !(flags & SDL_FULLSCREEN))
{
SDL_SysWMinfo info;
info.version.major = SDL_MAJOR_VERSION;
info.version.minor = SDL_MINOR_VERSION;
info.window = NULL;
if (SDL_GetWMInfo(&info))
{
RECT rect;

rect.left = rect.top = 0;
rect.right = width;
rect.bottom = height;
DWORD style = GetWindowLong(info.window, GWL_STYLE);
AdjustWindowRectEx(&rect,
style,
(style & WS_CHILDWINDOW) ? FALSE : GetMenu(info.window) != NULL,
GetWindowLong(info.window, GWL_EXSTYLE));

Uint32 prevFlags = window->flags;
window->flags |= SDL_RESIZABLE; // Prevent SDL from stopping resize
SetWindowPos(
info.window,
HWND_TOP,
0, 0,
rect.right - rect.left, rect.bottom - rect.top,
SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOMOVE);
window->flags = prevFlags;

}
window->w = width;
window->h = height;
}
else
{ // Create new window
window = SDL_SetVideoMode(width, height, bpp, flags);
/*** Do normal stuff here ***/
}
}



Just replace SetVideoMode with SDL_SetVideoMode_Win32Hack when on Windows and it does the trick. I made some modifications to it before posting, so hopefully I didn't stuff anything up :)

Share this post


Link to post
Share on other sites

This topic is 4813 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this