Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added a convenience function SDL_CreateWindowAndRenderer()
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 23, 2012
1 parent 6ad5c5a commit 3ff3cb5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/SDL_render.h
Expand Up @@ -147,6 +147,22 @@ extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
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.
*
Expand Down
20 changes: 20 additions & 0 deletions src/render/SDL_render.c
Expand Up @@ -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)
{
Expand Down

0 comments on commit 3ff3cb5

Please sign in to comment.