API reference / Windows and drawing
SDL_CreateWindowAndRenderer
Function, SDL3
Makes a window and a renderer in one call. The window is the rectangle on the screen, and the renderer is the object that draws in it.
Declaration
#include <SDL3/SDL.h>
bool SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer);Parameters
title | The text in the title bar. |
width | The width of the window in pixels. |
height | The height of the window in pixels. |
window_flags | Options for the window. Use 0 for a normal window. |
window | The address of your window pointer. SDL writes the new pointer there. |
renderer | The address of your renderer pointer. SDL writes the new pointer there. |
Return value
True on success. On failure it returns false, and SDL_GetError gives the reason.
Example
if (!SDL_CreateWindowAndRenderer("Hello, window", 640, 480, 0,
&window, &renderer)) {
SDL_Log("SDL_CreateWindowAndRenderer failed: %s", SDL_GetError());
return SDL_APP_FAILURE;
}See this code run in Open a window. Download the full program (.zip)
In SDL2
The name is the same, but the title is not an argument, and it returns 0 on success. Set the title with SDL_SetWindowTitle.