Wiki Page Content

Differences between revisions 17 and 18
Revision 17 as of 2010-05-08 22:09:31
Size: 3519
Editor: SheenaSmith
Comment:
Revision 18 as of 2010-07-30 06:43:56
Size: 5682
Editor: SheenaSmith
Comment: update content (old wiki); update formatting
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
||<tablewidth="100%"style="color: rgb(255, 0, 0); text-align: center;">DRAFT ||
Line 6: Line 7:

<<Color2(green,Should we highlight the importance of using this function first by using an icon like {i} or /!\ ?)>>
Line 15: Line 18:
These are the flags which may be passed to SDL_Init() -- you should
specify the subsystems which you will be using in your application. They should be OR'd together.

||'''SDL_INIT_TIMER'''||initialize timer subsystem||
||'''SDL_INIT_AUDIO'''||initialize audio subsystem||
||'''SDL_INIT_VIDEO'''||initialize video subsystem||
||'''SDL_INIT_CDROM'''||initialize CD-ROM subsystem||
||'''SDL_INIT_JOYSTICK'''||initialize joystick subsystem||
||'''SDL_INIT_HAPTIC'''||initialize haptic (force feedback) subsystem||
||'''SDL_INIT_EVERYTHING'''||initialize all of the above subsystems||
||'''SDL_INIT_NOPARACHUTE'''||don't catch fatal signals||
||'''SDL_INIT_EVENTTHREAD'''||run the event loop in a separate thread (not supported by all OSs)||
||'''flags'''||^subsystem initialization flags^; see [[#Remarks|Remarks]] for details||
Line 29: Line 21:
Returns 0 if successful, -1 otherwise. ,,Returns 0 if successful, -1 otherwise.,,
Line 31: Line 23:
If this function fails you can usually get an error message through [[SDL_GetError]](), but not always. ,,If this function fails you can usually get an error message through [[SDL_GetError]](), but not always.,,

<<Color2(green,the standard rv would be the following:)>>
Returns 0 on success or -1 on failure; call [[SDL_GetError]]() for more information.
Line 34: Line 29:
*<<BR>>
<<Color2(green,Should aspects of this code example (like the comment) from the old wiki be incorporated into the existing examples or is it unnecessary?)>>

{{{#!highlight cpp
// Initializes the video subsystem
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
    exit(1);
}
}}}<<BR>>*
Line 118: Line 124:
The [[CategoryEvents|Event Handling]], [[CategoryIO|File I/O]], and [[CategoryThread|Threading]] subsystems are initialized by default. To initialize other subsystems ^that you will be using in your application^ you must specifically call them. You can call SDL_Init(0) or SDL_Init(SDL_INIT_NOPARACHUTE) to initialize SDL without initializing any subsystems.

<<Color2(green,Consider replacing the purple with the orange.)>>

<<Color2(purple,These are the '''flags''' which may be passed to [[SDL_Init]]() -- you should specify the subsystems which you will be using in your application. They should be OR'd together.)>>

<<Color2(orange,'''flags''' may be 0 or a mask of any of the following subsystems OR'd together:)>>
''-or-''
<<Color2(orange,These are the '''flags''' which may be passed to [[SDL_Init]]() and may be OR'd together to initiate multiple subsystems.)>>

||'''SDL_INIT_TIMER'''||initialize timer subsystem||
||'''SDL_INIT_AUDIO'''||initialize audio subsystem||
||'''SDL_INIT_VIDEO'''||initialize video subsystem||
||'''SDL_INIT_CDROM'''||initialize CD-ROM subsystem||
||'''SDL_INIT_JOYSTICK'''||initialize joystick subsystem||
||'''SDL_INIT_HAPTIC'''||initialize haptic (force feedback) subsystem||
||'''SDL_INIT_EVERYTHING'''||initialize all of the above subsystems||
||'''SDL_INIT_NOPARACHUTE'''||don't catch fatal signals||
||'''SDL_INIT_EVENTTHREAD'''||run the event loop in a separate thread (not supported by all OSs)||
Line 119: Line 145:
the subsystems specified by 'flags' (and those satisfying dependencies).
Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup
signal handlers for some commonly ignored fatal signals (like SIGSEGV).

You can call SDL_Init
(0) or SDL_Init(SDL_INIT_NOPARACHUTE) to initialize SDL without initializing any subsystems.
the subsystems specified by '''flags''' (and those satisfying dependencies).
Unless ,,the,, SDL_INIT_NOPARACHUTE ,,flag is set,, ^is set in '''flags'''^, it will install cleanup signal handlers for some commonly ignored fatal signals (like SIGSEGV).
<<Color2(green,flag seems like it should be bolded but grammatically it doesn't work as flags like in the param. solution in superscript? Can signal handlers also be avoided with flag as 0?)>>
Line 126: Line 150:

*<<BR>>,,Typical cause of this error,, ^The most common cause for error^ is using a particular display without having ,,according,, ^the corresponding^ subsystem support^ed^, such as missing ^a^ mouse driver when using ^<<Color2(green,using what? SDL? A mouse?)>>^ with ^a^ framebuffer <<Color2(green,Should framebuffer be set apart somehow like `framebuffer`?)>> device. In this case you can either compile SDL without ^a^ mouse device, or set ^the^ "SDL_NOMOUSE=1" environment variable before running your application. <<BR>>*

DRAFT

SDL_Init

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

green

Syntax

int SDL_Init(Uint32 flags)

Function Parameters

flags

subsystem initialization flags; see Remarks for details

Return Value

Returns 0 if successful, -1 otherwise.

If this function fails you can usually get an error message through [[SDL_GetError]](), but not always.

green

Returns 0 on success or -1 on failure; call SDL_GetError() for more information.

Code Examples

*
green

// Initializes the video subsystem
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
    exit(1);
}


*

C

#include "SDL.h"

int main(int, char**)  {
    if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
        fprintf(stderr, 
                "\nUnable to initialize SDL:  %s\n", 
                SDL_GetError()
               );
        return 1;
    }
    atexit(SDL_Quit);
  
    /* ... */
  
    return 0;
}

C++

#include <exception>
#include <string>
#include "SDL.h"

class InitError: public std::exception {
    public:
        InitError();
        InitError(const std::string&);
        virtual ~InitError() throw();
        virtual const char* what() const throw();
    private:
        std::string msg;
};

InitError::InitError():
  exception(), msg(SDL_GetError()) {}
InitError::InitError(const std::string& m):
  exception(), msg(m) {}
InitError::~InitError() throw() {}
const char* InitError::what() const throw() {
    return msg.c_str();
}

class SDL {
    public:
        SDL(Uint32 flags = 0) throw(InitError);
        virtual ~SDL();
};

SDL::SDL(Uint32 flags) throw(InitError) {
    if (SDL_Init(flags) != 0)
        throw InitError();
}

SDL::~SDL() {
    SDL_Quit();
}

/* ... */

#include <iostream>

int main(int argc, char **argv) {
    try {
        SDL sdl(SDL_INIT_VIDEO|SDL_INIT_TIMER);

        /* ... */

        return 0;
    }

    catch (const InitError& err) {
        std::cerr
            << "Error while initializing SDL:  " 
            << err.what() << std::endl;
    }
    
    return 1;
}

Remarks

The Event Handling, File I/O, and Threading subsystems are initialized by default. To initialize other subsystems that you will be using in your application you must specifically call them. You can call SDL_Init(0) or SDL_Init(SDL_INIT_NOPARACHUTE) to initialize SDL without initializing any subsystems.

green

purple

orange

-or- orange

SDL_INIT_TIMER

initialize timer subsystem

SDL_INIT_AUDIO

initialize audio subsystem

SDL_INIT_VIDEO

initialize video subsystem

SDL_INIT_CDROM

initialize CD-ROM subsystem

SDL_INIT_JOYSTICK

initialize joystick subsystem

SDL_INIT_HAPTIC

initialize haptic (force feedback) subsystem

SDL_INIT_EVERYTHING

initialize all of the above subsystems

SDL_INIT_NOPARACHUTE

don't catch fatal signals

SDL_INIT_EVENTTHREAD

run the event loop in a separate thread (not supported by all OSs)

This function loads the SDL dynamically linked library and initializes the subsystems specified by flags (and those satisfying dependencies). Unless the SDL_INIT_NOPARACHUTE flag is set is set in '''flags''', it will install cleanup signal handlers for some commonly ignored fatal signals (like SIGSEGV). green

Note that the event system is actually started by the video subsystem, so using SDL_INIT_EVENTTHREAD without SDL_INIT_VIDEO is pointless.

*
Typical cause of this error The most common cause for error is using a particular display without having according the corresponding subsystem supported, such as missing a mouse driver when using <<Color2(green,using what? SDL? A mouse?)>> with a framebuffer green

device. In this case you can either compile SDL without a mouse device, or set the "SDL_NOMOUSE=1" environment variable before running your application.
*


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