Thread: SDL_WM_ToggleFullScreen( ... ); Not working

  1. #1
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Lurking about

    SDL_WM_ToggleFullScreen( ... ); Not working

    I ini SDL like so:
    struct sdldata
        SDL_Event event;
        int error;
        const SDL_VideoInfo *videoInfo;
        SDL_Surface* drawContext;
        Uint32 flags;
    void iniSDL(sdldata* sdldataToini)
        /* initialize SDL */
        if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    	    fprintf( stderr, "Video initialization failed: &#37;s\n",
    		     SDL_GetError( ) );
    	    Quit( 1 );
        /* Fetch the video info */
        sdldataToini->videoInfo = SDL_GetVideoInfo();
        if ( !sdldataToini->videoInfo )
    	    fprintf( stderr, "Video query failed: %s\n",
    		     SDL_GetError( ) );
    	    Quit( 1 );
        /* the flags to pass to SDL_SetVideoMode */
        sdldataToini->flags = SDL_OPENGL;          /* Enable OpenGL in SDL */
        sdldataToini->flags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
        sdldataToini->flags |= SDL_HWPALETTE;       /* Store the palette in hardware */
        /* This checks to see if surfaces can be stored in memory */
        if ( sdldataToini->videoInfo->hw_available )
    	sdldataToini->flags |= SDL_HWSURFACE;
    	sdldataToini->flags |= SDL_SWSURFACE;
        /* This checks if hardware blits can be done */
        if ( sdldataToini->videoInfo->blit_hw )
    	sdldataToini->flags |= SDL_HWACCEL;
        /* Sets up OpenGL double buffering */
        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
        /* get a SDL surface */
        sdldataToini->drawContext = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, sdldataToini->flags );
        /* Verify there is a surface */
        if ( !sdldataToini->drawContext )
    	    fprintf( stderr,  "Video mode set failed: %s\n", SDL_GetError( ) );
    	    Quit( 1 );
    Now when f1 is pressed it is supposed to toggle full screen:
    void handleKeyPress (sdldata *mySDL)
        switch ( mySDL->event.key.keysym.sym )
            case SDLK_ESCAPE:
            case SDLK_F1:
                SDL_WM_ToggleFullScreen( mySDL->drawContext );
    I have tested and am sure that the function is getting called, but the program does not go full screen. I've used nearly this exact code in previous projects and it worked. I can't for the life of me see why it wouldn't work.

    Any ideas?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Perhaps because it's not supported on all platforms?
    The docs for that function says:
    Quote Originally Posted by
    Toggles the application between windowed and fullscreen mode, if supported. (X11 is the only target currently supported, BeOS support is experimental).
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Yes, you have to actually call SDL_SetVideoMode() again to toggle fullscreen. With the SDL_FULLSCREEN flag.

    A good idea is to call SDL_WM_ToggleFullScreen(), and then if it fails (which you can tell from the return value), call SDL_SetVideoMode() instead.

    You see, SDL_WM_ToggleFullScreen() has to guarantee that the video surface won't change. (Otherwise, if you had a SDL_Surface *screen variable lying around, it would become invalid.) With SDL_SetVideoMode(), you get a new SDL_Surface * value, so this isn't a problem.

    Perhaps you're using Windows now? I gather that DirectX doesn't support this. (The SDL uses DirectX behind the scenes under Windows.)

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Nov 2005
    >>(The SDL uses DirectX behind the scenes under Windows.)

    Which is kinda sad. It uses directx, and does not allow for any of the features that directx provides. ( scaling, rotation, mesh effects, etc )

    I would recommend looking into Haaf's Game Engine. It is a very good library, (personal opinion) easier than SDL, and comes with Animation/Sprite/Font/Distortion Mesh/and more helper classes already done for you, and most of the HGE code is virtual, so you can change anything you don't like.

    EDIT: are you calling the SDL_PollEvent(SDL_Event*) correctly?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM