Libwiisprite/tutorial

From WiiBrew
< Libwiisprite
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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:

  1. ---------------------------------------------------------------------------------
  2. Clear the implicit built in rules
  3. ---------------------------------------------------------------------------------

.SUFFIXES:

  1. ---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITPPC)),) $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC") endif

include $(DEVKITPPC)/wii_rules

  1. ---------------------------------------------------------------------------------
  2. TARGET is the name of the output
  3. BUILD is the directory where object files & intermediate files will be placed
  4. SOURCES is a list of directories containing source code
  5. INCLUDES is a list of directories containing extra header files
  6. ---------------------------------------------------------------------------------

TARGET := $(notdir $(CURDIR)) BUILD := build SOURCES := source DATA := data INCLUDES :=

  1. ---------------------------------------------------------------------------------
  2. options for code generation
  3. ---------------------------------------------------------------------------------

CFLAGS = -g -O2 -mrvl -Wall $(MACHDEP) $(INCLUDE) -I$(DEVKITPPC)/local/include CXXFLAGS = $(CFLAGS) LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map

  1. ---------------------------------------------------------------------------------
  2. any extra libraries we wish to link with the project
  3. ---------------------------------------------------------------------------------

LIBS := -lwiisprite -lpng -lz -lwiiuse -lbte -lfat -logc -lm

  1. ---------------------------------------------------------------------------------
  2. list of directories containing libraries, this must be the top level containing
  3. include and lib
  4. ---------------------------------------------------------------------------------

LIBDIRS :=

  1. ---------------------------------------------------------------------------------
  2. no real need to edit anything past this point unless you need to add additional
  3. rules for different file extensions
  4. ---------------------------------------------------------------------------------

ifneq ($(BUILD),$(notdir $(CURDIR)))

  1. ---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ $(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR := $(CURDIR)/$(BUILD)

  1. ---------------------------------------------------------------------------------
  2. automatically build a list of object files for our project
  3. ---------------------------------------------------------------------------------

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)/*.*)))

  1. ---------------------------------------------------------------------------------
  2. use CXX for linking C++ projects, CC for standard C
  3. ---------------------------------------------------------------------------------

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)

  1. ---------------------------------------------------------------------------------
  2. build a list of include paths
  3. ---------------------------------------------------------------------------------

export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ -I$(CURDIR)/$(BUILD) \ -I$(LIBOGC_INC)

  1. ---------------------------------------------------------------------------------
  2. build a list of library paths
  3. ---------------------------------------------------------------------------------

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ -L$(LIBOGC_LIB) -L$(DEVKITPPC)/local/lib

export OUTPUT := $(CURDIR)/$(TARGET) .PHONY: $(BUILD) clean

  1. ---------------------------------------------------------------------------------

$(BUILD): @[ -d $@ ] || mkdir -p $@ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

  1. ---------------------------------------------------------------------------------

clean: @echo clean ... @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol

  1. ---------------------------------------------------------------------------------

run: psoload $(TARGET).dol

  1. ---------------------------------------------------------------------------------

reload: psoload -r $(TARGET).dol


  1. ---------------------------------------------------------------------------------

else

DEPENDS := $(OFILES:.o=.d)

  1. ---------------------------------------------------------------------------------
  2. main targets
  3. ---------------------------------------------------------------------------------

$(OUTPUT).dol: $(OUTPUT).elf $(OUTPUT).elf: $(OFILES)

  1. ---------------------------------------------------------------------------------
  2. This rule links in binary data with the .jpg extension
  3. ---------------------------------------------------------------------------------

%.jpg.o : %.jpg

  1. ---------------------------------------------------------------------------------

@echo $(notdir $<) $(bin2o)

-include $(DEPENDS)

  1. ---------------------------------------------------------------------------------

endif

  1. ---------------------------------------------------------------------------------

(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