views:

465

answers:

2

I'm starting a little RTS game with SDL and here are some questions:

  • I work with small sprites, is there a way of displaying the screen x2 with scanlines ? I tried zooming it with rotozoom but it slows down the game and I would like to avoid scaling my sprites by hand.
  • How can I switch between fullscreen and windowed while running ? I found the SDL_WM_ToggleFullScreen function but it doesn't seems to work on Windows according to SDL doc.
  • In order to put my own cursor I load a sprite with my pointer and make it follow the mouse. But I would also like to lower the framerate with SDL_Delay and doing so makes the pointer movements not smooth. The SDL cursor doesn't seemed influenced by the application framerate is it a better solution to use it and if so, is there a way of using a picture instead of a weird mask ?
  • Is there a better way of limiting framerate ?
  • How can I tinte a surface (like with draw_lit_sprite in Allegro)
+2  A: 

How can I switch between fullscreen and windowed while running ? I found the SDL_WM_ToggleFullScreen function but it doesn't seems to work on Windows according to SDL doc.

Yes, the documentation states that the SDL_WM_ToggleFullScreen function currently only works for X.

The way I do it is like so:

void SdlGraphics::setupScreenSurface() {
    Uint32 flags = 0;
    flags |= SDL_HWSURFACE;
    flags |= SDL_DOUBLEBUF;

    if(isFullScreen) {
        flags |= SDL_FULLSCREEN;
    }

    screenSurface = boost::shared_ptr<SDL_Surface>( 
        SDL_SetVideoMode(width, height, depth, flags), 
        utility::NullDeleter() 
    );
}

void SdlGraphics::setFullScreen(bool fullScreen) {
    if(isFullScreen != fullScreen) {
        isFullScreen = fullScreen;
        setupScreenSurface();
    }
}

For these points:

  • I work with small sprites, is there a way of displaying the screen x2 with scanlines ? I tried zooming it with rotozoom but it slows down the game and I would like to avoid scaling my sprites by hand.

  • How can I tinte a surface (like with draw_lit_sprite in Allegro)

I would almost recommend using OpenGL mode with SDL. It will give you hardware-accelerated freedom to do these kinds of things. rotozoom is all done in software (to my knowledge) and that's why it's so slow. It'll always be slow.

One other option you might have with drawing the sprites at 2x is to draw everything to a 1x sized texture, and then after everything is drawn, scale that texture 2x. Then you're only processing a single surface rather than many small ones over and over per frame.

As for the cursor issue, it sounds like you may want to be drawing as fast as possible, but only updating your game at a constant rate. That way you will have smooth scrolling but the game play won't get out of control.

Zack Mulgrew
"One other option you might have with drawing the sprites at 2x is to draw everything to a 1x sized texture, and then after everything is drawn, scale that texture 2x. Then you're only processing a single surface rather than many small ones over and over per frame."That's actually what I'm already doing
Giann
Ouch! Well, I tried ;)
Zack Mulgrew
+3  A: 

Sprite size - for any sort of real-time scaling or rotation you're best off with OpenGL rather than a software blitter like SDL. Other libraries such as SFML wrap this up for you.

Fullscreen/Windowed - Zack's answer looks good enough, just call SDL_SetVideoMode again.

Cursor movement - Usually the OS renders the mouse separately from the underlying application so that it stays responsive. If you're rendering the mouse cursor yourself then your only recourse is to render your game more quickly. I don't think you get much choice over the cursor itself though (possibly due to cross-platform requirements).

Framerate - many suggest decoupling in-game movement and physics from your framerate (eg. see 'Fix Your Timestep'). Also, be aware that SDL_Delay imposes a lower bound on the waiting time, not an upper bound.

Tinting a surface - again, this is best performed by OpenGL since SDL doesn't support this directly.

Kylotan
When I say OpenGL above, feel free to substitute DirectX if you're on Windows only, obviously.
Kylotan