summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2012-01-22 19:22:53 -0500
committerSam Lantinga <slouken@libsdl.org>2012-01-22 19:22:53 -0500
commitec5e44cc53e033c9965507c5feaee60084916d26 (patch)
treea8352be6359343adae3be7feb9270a9aefc31064
parent8f925a68c23654f8e287fee1c9d8be89e321b361 (diff)
Added a convenience function SDL_CreateWindowAndRenderer()
-rw-r--r--include/SDL_render.h16
-rwxr-xr-xsrc/render/SDL_render.c20
2 files changed, 36 insertions, 0 deletions
diff --git a/include/SDL_render.h b/include/SDL_render.h
index 7f0c815f..dbbf8362 100644
--- a/include/SDL_render.h
+++ b/include/SDL_render.h
@@ -148,6 +148,22 @@ extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
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.
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index dc59fd86..59872722 100755
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -126,6 +126,26 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
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)
{