SDL Wiki
(This is the documentation for SDL3, which is under heavy development and the API is changing! SDL2 is the current stable version!)


Initialize the video subsystem, optionally specifying a video driver.


int SDL_VideoInit(const char *driver_name);

Function Parameters


the name of a video driver to initialize, or NULL for the default driver

Return Value

Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information.


This function initializes the video subsystem, setting up a connection to the window manager, etc, and determines the available display modes and pixel formats, but does not initialize a window or graphics mode.

If you use this function and you haven't used the SDL_INIT_VIDEO flag with either SDL_Init() or SDL_InitSubSystem(), you should call SDL_VideoQuit() before calling SDL_Quit().

It is safe to call this function multiple times. SDL_VideoInit() will call SDL_VideoQuit() itself if the video subsystem has already been initialized.

You can use SDL_GetNumVideoDrivers() and SDL_GetVideoDriver() to find a specific driver_name.


This function is available since SDL 3.0.0.

Code Examples

#include "SDL.h"
#include <stdio.h> /* for printf() */
#include <stdlib.h> /* for atexit() */

SDL_bool videoinit = SDL_FALSE;

void OnQuit(void) {
    if (videoinit) {

int main(int argc, char** argv) {
    if (SDL_Init(0) != 0) {
        printf("Error initializing SDL:  %s\n", SDL_GetError());
        return 1;

    if (SDL_VideoInit(NULL) != 0) {
        printf("Error initializing SDL video:  %s\n", SDL_GetError());
        return 2;
    videoinit = SDL_TRUE;

    /* ... */

    return 0;

CategoryAPI, CategoryVideo

[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.