Libwiisprite/tutorial
Programming for Nintendo Wii with Libwiisprite.
Foreword
There are several things users should note before proceeding any further with the tutorial. This tutorial is released on the latest release of the Libwiisprite library, 0.3.0b which you can download here -> http://chaosteil.googlepages.com/libwiisprite-0.3.0b.tar.gz.
The tutorial will be written almost entirely in C++ with the possible exception of some C standard libraries functions. I will try and point this out where applicable. Also note that it is not a C++ programming tutorial, I will assume you have some knowledge in programming with C++ before you attempt the following. If you have learned C, and wish to use this, you will need some knowledge in Classes and protection levels, for more information on both of these topics visit www.cprogramming.com . If you are completely new to programming altogether I advise that you learn how to program C++ for PC before moving onto the Nintendo Wii. If you have programmed in C++ and are a little rusty, I have created a reference guide for some of the slightly more advanced C++ programming topics which can be viewed here http://wiibrew.org/wiki/Programming_in_C%2B%2B.
I do not guarantee the accuracy of this document, I will attempt to give all correct information, but no one is perfect, if you find an error please contact me on the one of the below ways.
I will also be referring to the Libwiisprite documentation for functions parameters and class hierarchy, and where required the source code for the functions, although if you wish to see the source code for the library you will need to contact the Author, this can be done at chaosteil@gmail.com.
If you wish to contact me, the author of this document, feel free to do so by emailing me at phlex.wii@gmail.com or sending me a pm at the wiidev forums here http://forum.wiibrew.org/. I spell words the English way, for example, initialise rather than initialize and colour instead of color. Of course if color is what a program requires I shall leave it so otherwise the program will not work as it is supposed to.
Lesson 1: Setting up Libwiisprite for use.
If you haven’t read the foreword, read it and don’t be lazy. This will be a fairly short lesson and at this point I will assume you have downloaded the Libwiisprite. First, you need to know how to set your make file. The basic template will look something like this:
- ---------------------------------------------------------------------------------
- Clear the implicit built in rules
- ---------------------------------------------------------------------------------
.SUFFIXES:
- ---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),) $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC") endif
include $(DEVKITPPC)/wii_rules
- ---------------------------------------------------------------------------------
- TARGET is the name of the output
- BUILD is the directory where object files & intermediate files will be placed
- SOURCES is a list of directories containing source code
- INCLUDES is a list of directories containing extra header files
- ---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR)) BUILD := build SOURCES := source DATA := data INCLUDES :=
- ---------------------------------------------------------------------------------
- options for code generation
- ---------------------------------------------------------------------------------
CFLAGS = -g -O2 -mrvl -Wall $(MACHDEP) $(INCLUDE) -I$(DEVKITPPC)/local/include CXXFLAGS = $(CFLAGS) LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map
- ---------------------------------------------------------------------------------
- any extra libraries we wish to link with the project
- ---------------------------------------------------------------------------------
LIBS := -lwiisprite -lpng -lz -lwiiuse -lbte -lfat -logc -lm
- ---------------------------------------------------------------------------------
- list of directories containing libraries, this must be the top level containing
- include and lib
- ---------------------------------------------------------------------------------
LIBDIRS :=
- ---------------------------------------------------------------------------------
- no real need to edit anything past this point unless you need to add additional
- rules for different file extensions
- ---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
- ---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ $(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
- ---------------------------------------------------------------------------------
- automatically build a list of object files for our project
- ---------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
- ---------------------------------------------------------------------------------
- use CXX for linking C++ projects, CC for standard C
- ---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),) export LD := $(CC) else export LD := $(CXX) endif
export OFILES := $(addsuffix .o,$(BINFILES)) \ $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ $(sFILES:.s=.o) $(SFILES:.S=.o)
- ---------------------------------------------------------------------------------
- build a list of include paths
- ---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ -I$(CURDIR)/$(BUILD) \ -I$(LIBOGC_INC)
- ---------------------------------------------------------------------------------
- build a list of library paths
- ---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ -L$(LIBOGC_LIB) -L$(DEVKITPPC)/local/lib
export OUTPUT := $(CURDIR)/$(TARGET) .PHONY: $(BUILD) clean
- ---------------------------------------------------------------------------------
$(BUILD): @[ -d $@ ] || mkdir -p $@ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
- ---------------------------------------------------------------------------------
clean: @echo clean ... @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
- ---------------------------------------------------------------------------------
run: psoload $(TARGET).dol
- ---------------------------------------------------------------------------------
reload: psoload -r $(TARGET).dol
- ---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
- ---------------------------------------------------------------------------------
- main targets
- ---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf $(OUTPUT).elf: $(OFILES)
- ---------------------------------------------------------------------------------
- This rule links in binary data with the .jpg extension
- ---------------------------------------------------------------------------------
%.jpg.o : %.jpg
- ---------------------------------------------------------------------------------
@echo $(notdir $<) $(bin2o)
-include $(DEPENDS)
- ---------------------------------------------------------------------------------
endif
- ---------------------------------------------------------------------------------
(taken from the Libwiisprite template make file) If you wish to add other libraries to your project to this by editing the LIBS flag by appending the name of the library prefixed with a -. As this a Libwiisprite tutorial, I won’t go into much detail on make files, if you wish to learn more visit http://www.gnu.org/software/make/manual/make.html. In order to ‘install’ Libwiisprite, follow these steps
1. Open the folder “libwiisprite/libwiisprite” then open the “include” folder. Next, copy the entire contents of the folder, there should be 8 files with the .h extension.
2. Next, open devkitPro/libogc/include ( \ slashes for windows) and paste the includes there.
3. Go back to libwiisprite and open the libwiisprite folder in libwiisprite. Then open lib and copy the one .a file there and paste it in devkitPro/libogc/lib/wii.
4. Again, go back to the root of libwiisprite and open libpng, copy the contents to the same place as the other .h files and then open.
5. Open libwiisprite/libpng/lib and copy libpng.a and paste it in devkitPro/libogc/wii.
Now you are set up to start programming.
- WiiPhlex