Added a convenience function SDL_CreateWindowAndRenderer()
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jan 2012 19:22:53 -0500
changeset 6258 fce7ce72677b
parent 6257 4b6e961362fb
child 6259 4aef5b792087
Added a convenience function SDL_CreateWindowAndRenderer()
include/SDL_render.h
src/render/SDL_render.c
--- a/include/SDL_render.h	Sun Jan 22 18:37:46 2012 -0500
+++ b/include/SDL_render.h	Sun Jan 22 19:22:53 2012 -0500
@@ -148,6 +148,22 @@
                                                     SDL_RendererInfo * info);
 
 /**
+ *  \brief Create a window and default renderer
+ *
+ *  \param width    The width of the window
+ *  \param height   The height of the window
+ *  \param window_flags The flags used to create the window
+ *  \param window   A pointer filled with the window, or NULL on error
+ *  \param renderer A pointer filled with the renderer, or NULL on error
+ *
+ *  \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(
+                                int width, int height, Uint32 window_flags,
+                                SDL_Window **window, SDL_Renderer **renderer);
+
+
+/**
  *  \brief Create a 2D rendering context for a window.
  *  
  *  \param window The window where rendering is displayed.
--- a/src/render/SDL_render.c	Sun Jan 22 18:37:46 2012 -0500
+++ b/src/render/SDL_render.c	Sun Jan 22 19:22:53 2012 -0500
@@ -126,6 +126,26 @@
     return 0;
 }
 
+int
+SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags,
+                            SDL_Window **window, SDL_Renderer **renderer)
+{
+    *window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED,
+                                     SDL_WINDOWPOS_UNDEFINED,
+                                     width, height, window_flags);
+    if (!*window) {
+        *renderer = NULL;
+        return -1;
+    }
+
+    *renderer = SDL_CreateRenderer(*window, -1, 0);
+    if (!*renderer) {
+        return -1;
+    }
+
+    return 0;
+}
+
 SDL_Renderer *
 SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
 {