SDL_CreateWindow vs. SDL_SetVideoMode

I’m fairly new to SDL. I have some legacy code that uses SDL_SetVideoMode. I noticed there seems to be no way to center the resulting window in the screen.

I also noticed that SDL_SetVideoMode is not documented in the SDL 1.3 Wiiki. So I’m guessing

  1. SDL_SetVideoMode is legacy SDL 1.2 API that has been replaced with SDL_CreateWindow?

  2. If I stick with SDL_SetVideoMode, is there a way to position the resulting window on the screen? Or do I have to upgrade the legacy code to use SDL_CreateWindow in order to have control over the window’s position?

afaik, SDL_SetVideoMode doesn’t exist in SDL 1.3On Thu, Jun 3, 2010 at 6:13 PM, VernJensen wrote:

I’m fairly new to SDL. I have some legacy code that uses
SDL_SetVideoMode. I noticed there seems to be no way to center the resulting
window in the screen.

I also noticed that SDL_SetVideoMode is not documented in the SDL 1.3
Wiiki. So I’m guessing

  1. SDL_SetVideoMode is legacy SDL 1.2 API that has been replaced with
    SDL_CreateWindow?

  2. If I stick with SDL_SetVideoMode, is there a way to position the
    resulting window on the screen? Or do I have to upgrade the legacy code to
    use SDL_CreateWindow in order to have control over the window’s position?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

oh, sorry, I misread your post- yes, use SDL_CreateWIndow - if you’re
updating old code, you could probably create a define:
#define SDL_SetVideoMode( x, y, b, flags ) SDL_CreateWindow( x, y, b, flags
)
This, of course, wouldn’t be perfect because it returns a SDL_Window instead
of a SDL_Surface, but it should work for simple programs.On Thu, Jun 3, 2010 at 8:28 PM, Alex Barry <@Alex_Barry> wrote:

afaik, SDL_SetVideoMode doesn’t exist in SDL 1.3

On Thu, Jun 3, 2010 at 6:13 PM, VernJensen wrote:

I’m fairly new to SDL. I have some legacy code that uses
SDL_SetVideoMode. I noticed there seems to be no way to center the resulting
window in the screen.

I also noticed that SDL_SetVideoMode is not documented in the SDL 1.3
Wiiki. So I’m guessing

  1. SDL_SetVideoMode is legacy SDL 1.2 API that has been replaced with
    SDL_CreateWindow?

  2. If I stick with SDL_SetVideoMode, is there a way to position the
    resulting window on the screen? Or do I have to upgrade the legacy code to
    use SDL_CreateWindow in order to have control over the window’s position?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

No, it won’t. Not even for simple programs. The SDL 1.3 video API is
completely different from the surface API. Specifically, SDL 1.3
windows do not have surfaces and require a renderer to display
graphics. You can’t even blit a surface directly to an SDL window;
you have to convert it to a texture first.

The SDL 1.2 surface API is still around, and SDL_SetVideoMode is still
available through a compatibility layer.On 03/06/2010, Alex Barry <alex.barry at gmail.com> wrote:

oh, sorry, I misread your post- yes, use SDL_CreateWIndow - if you’re
updating old code, you could probably create a define:
#define SDL_SetVideoMode( x, y, b, flags ) SDL_CreateWindow( x, y, b, flags
)
This, of course, wouldn’t be perfect because it returns a SDL_Window instead
of a SDL_Surface, but it should work for simple programs.

#include <SDL/SDL_compat.h>

it should be in there.
however, it should be noted that there have been several complaints about the compatibility layer simply not being good enough for any practical application of SDL.

So, in short, if you need SDL1.3 features, update your code to use SDL1.3. Otherwise, keep with SDL1.2 – SDL1.3 isn’t even the official release version of SDL yet, and probably won’t be for quite awhile. Using SDL1.2 for a new application is perfectly fine. Unless you need multi-windowing or the increased speed of hardware acceleration (you might be surprised, most computers should average at least 30fps with SDL on Windows, and for Linux/Mac there’s always the option of the non-official glSDL (same API, just using an OpenGL backend).

That said, the 1.3 API can be considered pretty much frozen (new things might be added, but I doubt what’s there will change significantly enough to make updating an issue). If you’re putting any serious thought into updating, starting now wouldn’t hurt. However I’d not make it the main branch of development.------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/

Well, my intend is to publish on iPhone / iPad. And my understanding is I need SDL 1.3 for that. So I guess I’ll be upgrading.

Is there any kind of an explanation somewhere for how SDL 1.3 is set up, with the windows and all? I do see documentation on the Wiki, but it seems to just be function-specific API references, not a “general overview” or “introduction”. If such a thing doesn’t exist, maybe someone could run down the basics for me? (As well as any tips for things I’ll need to do when upgrading from 1.2 API that uses SDL_Surface?)

Well, my intend is to publish on iPhone / iPad. And my understanding is I need SDL 1.3 for that. So I guess I’ll be upgrading.

Is there any kind of an explanation somewhere for how SDL 1.3 is set up, with the windows and all? I do see documentation on the Wiki, but it seems to just be function-specific API references, not a “general overview” or “introduction”. If such a thing doesn’t exist, maybe someone could run down the basics for me? (As well as any tips for things I’ll need to do when upgrading from 1.2 API that uses SDL_Surface?)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Well, not only for you. Other people need it too.On June 5, 2010, at 0:10:00.00, VernJensen wrote:

okay, I’ll post some code from my current project using SDL 1.3:

Code:

int SDL_main(int argc, char* argv[])
{
printf(“Starting SDL\n”);
if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_VIDEO) == -1){
printf(“Failed to start SDL! Reason: %s\n”, SDL_GetError());
return 1;
}

printf("Creating a Window\n");
// Create an SDL Window -- fullscreen and shown
     // NOTE: try to find the actual screen values, this will probably fail for iPad
SDL_Window* window = SDL_CreateWindow("SDL Window", 20, 20, 480, 320, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_SHOWN);

printf("Initializing Rendering Backend\n");
// Initialize the Rendering Backend: hardware accelerated with a backbuffer
    // TODO: Make sure we choose GLES?
int index = -1;
// See what renderers SDL has available
for(index = 0; index < SDL_GetNumRenderDrivers(); index++)
{
    printf("Getting info on driver %d\n", index);
    SDL_RendererInfo info;
    if(SDL_GetRenderDriverInfo(index, &info) != -1){
        printf("Driver %s index: %d\n\n", info.name, index);
    }
}
// Letting SDL choose... single backbuffer and hardware accelerated
if(SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_ACCELERATED) == -1){
    // D3D/GL/GLES failed, so let's just use software
    printf("Failed to get accelerated backend\n");
    if(SDL_CreateRenderer(window, -1, 0) == -1){
        // No rendering is available?
        printf("SDL has no rendering backend!\n");
        printf("Destroying Window and Shutting Down SDL\n");
        SDL_DestroyWindow(window);
        SDL_Quit();
        return 1;
    }
}
SDL_RendererInfo info;
if(SDL_GetRendererInfo(&info) == -1){
    printf("Error: Could not get rendering info\n");
}
else {
    printf("SDL chose %s Rendering Backend\n", info.name);
}

printf("Starting Event Loop\n");
SDL_Event event;
GameMode* running = new TitleScreen();
while(running)
{
    if(SDL_PollEvent(&event) == 1){
        if(event.type == SDL_QUIT){
            printf("Quitting\n");
            running = false;
            break;
        }
        // Pressing the "X" button in the window -- this used to be type SDL_QUIT as above
        else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE){
            // Q: Should I place a Quit event in queue instead?
            printf("Quitting\n");
            running = false;
            break;
        }
        running->eventLogic(&event);
    }
    // Fill the screen with black.
    SDL_RenderClear();

    running->renderLogic();

    // Update the screen
    SDL_RenderPresent();

    running = running->gameLogic();
    // Delaying just 1 millisecond will prevent the event loop from trying to hog resources and waste battery power.
    SDL_Delay(1);
}

// Cleaning up SDL
printf("Destroying Window and Shutting Down SDL\n");
SDL_DestroyWindow(window);
SDL_Quit();

return 0;

}

I use two classes here called “GameMode” and “TitleScreen”, which for understanding purposes I’ll talk about (in case they confuse you)
TitleScreen is an implementation of GameMode, GameMode is essentially just an interface (a class with no members or function implementations).
The function GameMode::eventLogic(SDL_Event*) handles user input.
The function GameMode::renderLogic(void) renders the game area.
The function GameMode::gameLogic(void) performs any auxiliary game functions – AI, physics, whatever.
I’ve been using this design for single-threaded games for about 4 years now, it’s very simple and straightforward and works quite well.

Aside for those, hopefully the comments will be helpful with explaining the use of the functions there and why I use flags I used etc.

I could also post my code for loading and rendering images, but it’s pretty much garbage right now. It needs more playing with. The presense of the API documentation in the headers should be enough to lead you on the right path. Also, look at my topic “Am I doing something wrong?” to see how I worked around problems I came across with the new API.------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/