SDL API
SDL所有API可以从这里查看并且详细阅读:
http://wiki.libsdl.org/FrontPage
Initializing the Library
可以用 SDL_Init() 动态地加载和初始化SDL库。这个函数会用系列集flags初始化对应的功能。
SDL_INIT_TIMER Initializes the timer subsystem.
SDL_INIT_AUDIO Initializes the audio subsystem.
SDL_INIT_VIDEO Initializes the video subsystem
SDL_INIT_CDROM Initializes the cdrom subsystem.
SDL_INIT_JOYSTICK Initializes the joystick subsystem.
SDL_INIT_EVERYTHING Initialize all of the above.
退出的时候调用SDL_Quit() 清除库。下面的是SDL init(), SDL Quit()和SDL QuitSubSystem()的粗略概要和介绍。其中的“Uint32” 是32-bit unsigned integer类型.
NAME
SDL_Init - Initializes SDL
SYNOPSIS
#include "SDL.h"
int SDL_Init(Uint32 flags);
DESCRIPTION
Initializes SDL. This should be called before all other SDL functions. The flags parameter specifies what part(s) of SDL to initial‐
ize.
SDL_INIT_TIMER Initializes the timer subsystem.
SDL_INIT_AUDIO Initializes the audio subsystem.
SDL_INIT_VIDEO Initializes the video subsystem.
SDL_INIT_CDROM Initializes the cdrom subsystem.
SDL_INIT_JOYSTICK Initializes the joystick subsystem.
SDL_INIT_EVERYTHING Initialize all of the above.
SDL_INIT_NOPARACHUTE Prevents SDL from catching fatal signals.
SDL_INIT_EVENTTHREAD
RETURN VALUE
Returns -1 on an error or 0 on success.
SEE ALSO
SDL_Quit, SDL_InitSubSystem
NAME
SDL_Quit - Shut down SDL
SYNOPSIS
#include "SDL.h"
void SDL_Quit(void);
DESCRIPTION
SDL_Quit shuts down all SDL subsystems and frees the resources allocated to them. This should always be called before you exit. For
the sake of simplicity you can set SDL_Quit as your atexit call, like:
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
atexit(SDL_Quit);
.
.
Note:
While using atexit maybe be fine for small programs, more advanced users should shut down SDL in their own cleanup code.
Plus, using atexit in a library is a sure way to crash dynamically loaded code
SEE ALSO
SDL_QuitSubsystem, SDL_Init
NAME
SDL_QuitSubSystem - Shut down a subsystem
SYNOPSIS
#include "SDL.h"
void SDL_QuitSubSystem(Uint32 flags);
DESCRIPTION
SDL_QuitSubSystem allows you to shut down a subsystem that has been previously initialized by SDL_Init or SDL_InitSubSystem. The
flags tells SDL_QuitSubSystem which subsystems to shut down, it uses the same values that are passed to SDL_Init.
SEE ALSO
SDL_Quit, SDL_Init, SDL_InitSubSystem
实例代码:
/*************************************************************************
> File Name: testSDL.cpp
> Author: Mandagod
> Blog: http://blog.csdn.net/mandagod
> Mail: manda2003@163.com
> Created Time: 2016年08月07日 星期日 15时16分31秒
************************************************************************/
#include<iostream>
#include<stdio.h>
using namespace std;
extern "C" {
#include<SDL/SDL.h>
}
int main(int argc, char* argv[]) {
if ( SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
} else {
printf("Success init SDL\n");
}
// atexit(SDL_Quit);
SDL_Quit();
return 0;
}