sdl.video
Class Video

java.lang.Object
  |
  +--sdl.video.Video

public class Video
extends java.lang.Object

The Video class is used to modify and query the state of the SDL Video subsystem. The first step is to initialize the SDL Video subsytem. then instantiate a new Video() object.

 	int res = sdl.SDLInit(Main.SDL_INIT_VIDEO);
 	Video video = new Video();
 
The next step is to set the video mode and get a reference to the SDLurface object that represents the framebuffer you will write pixels to.


      SDLSurface surface = null;
      surface = video.setVideoMode(1024,768,16,Video.SDL_FULLSCREEN);
 
Here is the full code snippit
      Main sdl = new Main();
      SDLSurface surface = null; 
      try 
      {
          int res = sdl.SDLInit(Main.SDL_INIT_VIDEO);
          System.out.println("TestVideo SDL Initialization res:" + res);

          Video video = new Video();
          surface = video.setVideoMode(1024,768,16,Video.SDL_FULLSCREEN);


      } catch (Exception e)  {
          System.out.println("Exception: " + e);
      }

 

Most of the interesting state variables for the Video subsystem are held in a reference to the current SDLSurface. Information on current color depth, screen size, etc are stored in this Surface's SDLPixelFormat.

      SDLPixelFormat videoFormat =video.getVideoSurface().m_Format;
  

See Also:
SDLSurface, SDLPixelFormat

Field Summary
static int SDL_ANYFORMAT
          Use a differing color depth if the one requested is unavailable.
static int SDL_ASYNCBLIT
          Enable the use of asynchronous updates of the display surface.
static int SDL_DISABLE
          Hide the cursor.
static int SDL_DOUBLEBUF
          Enable hardware double buffering; only valid with SDL_HWSURFACE.
static int SDL_ENABLE
          Show the cursor
static int SDL_FULLSCREEN
          Use fullscreen mode, if available.
static int SDL_HWACCEL
          Blit uses hardware acceleration
static int SDL_HWPALETTE
          Give SDL exclusive palette access.
static int SDL_HWSURFACE
          Put the surface in video memory, if possible.
static int SDL_OPENGL
          Create an OpenGL rendering context.
static int SDL_OPENGLBLIT
          Create an OpenGL rendering context, like SDL_OPENGL, but allow normal blitting operations.
static int SDL_PREALLOC
          Surface uses preallocated memory
static int SDL_QUERY
          Is the cursor visible?
static int SDL_RESIZABLE
          If operating in a windowed environment, allow the user to resize the window.
static int SDL_RLEACCEL
          Colorkey blit is RLE accelerated
static int SDL_RLEACCELOK
          Private flag
static int SDL_SRCALPHA
          Blit uses source alpha blending
static int SDL_SRCCOLORKEY
          Blit uses a source color key
static int SDL_SWSURFACE
          Put the surface in regular memory.
 
Constructor Summary
Video()
           
 
Method Summary
 SDLCursor createCursor(byte[] data, byte[] mask, int width, int height, int hotX, int hotY)
          Create a cursor.
 SDLSurface createRGBSurface(int flags, int width, int height, int depth, int rMask, int gMask, int bMask, int aMask)
          Create a new SDLSurface.
 SDLSurface createRGBSurfaceFrom(byte[] pixels, int flags, int width, int height, int depth, int pitch, int rMask, int gMask, int bMask, int aMask)
          Create a new SDLSurface and fill it with the data.
protected  void finalize()
           
 void freeVideo()
          Frees the root SDLSurface created by setVideoMode.
 SDLCursor getCursor()
           
 boolean getGammaRamp(short[] redTable, short[] greenTable, short[] blueTable)
          TODO: should probably throw a RuntimeException if length!=256
 java.util.Vector getListModes(SDLPixelFormat format, int flags)
           
 void getRGB(int pixel, SDLPixelFormat format, byte[] color)
          TODO: should probably throw a RuntimeException if color.length!=3
 void getRGBA(int pixel, SDLPixelFormat format, byte[] color)
          TODO: should probably throw a RuntimeException if color.length!=4
 java.lang.String getVideoDriverName()
          Get the name of the driver used by the screen SDLSurface.
 SDLVideoInfo getVideoInfo()
          Get video info about the screen SDLSurface.
 SDLSurface getVideoSurface()
          Get the screen SDLSurface.
 int isVideoModeOk(int width, int height, int bpp, int flags)
          TODO: could this be made boolean?
 boolean setGammaRamp(short[] redTable, short[] greenTable, short[] blueTable)
          TODO: should probably throw a RuntimeException if length!=256
 SDLSurface setVideoMode(int width, int height, int bpp, int flags)
          Sets the video mode.
 int showCursor(int toggle)
          Hide, show, or return the state of the cursor.
 void warpMouse(short x, short y)
          Warp the mouse to a specific point on the screen.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SDL_SWSURFACE

public static final int SDL_SWSURFACE
Put the surface in regular memory.

See Also:
Constant Field Values

SDL_HWSURFACE

public static final int SDL_HWSURFACE
Put the surface in video memory, if possible.

See Also:
Constant Field Values

SDL_OPENGL

public static final int SDL_OPENGL
Create an OpenGL rendering context. You should have previously set OpenGL video attributes with TODO: SDL_GL_SetAttribute. TODO:

See Also:
sdl.video.gl#setAttributes(), Constant Field Values

SDL_ASYNCBLIT

public static final int SDL_ASYNCBLIT
Enable the use of asynchronous updates of the display surface. This will usually slow down blitting on single CPU machines, but may provide a speed increase on SMP systems.

See Also:
Constant Field Values

SDL_OPENGLBLIT

public static final int SDL_OPENGLBLIT
Create an OpenGL rendering context, like SDL_OPENGL, but allow normal blitting operations. The screen (2D) surface may have an alpha channel, and TODO: SDL_UpdateRects must be used for updating changes to the screen surface.

See Also:
SDL_OPENGL, Constant Field Values

SDL_RESIZABLE

public static final int SDL_RESIZABLE
If operating in a windowed environment, allow the user to resize the window. When the window is resized by the user a TODO: SDL_VIDEORESIZE event is generated and setVideoMode() can be called again with the new size.

See Also:
setVideoMode(int, int, int, int), Constant Field Values

SDL_ANYFORMAT

public static final int SDL_ANYFORMAT
Use a differing color depth if the one requested is unavailable. Normally, if a video surface of the requested bits-per-pixel (bpp) is not available, SDL will emulate one with a shadow surface. Passing SDL_ANYFORMAT prevents this and causes SDL to use the video surface, regardless of its pixel depth.

See Also:
Constant Field Values

SDL_HWPALETTE

public static final int SDL_HWPALETTE
Give SDL exclusive palette access. Without this flag you may not always get the the exact colors you request with SDL_SetColors or SDL_SetPalette. TODO:

See Also:
TODO:, #setPalette(), Constant Field Values

SDL_DOUBLEBUF

public static final int SDL_DOUBLEBUF
Enable hardware double buffering; only valid with SDL_HWSURFACE.
Use of this option is fairly transparent: all operations on the SDLSurface returned by setVideoMode() and getVideoSurface() will actually operate on a double buffer. When you are ready for the screen to be updated, call TODO: SDL_Flip()
If hardware double buffering is not possible, SDL will transparently revert to non-double buffering (actually, I think it still does double buffering, just unaccelerated). TODO:

See Also:
SDLSurface.flip(), Constant Field Values

SDL_FULLSCREEN

public static final int SDL_FULLSCREEN
Use fullscreen mode, if available. In Linux, it might be necessary to intialize the framebuffer prior to running SDL. The easiest way to do this is to set the VESA mode via the boot loader (see Grub or Lilo docs)

See Also:
Constant Field Values

SDL_HWACCEL

public static final int SDL_HWACCEL
Blit uses hardware acceleration

See Also:
Constant Field Values

SDL_SRCCOLORKEY

public static final int SDL_SRCCOLORKEY
Blit uses a source color key

See Also:
Constant Field Values

SDL_RLEACCELOK

public static final int SDL_RLEACCELOK
Private flag

See Also:
Constant Field Values

SDL_RLEACCEL

public static final int SDL_RLEACCEL
Colorkey blit is RLE accelerated

See Also:
Constant Field Values

SDL_SRCALPHA

public static final int SDL_SRCALPHA
Blit uses source alpha blending

See Also:
Constant Field Values

SDL_PREALLOC

public static final int SDL_PREALLOC
Surface uses preallocated memory

See Also:
Constant Field Values

SDL_QUERY

public static final int SDL_QUERY
Is the cursor visible?

See Also:
showCursor(int), Constant Field Values

SDL_DISABLE

public static final int SDL_DISABLE
Hide the cursor.

See Also:
showCursor(int), Constant Field Values

SDL_ENABLE

public static final int SDL_ENABLE
Show the cursor

See Also:
showCursor(int), Constant Field Values
Constructor Detail

Video

public Video()
Method Detail

setVideoMode

public SDLSurface setVideoMode(int width,
                               int height,
                               int bpp,
                               int flags)
Sets the video mode. If the screen does not support the specified width and height, the next highest resolution will be used, with the returned SDLSurface centered on it.

Parameters:
width - desired screen width
height - desired screen height
bpp - specifies the bits per pixel, commonly 8, 15, 16, 24, or 32
flags - should be one of SDL_SWSURFACE or SDL_HWSURFACE, optionally ORed with any of SDL_OPENGL, SDL_ASYNCBLIT, SDL_OPENGLBLIT, SDL_RESIZABLE, SDL_ANYFORMAT, SDL_HWPALETTE, SDL_DOUBLEBUF, and SDL_FULLSCREEN.
Returns:
the newly created root SDLSurface
See Also:
SDL_SWSURFACE, SDL_HWSURFACE, SDL_OPENGL, SDL_ASYNCBLIT, SDL_OPENGLBLIT, SDL_RESIZABLE, SDL_ANYFORMAT, SDL_HWPALETTE, SDL_DOUBLEBUF, SDL_FULLSCREEN

freeVideo

public void freeVideo()
Frees the root SDLSurface created by setVideoMode.

See Also:
setVideoMode(int, int, int, int)

getVideoSurface

public SDLSurface getVideoSurface()
Get the screen SDLSurface.


getVideoInfo

public SDLVideoInfo getVideoInfo()
Get video info about the screen SDLSurface.


getVideoDriverName

public java.lang.String getVideoDriverName()
Get the name of the driver used by the screen SDLSurface.


getListModes

public java.util.Vector getListModes(SDLPixelFormat format,
                                     int flags)
Returns:
Vector, null if no modes available, empty if all modes available.

isVideoModeOk

public int isVideoModeOk(int width,
                         int height,
                         int bpp,
                         int flags)
TODO: could this be made boolean?

Returns:
0 if mode not supported in any bpp else returns nearest bpp supported.

getGammaRamp

public boolean getGammaRamp(short[] redTable,
                            short[] greenTable,
                            short[] blueTable)
TODO: should probably throw a RuntimeException if length!=256


setGammaRamp

public boolean setGammaRamp(short[] redTable,
                            short[] greenTable,
                            short[] blueTable)
TODO: should probably throw a RuntimeException if length!=256


getRGB

public void getRGB(int pixel,
                   SDLPixelFormat format,
                   byte[] color)
TODO: should probably throw a RuntimeException if color.length!=3

Parameters:
color - must be 3 bytes long!

getRGBA

public void getRGBA(int pixel,
                    SDLPixelFormat format,
                    byte[] color)
TODO: should probably throw a RuntimeException if color.length!=4

Parameters:
color - must be 4 bytes long!

createRGBSurface

public SDLSurface createRGBSurface(int flags,
                                   int width,
                                   int height,
                                   int depth,
                                   int rMask,
                                   int gMask,
                                   int bMask,
                                   int aMask)
Create a new SDLSurface. should this be the constructor for SDLSurface?


createRGBSurfaceFrom

public SDLSurface createRGBSurfaceFrom(byte[] pixels,
                                       int flags,
                                       int width,
                                       int height,
                                       int depth,
                                       int pitch,
                                       int rMask,
                                       int gMask,
                                       int bMask,
                                       int aMask)
Create a new SDLSurface and fill it with the data.

Parameters:
pixels - the data to fill the SDLSurface with

warpMouse

public void warpMouse(short x,
                      short y)
Warp the mouse to a specific point on the screen. Use with caution: can be very disconcerting to the user.


createCursor

public SDLCursor createCursor(byte[] data,
                              byte[] mask,
                              int width,
                              int height,
                              int hotX,
                              int hotY)
Create a cursor.


getCursor

public SDLCursor getCursor()
Returns:
the cursor being used by the screen SDLImage

showCursor

public int showCursor(int toggle)
Hide, show, or return the state of the cursor.

Parameters:
toggle - one of SDL_ENABLE, SDL_DISABLE, or SDL_QUERY.

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
java.lang.Throwable