mirror of
https://github.com/knightfox75/nds_nflib.git
synced 2025-06-19 09:15:39 -04:00
examples: Add example of deleting 3D sprites
This commit is contained in:
parent
90287a7133
commit
6be1dfa154
222
examples/3dsprites/delete/Makefile
Normal file
222
examples/3dsprites/delete/Makefile
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
.SUFFIXES:
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ifeq ($(strip $(DEVKITARM)),)
|
||||||
|
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||||
|
endif
|
||||||
|
|
||||||
|
# These set the information text in the nds file
|
||||||
|
#GAME_TITLE := My Wonderful Homebrew
|
||||||
|
#GAME_SUBTITLE1 := built with devkitARM
|
||||||
|
#GAME_SUBTITLE2 := http://devitpro.org
|
||||||
|
|
||||||
|
include $(DEVKITARM)/ds_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
|
||||||
|
# DATA is a list of directories containing binary files embedded using bin2o
|
||||||
|
# GRAPHICS is a list of directories containing image files to be converted with grit
|
||||||
|
# AUDIO is a list of directories containing audio to be converted by maxmod
|
||||||
|
# ICON is the image used to create the game icon, leave blank to use default rule
|
||||||
|
# NITRO is a directory that will be accessible via NitroFS
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
TARGET := $(shell basename $(CURDIR))
|
||||||
|
BUILD := build
|
||||||
|
SOURCES := source
|
||||||
|
INCLUDES := include
|
||||||
|
DATA := data
|
||||||
|
GRAPHICS :=
|
||||||
|
AUDIO :=
|
||||||
|
ICON :=
|
||||||
|
|
||||||
|
# specify a directory which contains the nitro filesystem
|
||||||
|
# this is relative to the Makefile
|
||||||
|
NITRO := nitrofiles
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# options for code generation
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
|
||||||
|
|
||||||
|
CFLAGS := -g -Wall -O3\
|
||||||
|
$(ARCH) $(INCLUDE) -DARM9
|
||||||
|
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||||
|
ASFLAGS := -g $(ARCH)
|
||||||
|
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# any extra libraries we wish to link with the project (order is important)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBS := -lnflib
|
||||||
|
|
||||||
|
# automatigically add libraries for NitroFS
|
||||||
|
ifneq ($(strip $(NITRO)),)
|
||||||
|
LIBS := $(LIBS) -lfilesystem -lfat
|
||||||
|
endif
|
||||||
|
# automagically add maxmod library
|
||||||
|
ifneq ($(strip $(AUDIO)),)
|
||||||
|
LIBS := $(LIBS) -lmm9
|
||||||
|
endif
|
||||||
|
|
||||||
|
LIBS := $(LIBS) -lnds9
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# list of directories containing libraries, this must be the top level containing
|
||||||
|
# include and lib
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nflib
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# 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 := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
|
||||||
|
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
|
||||||
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
|
||||||
|
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
|
||||||
|
|
||||||
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
|
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||||
|
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||||
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
|
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
|
||||||
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
|
||||||
|
# prepare NitroFS directory
|
||||||
|
ifneq ($(strip $(NITRO)),)
|
||||||
|
export NITRO_FILES := $(CURDIR)/$(NITRO)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# get audio list for maxmod
|
||||||
|
ifneq ($(strip $(AUDIO)),)
|
||||||
|
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
|
||||||
|
|
||||||
|
# place the soundbank file in NitroFS if using it
|
||||||
|
ifneq ($(strip $(NITRO)),)
|
||||||
|
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
|
||||||
|
|
||||||
|
# otherwise, needs to be loaded from memory
|
||||||
|
else
|
||||||
|
export SOUNDBANK := soundbank.bin
|
||||||
|
BINFILES += $(SOUNDBANK)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# use CXX for linking C++ projects, CC for standard C
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifeq ($(strip $(CPPFILES)),)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LD := $(CC)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LD := $(CXX)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||||
|
|
||||||
|
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||||
|
|
||||||
|
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
|
||||||
|
|
||||||
|
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||||
|
|
||||||
|
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
|
||||||
|
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
|
||||||
|
-I$(CURDIR)/$(BUILD)
|
||||||
|
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||||
|
|
||||||
|
ifeq ($(strip $(ICON)),)
|
||||||
|
icons := $(wildcard *.bmp)
|
||||||
|
|
||||||
|
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
|
||||||
|
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
|
||||||
|
else
|
||||||
|
ifneq (,$(findstring icon.bmp,$(icons)))
|
||||||
|
export GAME_ICON := $(CURDIR)/icon.bmp
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
ifeq ($(suffix $(ICON)), .grf)
|
||||||
|
export GAME_ICON := $(CURDIR)/$(ICON)
|
||||||
|
else
|
||||||
|
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: $(BUILD) clean
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(BUILD):
|
||||||
|
@mkdir -p $@
|
||||||
|
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
clean:
|
||||||
|
@echo clean ...
|
||||||
|
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# main targets
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(OUTPUT).nds: $(OUTPUT).elf $(NITRO_FILES) $(GAME_ICON)
|
||||||
|
$(OUTPUT).elf: $(OFILES)
|
||||||
|
|
||||||
|
# source files depend on generated headers
|
||||||
|
$(OFILES_SOURCES) : $(HFILES)
|
||||||
|
|
||||||
|
# need to build soundbank first
|
||||||
|
$(OFILES): $(SOUNDBANK)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# rule to build solution from music files
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(SOUNDBANK) : $(MODFILES)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
mmutil $^ -d -o$@ -hsoundbank.h
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.bin.o %_bin.h : %.bin
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(bin2o)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# This rule creates assembly source files using grit
|
||||||
|
# grit takes an image file and a .grit describing how the file is to be processed
|
||||||
|
# add additional rules like this for each image extension
|
||||||
|
# you use in the graphics folders
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.s %.h: %.png %.grit
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
grit $< -fts -o$*
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# Convert non-GRF game icon to GRF if needed
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(GAME_ICON): $(notdir $(ICON))
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo convert $(notdir $<)
|
||||||
|
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
|
||||||
|
|
||||||
|
-include $(DEPSDIR)/*.d
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------------
|
1
examples/3dsprites/delete/Makefile.blocksds
Normal file
1
examples/3dsprites/delete/Makefile.blocksds
Normal file
@ -0,0 +1 @@
|
|||||||
|
include ../../Makefile.example.blocksds
|
BIN
examples/3dsprites/delete/assets/bg3.png
Normal file
BIN
examples/3dsprites/delete/assets/bg3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
BIN
examples/3dsprites/delete/assets/blueball.png
Normal file
BIN
examples/3dsprites/delete/assets/blueball.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.9 KiB |
17
examples/3dsprites/delete/assets/convert.sh
Normal file
17
examples/3dsprites/delete/assets/convert.sh
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
grit blueball.png -ftb -fh! -gTFF00FF -gb -gB8 -m!
|
||||||
|
|
||||||
|
for file in *.bin; do
|
||||||
|
mv -- "$file" "${file%.bin}"
|
||||||
|
done
|
||||||
|
|
||||||
|
mv *.pal *.img ../nitrofiles/sprite
|
||||||
|
|
||||||
|
grit bg3.png -ftb -fh! -gTFF00FF -gt -gB8 -mR8 -mLs
|
||||||
|
|
||||||
|
for file in *.bin; do
|
||||||
|
mv -- "$file" "${file%.bin}"
|
||||||
|
done
|
||||||
|
|
||||||
|
mv *.pal *.img *.map ../nitrofiles/bg
|
BIN
examples/3dsprites/delete/nitrofiles/bg/bg3.img
Normal file
BIN
examples/3dsprites/delete/nitrofiles/bg/bg3.img
Normal file
Binary file not shown.
BIN
examples/3dsprites/delete/nitrofiles/bg/bg3.map
Normal file
BIN
examples/3dsprites/delete/nitrofiles/bg/bg3.map
Normal file
Binary file not shown.
BIN
examples/3dsprites/delete/nitrofiles/bg/bg3.pal
Normal file
BIN
examples/3dsprites/delete/nitrofiles/bg/bg3.pal
Normal file
Binary file not shown.
BIN
examples/3dsprites/delete/nitrofiles/sprite/blueball.img
Normal file
BIN
examples/3dsprites/delete/nitrofiles/sprite/blueball.img
Normal file
Binary file not shown.
BIN
examples/3dsprites/delete/nitrofiles/sprite/blueball.pal
Normal file
BIN
examples/3dsprites/delete/nitrofiles/sprite/blueball.pal
Normal file
Binary file not shown.
112
examples/3dsprites/delete/source/main.c
Normal file
112
examples/3dsprites/delete/source/main.c
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
//
|
||||||
|
// SPDX-FileContributor: Antonio Niño Díaz, 2023
|
||||||
|
//
|
||||||
|
// 3D sprite deletion example.
|
||||||
|
// http://www.nightfoxandco.com
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <nds.h>
|
||||||
|
#include <filesystem.h>
|
||||||
|
|
||||||
|
#include <nf_lib.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// Prepare a NitroFS initialization screen
|
||||||
|
NF_Set2D(0, 0);
|
||||||
|
NF_Set2D(1, 0);
|
||||||
|
consoleDemoInit();
|
||||||
|
printf("\n NitroFS init. Please wait.\n\n");
|
||||||
|
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
|
||||||
|
swiWaitForVBlank();
|
||||||
|
|
||||||
|
// Initialize NitroFS and set it as the root folder of the filesystem
|
||||||
|
nitroFSInit(NULL);
|
||||||
|
NF_SetRootFolder("NITROFS");
|
||||||
|
|
||||||
|
// Initialize 3D engine in the top screen in mode 0
|
||||||
|
NF_Set3D(0, 0);
|
||||||
|
|
||||||
|
// Initialize tiled backgrounds system
|
||||||
|
NF_InitTiledBgBuffers(); // Initialize storage buffers
|
||||||
|
NF_InitTiledBgSys(0); // Top screen
|
||||||
|
|
||||||
|
// Initialize 3D sprite system
|
||||||
|
NF_InitSpriteBuffers(); // Initialize storage buffers
|
||||||
|
NF_Init3dSpriteSys();
|
||||||
|
|
||||||
|
// Load background files from NitroFS
|
||||||
|
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
|
||||||
|
|
||||||
|
// Load sprite files from NitroFS
|
||||||
|
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
||||||
|
NF_LoadSpritePal("sprite/blueball", 0);
|
||||||
|
|
||||||
|
// Transfer the required sprite to VRAM
|
||||||
|
NF_Vram3dSpriteGfx(0, 0, true);
|
||||||
|
NF_Vram3dSpritePal(0, 0);
|
||||||
|
|
||||||
|
// Create background in the top screen
|
||||||
|
NF_CreateTiledBg(0, 3, "bg3");
|
||||||
|
|
||||||
|
// Create a few sprites
|
||||||
|
NF_Create3dSprite(0, 0, 0, 0, 0);
|
||||||
|
NF_Create3dSprite(1, 0, 0, 80, 0);
|
||||||
|
NF_Create3dSprite(2, 0, 0, 160, 0);
|
||||||
|
|
||||||
|
// Sort their priorites based on their IDs (lower IDs have higher priority)
|
||||||
|
NF_Sort3dSprites();
|
||||||
|
|
||||||
|
consoleClear();
|
||||||
|
printf("A: Create and delete sprites\n\n\n");
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
// Read keys
|
||||||
|
scanKeys();
|
||||||
|
u16 keys = keysDown();
|
||||||
|
|
||||||
|
if (keys & KEY_A)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Draw all 3D sprites
|
||||||
|
NF_Draw3dSprites();
|
||||||
|
|
||||||
|
// Tell the GPU to draw the scene and wait until it's done
|
||||||
|
glFlush(0);
|
||||||
|
|
||||||
|
// Wait for the screen refresh
|
||||||
|
swiWaitForVBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete one sprite
|
||||||
|
NF_Delete3dSprite(1);
|
||||||
|
|
||||||
|
// Overwrite a sprite that exists
|
||||||
|
NF_Create3dSprite(2, 0, 0, 160, 80);
|
||||||
|
|
||||||
|
// Create a new sprite
|
||||||
|
NF_Create3dSprite(3, 0, 0, 0, 80);
|
||||||
|
|
||||||
|
// Sort their priorites based on their IDs (lower IDs have higher priority)
|
||||||
|
NF_Sort3dSprites();
|
||||||
|
|
||||||
|
printf("Done!");
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
// Draw all 3D sprites
|
||||||
|
NF_Draw3dSprites();
|
||||||
|
|
||||||
|
// Tell the GPU to draw the scene and wait until it's done
|
||||||
|
glFlush(0);
|
||||||
|
|
||||||
|
// Wait for the screen refresh
|
||||||
|
swiWaitForVBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user