Jump to content
  • Advertisement
Sign in to follow this  
Boku San

SDL on Windows - Easier way to resize?

This topic is 5397 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;
   if(screen == NULL)
      cerr << "SDL_SetVideoMode() Failed: " << SDL_GetError() << endl;
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);
(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
0, 0,
rect.right - rect.left, rect.bottom - rect.top,
window->flags = prevFlags;

window->w = width;
window->h = height;
{ // 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!