Added a convenience function SDL_CreateWindowAndRenderer()
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jan 2012 19:22:53 -0500
changeset 6258fce7ce72677b
parent 6257 4b6e961362fb
child 6259 4aef5b792087
Added a convenience function SDL_CreateWindowAndRenderer()
include/SDL_render.h
src/render/SDL_render.c
     1.1 --- a/include/SDL_render.h	Sun Jan 22 18:37:46 2012 -0500
     1.2 +++ b/include/SDL_render.h	Sun Jan 22 19:22:53 2012 -0500
     1.3 @@ -148,6 +148,22 @@
     1.4                                                      SDL_RendererInfo * info);
     1.5  
     1.6  /**
     1.7 + *  \brief Create a window and default renderer
     1.8 + *
     1.9 + *  \param width    The width of the window
    1.10 + *  \param height   The height of the window
    1.11 + *  \param window_flags The flags used to create the window
    1.12 + *  \param window   A pointer filled with the window, or NULL on error
    1.13 + *  \param renderer A pointer filled with the renderer, or NULL on error
    1.14 + *
    1.15 + *  \return 0 on success, or -1 on error
    1.16 + */
    1.17 +extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(
    1.18 +                                int width, int height, Uint32 window_flags,
    1.19 +                                SDL_Window **window, SDL_Renderer **renderer);
    1.20 +
    1.21 +
    1.22 +/**
    1.23   *  \brief Create a 2D rendering context for a window.
    1.24   *  
    1.25   *  \param window The window where rendering is displayed.
     2.1 --- a/src/render/SDL_render.c	Sun Jan 22 18:37:46 2012 -0500
     2.2 +++ b/src/render/SDL_render.c	Sun Jan 22 19:22:53 2012 -0500
     2.3 @@ -126,6 +126,26 @@
     2.4      return 0;
     2.5  }
     2.6  
     2.7 +int
     2.8 +SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags,
     2.9 +                            SDL_Window **window, SDL_Renderer **renderer)
    2.10 +{
    2.11 +    *window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED,
    2.12 +                                     SDL_WINDOWPOS_UNDEFINED,
    2.13 +                                     width, height, window_flags);
    2.14 +    if (!*window) {
    2.15 +        *renderer = NULL;
    2.16 +        return -1;
    2.17 +    }
    2.18 +
    2.19 +    *renderer = SDL_CreateRenderer(*window, -1, 0);
    2.20 +    if (!*renderer) {
    2.21 +        return -1;
    2.22 +    }
    2.23 +
    2.24 +    return 0;
    2.25 +}
    2.26 +
    2.27  SDL_Renderer *
    2.28  SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
    2.29  {