|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sdl.core.Main
Top of the entire SDL interface. The Main() method is where users initialize the SDL sybsystems for use in the java runtime. Basic use looks like this:
public static void main(String[] args) { SDLSurface screenSurface; Main sdl = new Main(); try { int res = sdl.SDLInit(Main.SDL_INIT_VIDEO); if (res!=0) System.exit(1); Video video = new Video(); screenSurface = video.setVideoMode(1024, 768, 16, Video.SDL_SWSURFACE); ... } finally { sdl.SDLQuit(); } }From SDL Library Documentation, II SDL Reference, Chapter 5. General
Before SDL can be used in a program it must be initialized with SDLInit(). SDLInit() initializes all the subsystems that the user requests (video, audio, joystick, timers and/or cdrom). Once SDL is initialized with SDLInit() subsystems can be shut down and initialized as needed using SDLInitSubSystem and SDLQuitSubSystem.
SDL must also be shut down before the program exits to make sure it cleans up correctly. Calling SDL_Quit shuts down all subsystems and frees any resources allocated to SDL.
The following was copied with slight modifications from the
SDL Library Documentation, Chapter 1. The basics, Initializing SDL
SDL is composed of eight subsystems - Audio, CDROM, Event Handling, File I/O, Joystick Handling, Threading, Timers and Video. Before you can use any of these subsystems they must be initialized by calling SDLInit (or SDLInitSubSystem). SDLInit must be called before any other SDL function. It automatically initializes the Event Handling, File I/O and Threading subsystems and it takes a parameter specifying which other subsystems to initialize. So, to initialize the default subsystems and the Video subsystems you would call:
Main.SDLInit ( Main.SDL_INIT_VIDEO ); To initialize the default subsystems, the Video subsystem and the Timers subsystem you would call: Main.SDLInit ( Main.SDL_INIT_VIDEO | Main.SDL_INIT_TIMER );SDLInit is complemented by SDLQuit (and SDLQuitSubSystem). SDLQuit shuts down all subsystems, including the default ones. It should always be called before a SDL application exits.
The return value error handling mechanism still exists, however, it is preferable to throw and catch SDLExceptions
With SDLInit and SDLQuit firmly embedded in your programmers toolkit you can write your first and most basic SDL application. However, we must be prepare to handle errors. Many SDL functions return a value and indicates whether the function has succeeded or failed, SDLInit, for instance, returns -1 if it could not initialize a subsystem. SDL provides a useful facility that allows you to determine exactly what the problem was, every time an error occurs within SDL an error message is stored which can be retrieved using SDLGetError. Use this often, you can never know too much about an error.
SDLException
,
Video
Field Summary | |
static int |
SDL_INIT_AUDIO
The Audio subsystem. |
static int |
SDL_INIT_CDROM
The Cdrom subsystem. |
static int |
SDL_INIT_EVENTTHREAD
The Event thread subsystem? |
static int |
SDL_INIT_EVERYTHING
All available subsystems. |
static int |
SDL_INIT_JOYSTICK
The Joystick subsystem. |
static int |
SDL_INIT_NOPARACHUTE
Disable the SDL parachute: *PROBABLY VERY BAD IDEA IN A JAVA PROGRAM*. |
static int |
SDL_INIT_TIMER
The Timer subsystem. |
static int |
SDL_INIT_VIDEO
The Video subsystem. |
Constructor Summary | |
Main()
doesn't do anything, no need to call. |
Method Summary | |
static int |
rand()
calls the c function rand()... |
static int |
SDLInit(int i)
Inits the SDL system, plus specified subsystems. |
static int |
SDLInitSubSystem(int i)
Inits additional subsystems after SDLInit() has been called. |
static void |
SDLQuit()
Bring down the entire SDL system. |
static void |
SDLQuitSubSystem(int i)
Bring down one or more subsystems. |
static int |
SDLWasInit(int i)
Yikes! this doesn't do anything. |
static void |
sRand(int i)
calls the c function srand()... |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static int SDL_INIT_TIMER
SDLInit(int)
,
sdl.timer
public static int SDL_INIT_AUDIO
SDLInit(int)
,
sdl.audiopublic static int SDL_INIT_VIDEO
SDLInit(int)
,
sdl.videopublic static int SDL_INIT_CDROM
SDLInit(int)
,
sdl.cdrompublic static int SDL_INIT_JOYSTICK
SDLInit(int)
,
sdl.joystick
public static int SDL_INIT_NOPARACHUTE
SDLInit(int)
public static int SDL_INIT_EVENTTHREAD
SDLInit(int)
,
sdl.eventpublic static int SDL_INIT_EVERYTHING
SDLInit(int)
,
SDL_INIT_TIMER
,
SDL_INIT_AUDIO
,
SDL_INIT_VIDEO
,
SDL_INIT_CDROM
,
SDL_INIT_JOYSTICK
,
SDL_INIT_EVENTTHREAD
Constructor Detail |
public Main()
Method Detail |
public static int SDLInit(int i)
i
- an ORed mask of the various subsystems.
SDL_INIT_TIMER
,
SDL_INIT_AUDIO
,
SDL_INIT_VIDEO
,
SDL_INIT_CDROM
,
SDL_INIT_JOYSTICK
,
SDL_INIT_NOPARACHUTE
,
SDL_INIT_EVENTTHREAD
,
SDL_INIT_EVERYTHING
public static int SDLInitSubSystem(int i)
public static void SDLQuitSubSystem(int i)
public static int SDLWasInit(int i)
public static void SDLQuit()
public static int rand()
public static void sRand(int i)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |