mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-24 07:42:20 +00:00
First limited TPL implementation
This commit is contained in:
parent
35ddfba78a
commit
ffb08c5764
8 changed files with 65 additions and 4 deletions
|
@ -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.
|
||||
|
|
|
@ -43,6 +43,7 @@ THE SOFTWARE.
|
|||
// Includes
|
||||
//==============================================================================
|
||||
#include <gccore.h>
|
||||
#include <ogc/tpl.h>
|
||||
//==============================================================================
|
||||
|
||||
//==============================================================================
|
||||
|
@ -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;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
|
|
|
@ -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);
|
||||
|
|
BIN
examples/basic_drawing/textures/ballsprites.png
Normal file
BIN
examples/basic_drawing/textures/ballsprites.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
1
examples/basic_drawing/textures/textures.scf
Normal file
1
examples/basic_drawing/textures/textures.scf
Normal file
|
@ -0,0 +1 @@
|
|||
<filepath="ballsprites.png" id="ballsprites" colfmt=6 />
|
Loading…
Reference in a new issue