Archived

This topic is now archived and is closed to further replies.

Xorcist

SDL Toggling Windowed/Fullscreen Mode

Recommended Posts

Okay I've got a quick question... I have used this code to toggle the screen:
      
SDL_Surface *ToggleScreenMode(SDL_Surface *screen)
  {//Begin ToggleScreenMode


    Uint32 flags;
    flags = screen->flags;
    flags ^= SDL_FULLSCREEN;

    printf("Toggle: %s",(screen->flags & SDL_FULLSCREEN)
      ? "Fullscreen -> Windowed\n"
      : "Windowed -> Fullscreen\n");

    screen = CreateScreen(screen->w, screen->h, screen->format->BitsPerPixel, flags);
    return(screen);

  }//End ToggleScreenMode

  
and it seems to work okay when used in the format: screen = ToggleScreenMode(screen); *note CreateScreen is a custom function that returns a SDL_Surface. what I don't understand is why when the code is modified as such:
              
void ToggleScreenMode(SDL_Surface *screen)
  {//Begin ToggleScreenMode


    Uint32 flags;
    flags = screen->flags;
    flags ^= SDL_FULLSCREEN;

    printf("Toggle: %s",(screen->flags & SDL_FULLSCREEN)
      ? "Fullscreen -> Windowed\n"
      : "Windowed -> Fullscreen\n");

    screen = CreateScreen(screen->w, screen->h, screen->format->BitsPerPixel, flags);

  }//End ToggleScreenMode

      
and called like this: ToggleScreenMode(screen); it fails when trying to toggle back to windowed mode, after being toggled to fullscreen. According to my log it seems to try to toggle the fullscreen into fullscreen and then I get a segmentation error. It's probably some stupid mistake I'm overlooking, but I just don't get why it's not working... it should shouldn't it? Any help would be greatly appreciated. Edited by - Xorcist on February 6, 2002 12:36:52 AM Edited by - Xorcist on February 7, 2002 4:14:21 AM

Share this post


Link to post
Share on other sites
Firstly, have you searched the SDL website and mailing list archives. Go to Google, enter "site:libsdl.org" and follow that with some relevant keywords. I guarantee you that this topic has come up several times before, and I'm pretty sure the way you're doing it is wrong.

Secondly, your code doesn't do what you expect it to. All you're doing in that modified version is changing the local variable called 'screen'. That has no effect on the variable that you passed to the ToggleScreenMode function. What you want is to pass the pointer or the surface by reference.

Edited by - Kylotan on February 7, 2002 12:36:33 PM

Share this post


Link to post
Share on other sites
See that''s just it, I already did a search, and I found this:

http://archives.seul.org/pygame/users/Apr-2001/msg00009.html

which if you don''t feel like reading it says the built in toggle function is a bit unreliable and the best way to toggle is to just create a new surface with or without the FULLSCREEN flag. That''s what I was trying to do, I just created a new surface and set the old one equal to the new one and it seems to work fine.

P.S. Don''t worry about my modified code, I musta not bun thunkin''

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Correct me if I''m wrong, but I think the second version, the "void ToggleScreenMode(SDL_Surface *screen)" version, is because you are only changing the temporary pointer ''screen''. Just change the function''s parameter to (SDL_Surface* &screen). That way you will modify the pointer that is passed to the function and should correct your problems.

Share this post


Link to post
Share on other sites