From ffb08c576436c47afd8d802dfef4501fe073ff7e Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Mon, 4 Mar 2024 15:35:56 -0500 Subject: [PATCH] First limited TPL implementation --- GRRLIB/GRRLIB/GRRLIB_texEdit.c | 35 ++++++++++++++++++ GRRLIB/GRRLIB/grrlib.h | 3 ++ GRRLIB/GRRLIB/grrlib/GRRLIB__lib.h | 1 + GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h | 6 ++- examples/basic_drawing/Makefile | 16 ++++++-- examples/basic_drawing/source/main.c | 7 ++++ .../basic_drawing/textures/ballsprites.png | Bin 0 -> 5600 bytes examples/basic_drawing/textures/textures.scf | 1 + 8 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 examples/basic_drawing/textures/ballsprites.png create mode 100644 examples/basic_drawing/textures/textures.scf 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 0000000000000000000000000000000000000000..910cea245f21059a2022c15b9e741ebaa4713947 GIT binary patch literal 5600 zcmV<66(8z}P)~-DWl4#4VL3=7 zFaeSm{|SaEBeoOAmMu$`Wl31c7S@3*0RlFNWgv*1H(OS0zy|!}AP;sB(DqYc3xa>_ zdb3)tmR#5A`Tt zzWQ%|N;rQWR#spz0Hxyx)eOdC80~ZYH-Gbyp7|)_A6qLs#;~q6L#0TwGZSGX!o3jq z%esD~`5)@bSAXe~!p;u#dSDCC>1P=L3Gv!Ea1HG3!HX|({r7+Wy8_0)C`-9)3Z(P5Z?E`D0o>$fo&4nn8g>pPb&#=HQqyA z!;KqUf8m9948r@Yl^-e!hDuQ?g#m2(Oe-}Pz>CD`)2jh05ngtVKl=_A@xTwSe)MOB zr{5EWFANwPHE&D=LaTVq+7A*1mk_TmL=f)0#r5ZZ?U6zFU{T03ML}OFO28_GN&x7V z6-evlMewcb47lYze>|H#aQ^##aP{YYPI%AL(CI>_h}vH{1H)kipswS-pKCs90N2EO z-pB2bx5VAMT>sTCJTwUZq$uPAN%#)XRf;vOSyc+H6txIb5t{V<41g2CrEA^}6>!^o z{^$W9oVt1SC;qkY%(GGRodV8o!ebXnvM+lj(oya<;s!{d*$UKaEK1607#xlJbLx8TNWFd9X{Z5G~usu#}; zz{QJP{dYet*MIxJye$YHEDCx_^G{gIdyL^yzt5TVbxgMlMS)BvTsS`F!g$QfO~Y;o zcoE7Zc%>9Z1d^W!z-422wkYJUn`UYLB>=8|?m3}9fUXE=*>;g8aX^f4TsR}vi`S!%Z1%tW=(@uiuvp!g!Fev zPO+yHA1+Jzi&kWq190^d9~TN67h0CEx=MFA;5>>A;4+F$qSM$%5r__EgkpbV1Mcm{ z2Q}`r@I`WrMTk~)pYh?cloBY2PH#hN)_Xn7&JJd43v=ZPW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