SDL Wii

From WiiBrew
(Redirected from Sdl)
Jump to navigation Jump to search
SDL Wii
SDL logo.png
General
Author(s)Numerous
Maintainer(s)Tantric
TypeFramework library
Links
Download
Source

Simple DirectMedia Layer (SDL) is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, and video. It is used by MPEG playback software, emulators, and many popular games. SDL is written in C, but works with C++ natively.

SDL support on Wii is currently incomplete. Although SDL is useable, you will likely experience problems until this is rectified. Please contribute any improvements you make to the SDL Wii SVN.


Usage

  • Grab the latest devkitPPC and libogc
  • Download and copy the PPC ported libraries to your portlibs folder (on Windows this is c:\devkitPro\portlibs\ppc)
  • Copy all of the SDL files to the libogc folder (on Windows by default this is c:\devkitPro\libogc).

Remember to link the libraries in the right order:

LIBS	:=	-lSDL_net -lSDL_ttf -lSDL_gfx -lSDL_mixer -lSDL_image -lsmpeg \
                -lSDL -ljpeg -lpng -lfreetype -lvorbisidec \
                -lz -lfat -lwiiuse -lbte -lwiikeyboard -logc -lm


Use your friend google to learn how to use SDL.

There is also additional installation help available.

Tutorial

A simple but currently incomplete tutorial can be found here. Made by GabberNL.

An input testing source code and binaries can be found here. Made by TheDrev.

Very simple application that simulates plasma fireworks is Fire.

Using SDL

SDL has graphics, sound, and input all in one. SDL is a very popular library used in many open source programs. It is most commonly used in games, but it is also used in emulators and media players. SDL is very easy to use and it is very easy to port apps that use it.

SDL Wii supports 640X480 and 320X240 framebuffer resolution. The default bitdepth is 16 with RGB565 color space but better immage quality can be obtained with 24 bits (i.e. using SDL_SetVideoMode(width, height, 24, flags)).

Power buttons are handled by SDL. Power switches off the Wii. Reset returns to Homebrew channel.

The library also inits the Wii video console.

SDL joystick mapping

The Wii controllers are mapped as SDL joysticks 0-3. The gamecube controller ports are mapped as SDL joysticks 4-7.

The sticks and axes are mapped this way:

SDL axis Nunchuck alternative.svg ClassicController.svg GameCube Controller Comments
0 (horizontal) Nunchuck Control Stick Classic Left Control Stick GameCube Control Stick Only one Wii expansion can be connected
1 (vertical) Nunchuck Control Stick Classic Left Control Stick GameCube Control Stick
2 (horizontal) Classic Right Control Stick Gamecube C Control Stick
3 (vertical) Classic Right Control Stick Gamecube C Control Stick
4 (horizontal) Classic R Trigger GameCube L Trigger
5 (vertical) Classic L Trigger GameCube R Trigger

Axis 6,7 and 8 are the wiimote itself axis' orientation.

Triggers give only positive values (0-32678).


SDL joystick button mapping

The D-pads on the Wii Remote, the Classic Controller and Gamecube controller are mapped as a joystick hat.

For Wii, only one hat is reported per joystick, so when Classic Controller is plugged in, the D-pad on the Wii Remote is ignored. As far as orientation, SDL_HAT_UP is the up button on the Wii Remote's D-pad when it's held in horizontal position (with D-pad to the left).

The wiimote and gamecube conntroller buttons are mapped this way in SDL:

SDL joystick
button index
WiimoteHorizontal.svg Nunchuck alternative.svg ClassicController.svg GameCube Controller
0 Wiimote A Button Gamecube A Button
1 Wiimote B Button Gamecube B Button
2 Wiimote 1 Button Gamecube X Button
3 Wiimote 2 Button Gamecube Y Button
4 Wiimote - Button GameCube Z Button
5 Wiimote + Button GameCube R Trigger
6 Wiimote HOME Button GameCube L Trigger
7 Nunchuck Z Button GameCube START Button
8 Nunchuck C Button
9 Classic a Button
10 Classic b Button
11 Classic x Button
12 Classic y Button
13 Classic L Trigger
14 Classic R Trigger
15 Classic ZL Button
16 Classic ZR Button
17 Classic - Button
18 Classic + Button
19 Wiimote HOME Button


SDL mouse mapping

Mouse movements are emulated by IR pointer of Wiimote 1 or/and a mouse connected in the USB port.

SDL mouse button mapping

SDL mouse
button index
WiimoteHorizontal.svg USB Mouse
Left button Wiimote A Button Left button
Right button Wiimote B Button Right button

You have to point the Wiimote towards the screen to use the Wiimote buttons as mouse buttons.

Bugs

  • SDL_gfx eats up memory and can cause code dumps. If you get code dumps then try removing SDL_gfx.
  • See Issues for bugs reporting.

Source

Many authors have contributed to the SDL Wii port over the years. The original source is from libSDL. A GameCube version was found in the devkitPro CVS repository. Mindcry made the port compatible with the Wii and added on sound, SDL_mixer and SDL_image. Devildante recompiled a version of SDL_image with libjpeg support, and added SDL_gfx and SDL_ttf with FreeType. Numerous changes were also made by Yohannes (threading, audio, etc), and David Hudson updated to the latest SDL SVN. Tantric has also rewritten portions, including the file access, audio, and video systems.

Tips

  • SDL_Init must include the SDL_INIT_JOYSTICK flag set for any input events to work, and SDL_JoystickOpen(0) must be called. When you point the Wiimote towards the screen, Wiimote events come as SDL_MOUSBUTTON and SDL_MOUSEMOTION as well as SDL_JOYBUTTON events. To enable this, for all wiimote events (both joystick and mouse), you must set the joystick event processing state with SDL_JoystickEventState. If you are not handling the wiimote via the event queue then you must explicitly request a joystick update by calling SDL_JoystickUpdate.
  • If you're going to be doing file I/O operations, call fatInitDefault() before any calls to SDL. Lockups can occur if you call that after SDL and do some big writes to the SD card.
  • The audio framebuffer lenght is fixed.
  • No more then 12 user threads can be created.

See Also