sdl.core
Class Main

java.lang.Object
  |
  +--sdl.core.Main

public class Main
extends java.lang.Object

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.

See Also:
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

SDL_INIT_TIMER

public static int SDL_INIT_TIMER
The Timer subsystem.

See Also:
SDLInit(int), sdl.timer

SDL_INIT_AUDIO

public static int SDL_INIT_AUDIO
The Audio subsystem.

See Also:
SDLInit(int), sdl.audio

SDL_INIT_VIDEO

public static int SDL_INIT_VIDEO
The Video subsystem.

See Also:
SDLInit(int), sdl.video

SDL_INIT_CDROM

public static int SDL_INIT_CDROM
The Cdrom subsystem.

See Also:
SDLInit(int), sdl.cdrom

SDL_INIT_JOYSTICK

public static int SDL_INIT_JOYSTICK
The Joystick subsystem.

See Also:
SDLInit(int), sdl.joystick

SDL_INIT_NOPARACHUTE

public static int SDL_INIT_NOPARACHUTE
Disable the SDL parachute: *PROBABLY VERY BAD IDEA IN A JAVA PROGRAM*.

See Also:
SDLInit(int)

SDL_INIT_EVENTTHREAD

public static int SDL_INIT_EVENTTHREAD
The Event thread subsystem?

See Also:
SDLInit(int), sdl.event

SDL_INIT_EVERYTHING

public static int SDL_INIT_EVERYTHING
All available subsystems.

See Also:
SDLInit(int), SDL_INIT_TIMER, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_INIT_CDROM, SDL_INIT_JOYSTICK, SDL_INIT_EVENTTHREAD
Constructor Detail

Main

public Main()
doesn't do anything, no need to call.

Method Detail

SDLInit

public static int SDLInit(int i)
Inits the SDL system, plus specified subsystems.

Parameters:
i - an ORed mask of the various subsystems.
Returns:
0 on success, -1 on failure. maybe this should throw something instead?
See Also:
SDL_INIT_TIMER, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_INIT_CDROM, SDL_INIT_JOYSTICK, SDL_INIT_NOPARACHUTE, SDL_INIT_EVENTTHREAD, SDL_INIT_EVERYTHING

SDLInitSubSystem

public static int SDLInitSubSystem(int i)
Inits additional subsystems after SDLInit() has been called.

Returns:
-1 on error, 0 on success. maybe this should just throw something?

SDLQuitSubSystem

public static void SDLQuitSubSystem(int i)
Bring down one or more subsystems.


SDLWasInit

public static int SDLWasInit(int i)
Yikes! this doesn't do anything.


SDLQuit

public static void SDLQuit()
Bring down the entire SDL system.


rand

public static int rand()
calls the c function rand()... why not just use java.util.Random.nextInt()?


sRand

public static void sRand(int i)
calls the c function srand()... why not just use java.util.Random.setSeed()?