Nintendo 3DS >> C/C++ >> SDL v1.2
Hello, world!
參考資訊:
1. libctru doc
2. 3ds-examples
說明:
API |
---|
int SDL_Init(Uint32 flags) |
SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) |
int stringRGBA(SDL_Surface *dst, Sint16 x, Sint16 y, const char *s, Uint8 r, Uint8 g, Uint8 b, Uint8 a) |
int SDL_Flip(SDL_Surface *screen) |
void SDL_Delay(Uint32 ms) |
void SDL_Quit(void) |
main.c
#include <stdio.h> #include <stdlib.h> #include <SDL.h> #include <SDL_gfxPrimitives.h> int main(void) { SDL_Surface *screen = NULL; SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(400, 240, 16, SDL_HWSURFACE); stringRGBA(screen, 100, 100, "hello, world!", 0xff, 0xff, 0xff, 0xff); SDL_Flip(screen); SDL_Delay(3000); SDL_Quit(); return 0; }
Makefile
include $(DEVKITARM)/3ds_rules all: arm-none-eabi-gcc -mword-relocations -ffunction-sections -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -I/opt/devkitpro/libctru/include -I/opt/devkitpro/portlibs/3ds/include/ -I/opt/devkitpro/portlibs/3ds/include/opus/ -I/opt/devkitpro/portlibs/3ds/include/SDL -D__3DS__ -c main.c -o main.o arm-none-eabi-gcc -specs=3dsx.specs -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft main.o -L/opt/devkitpro/portlibs/3ds/lib -lopusfile -logg -lopus -L/opt/devkitpro/libctru/lib -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_gfx -lSDL -lfreetype -lbz2 -lpng -ljpeg -lz -lcitro2d -lcitro3d -lctru -lm -lstdc++ -o main.elf smdhtool --create "main" "devkitARM" "steward" /opt/devkitpro/libctru/default_icon.png main.smdh 3dsxtool main.elf main.3dsx --smdh=main.smdh clean: rm -rf main.o main.elf main.3dsx main.smdh
編譯、執行
$ sudo docker run --rm -it -v $(pwd):/source nds-env /bin/bash root@c18881035cba:/source# make && exit $ citra main.3dsx
完成