Wiki Page Content

Differences between revisions 46 and 47
Revision 46 as of 2017-01-14 22:55:56
Size: 2503
Comment: Updated example.
Revision 47 as of 2017-01-14 22:57:32
Size: 2532
Comment: Fixed flag descriptions.
Deletions are marked like this. Additions are marked like this.
Line 54: Line 54:
||'''SDL_INIT_VIDEO'''||video subsystem. Automatically initializes the SDL_INIT_EVENTS subsystem||
||'''SDL_INIT_JOYSTICK'''||joystick subsystem||
||'''SDL_INIT_VIDEO'''||video subsystem; automatically initializes the events subsystem||
||'''SDL_INIT_JOYSTICK'''||joystick subsystem; automatically initializes the events subsystem||
Line 57: Line 57:
||'''SDL_INIT_GAMECONTROLLER'''||controller subsystem.  Automatically initializes the SDL_INIT_JOYSTICK subsystem|| ||'''SDL_INIT_GAMECONTROLLER'''||controller subsystem; automatically initializes the joystick subsystem||

SDL_Init

Use this function to initialize the SDL library. This must be called before using any other SDL function.

Syntax

int SDL_Init(Uint32 flags)

Function Parameters

flags

subsystem initialization flags; see Remarks for details

Return Value

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

Code Examples

#include "SDL.h"
#include <stdio.h> /* for fprintf() and stderr */

int main(int argc, char* argv[])
{
    if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
        fprintf(stderr,
                "Unable to initialize SDL: %s\n",
                SDL_GetError()
               );
        return 1;
    }

    /* ... */

    SDL_Quit();

    return 0;
}

Remarks

SDL_Init() simply forwards to calling SDL_InitSubSystem(). Therefore, the two may be used interchangeably. Though for readability of your code SDL_InitSubSystem() might be preferred.

The File I/O and Threading subsystems are initialized by default. You must specifically initialize other subsystems if you use them in your application.

flags may be any of the following OR'd together:

SDL_INIT_TIMER

timer subsystem

SDL_INIT_AUDIO

audio subsystem

SDL_INIT_VIDEO

video subsystem; automatically initializes the events subsystem

SDL_INIT_JOYSTICK

joystick subsystem; automatically initializes the events subsystem

SDL_INIT_HAPTIC

haptic (force feedback) subsystem

SDL_INIT_GAMECONTROLLER

controller subsystem; automatically initializes the joystick subsystem

SDL_INIT_EVENTS

events subsystem

SDL_INIT_EVERYTHING

all of the above subsystems

SDL_INIT_NOPARACHUTE

compatibility; this flag is ignored

If you want to initialize subsystems separately you would call SDL_Init(0) followed by SDL_InitSubSystem() with the desired subsystem flag.


CategoryAPI, CategoryInit

None: SDL_Init (last edited 2017-04-08 21:22:04 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit