diff --git a/GRRLIB/GRRLIB/GRRLIB_texEdit.c b/GRRLIB/GRRLIB/GRRLIB_texEdit.c index a4c6892..a416ae3 100644 --- a/GRRLIB/GRRLIB/GRRLIB_texEdit.c +++ b/GRRLIB/GRRLIB/GRRLIB_texEdit.c @@ -143,6 +143,41 @@ GRRLIB_texImg* GRRLIB_CreateEmptyTexture (const u32 width, const u32 height) return GRRLIB_CreateEmptyTextureFmt(width, height, GX_TF_RGBA8); } +/** + * Set TPL data to a GRRLIB_texImg structure. + * @param my_tpl The TPL buffer to set. + * @param size Size of the TPL buffer to set. + * @return A GRRLIB_texImg structure filled with image information. + */ +GRRLIB_texImg* GRRLIB_LoadTextureTPL (u8 *my_tpl, const int size) { + u16 width = 0; + u16 height = 0; + const s32 id = 0; // Only id zero is valid for now + GRRLIB_texImg *my_texture = NULL; + + if(my_tpl == NULL || !size || + (my_texture = calloc(1, sizeof(GRRLIB_texImg))) == NULL) { + return NULL; + } + + TPLFile *tdf = calloc(1, sizeof(TPLFile)); + if (tdf && TPL_OpenTPLFromMemory(tdf, my_tpl, size) == 1) { + TPL_GetTextureInfo(tdf, id, NULL, &width, &height); + my_texture->data = (u8 *)my_tpl; + my_texture->w = width; + my_texture->h = height; + my_texture->tdf = tdf; + my_texture->tplid = id; + GRRLIB_SetHandle( my_texture, 0, 0 ); + GRRLIB_FlushTex( my_texture ); + } + else { + free(my_texture); + return NULL; + } + return my_texture; +} + /** * Load a texture from a buffer. * @param my_img The JPEG, PNG or Bitmap buffer to load. diff --git a/GRRLIB/GRRLIB/grrlib.h b/GRRLIB/GRRLIB/grrlib.h index a2b30e8..c3229bb 100644 --- a/GRRLIB/GRRLIB/grrlib.h +++ b/GRRLIB/GRRLIB/grrlib.h @@ -43,6 +43,7 @@ THE SOFTWARE. // Includes //============================================================================== #include +#include //============================================================================== //============================================================================== @@ -123,6 +124,8 @@ typedef struct GRRLIB_texImg { f32 ofnormaltexy;/**< Offset of normalized texture on y. */ void *data; /**< Pointer to the texture data. */ + TPLFile *tdf; /**< Pointer to the a TPL file structure. */ + s32 tplid; /**< ID to the texture number in the file. */ } GRRLIB_texImg; //------------------------------------------------------------------------------ diff --git a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h index d79a6aa..e24dca0 100644 --- a/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h +++ b/GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h @@ -142,6 +142,7 @@ GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png); GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg); GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const u32 my_size); GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp); +GRRLIB_texImg* GRRLIB_LoadTextureTPL (u8 *my_tpl, const int size); //------------------------------------------------------------------------------ // GRRLIB_gecko.c - USB_Gecko output facilities diff --git a/GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h b/GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h index ca3acdd..3fb59ed 100644 --- a/GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h +++ b/GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h @@ -49,7 +49,11 @@ void GRRLIB_FreeTexture (GRRLIB_texImg *tex) { if(tex == NULL) { return; } - if (tex->data != NULL) { + if (tex->tdf != NULL) { + TPL_CloseTPLFile(tex->tdf); + free(tex->tdf); + } + else if (tex->data != NULL) { free(tex->data); } free(tex); diff --git a/examples/basic_drawing/Makefile b/examples/basic_drawing/Makefile index 90b5b97..00e94b5 100644 --- a/examples/basic_drawing/Makefile +++ b/examples/basic_drawing/Makefile @@ -19,6 +19,7 @@ TARGET := $(notdir $(CURDIR)) BUILD := build SOURCES := source DATA := data +TEXTURES := textures INCLUDES := #--------------------------------------------------------------------------------- @@ -51,7 +52,8 @@ ifneq ($(BUILD),$(notdir $(CURDIR))) export OUTPUT := $(CURDIR)/$(TARGET) export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ + $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) export DEPSDIR := $(CURDIR)/$(BUILD) @@ -63,6 +65,8 @@ 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)/*.*))) +SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) +TPLFILES := $(SCFFILES:.scf=.tpl) #--------------------------------------------------------------------------------- # use CXX for linking C++ projects, CC for standard C @@ -73,11 +77,11 @@ else export LD := $(CXX) endif -export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) -export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) #--------------------------------------------------------------------------------- # build a list of include paths @@ -155,6 +159,12 @@ $(OFILES_SOURCES) : $(HFILES) @echo $(notdir $<) $(bin2o) +#--------------------------------------------------------------------------------- +%.tpl.o %_tpl.h : %.tpl +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + -include $(DEPENDS) #--------------------------------------------------------------------------------- diff --git a/examples/basic_drawing/source/main.c b/examples/basic_drawing/source/main.c index ebece40..e665498 100644 --- a/examples/basic_drawing/source/main.c +++ b/examples/basic_drawing/source/main.c @@ -22,6 +22,9 @@ #include "ocean_bmf.h" #include "frontal_bmf.h" +#include "textures_tpl.h" +#include "textures.h" + // Tile stuff #define TILE_DELAY 10 #define TILE_UP 12 * 0 @@ -91,6 +94,8 @@ int main() { GRRLIB_texImg *tex_BMfont5 = GRRLIB_LoadTexture(BMfont5_png); GRRLIB_InitTileSet(tex_BMfont5, 8, 16, 0); + GRRLIB_texImg *tex_test_tpl = GRRLIB_LoadTextureTPL(textures_tpl, textures_tpl_size); + while(1) { WPAD_SetVRes(0, 640, 480); WPAD_ScanPads(); @@ -109,6 +114,8 @@ int main() { GRRLIB_DrawImg(10, 50, tex_test_jpg, 0, 1, 1, GRRLIB_WHITE); // Draw a jpeg GRRLIB_DrawImg(350, 50, tex_test_bmp, 0, 4, 4, GRRLIB_WHITE); // Draw a bitmap + GRRLIB_DrawImg(400, 150, tex_test_tpl, 0, 2, 2, GRRLIB_WHITE); // Draw a TPL + // Draw a sprite GRRLIB_DrawTile(600, 400, tex_sprite_png, 0, 2, 2, GRRLIB_WHITE, 12*4); // Rupee GRRLIB_DrawTile(320+left, 240+top, tex_sprite_png, 0, 2, 2, GRRLIB_WHITE, frame); diff --git a/examples/basic_drawing/textures/ballsprites.png b/examples/basic_drawing/textures/ballsprites.png new file mode 100644 index 0000000..910cea2 Binary files /dev/null and b/examples/basic_drawing/textures/ballsprites.png differ diff --git a/examples/basic_drawing/textures/textures.scf b/examples/basic_drawing/textures/textures.scf new file mode 100644 index 0000000..7c3ded1 --- /dev/null +++ b/examples/basic_drawing/textures/textures.scf @@ -0,0 +1 @@ +