mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-21 14:32:20 +00:00
Add id parameter to GRRLIB_LoadTextureTPL
This commit is contained in:
parent
1510e5326b
commit
b1d7144ad2
6 changed files with 58 additions and 45 deletions
|
@ -25,46 +25,50 @@ THE SOFTWARE.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <jpeglib.h>
|
#include <jpeglib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ogc/tpl.h>
|
|
||||||
|
|
||||||
#include <grrlib.h>
|
#include <grrlib.h>
|
||||||
|
|
||||||
|
#define TPL_HDR_VERSION_FIELD 0
|
||||||
|
#define TPL_HDR_NTEXTURE_FIELD 4
|
||||||
|
#define TPL_HDR_HDRSIZE_FIELD 8
|
||||||
|
#define TPL_HDR_DESCR_FIELD 12
|
||||||
|
|
||||||
// texture header
|
// texture header
|
||||||
typedef struct _tplimgheader TPLImgHeader;
|
typedef struct _tplimgheader TPLImgHeader;
|
||||||
|
|
||||||
struct _tplimgheader {
|
struct _tplimgheader {
|
||||||
u16 height;
|
u16 height;
|
||||||
u16 width;
|
u16 width;
|
||||||
u32 fmt;
|
u32 fmt;
|
||||||
void *data;
|
void *data;
|
||||||
u32 wraps;
|
u32 wraps;
|
||||||
u32 wrapt;
|
u32 wrapt;
|
||||||
u32 minfilter;
|
u32 minfilter;
|
||||||
u32 magfilter;
|
u32 magfilter;
|
||||||
f32 lodbias;
|
f32 lodbias;
|
||||||
u8 edgelod;
|
u8 edgelod;
|
||||||
u8 minlod;
|
u8 minlod;
|
||||||
u8 maxlod;
|
u8 maxlod;
|
||||||
u8 unpacked;
|
u8 unpacked;
|
||||||
} ATTRIBUTE_PACKED;
|
} ATTRIBUTE_PACKED;
|
||||||
|
|
||||||
// texture palette header
|
// texture palette header
|
||||||
typedef struct _tplpalheader TPLPalHeader;
|
typedef struct _tplpalheader TPLPalHeader;
|
||||||
|
|
||||||
struct _tplpalheader {
|
struct _tplpalheader {
|
||||||
u16 nitems;
|
u16 nitems;
|
||||||
u8 unpacked;
|
u8 unpacked;
|
||||||
u8 pad;
|
u8 pad;
|
||||||
u32 fmt;
|
u32 fmt;
|
||||||
void *data;
|
void *data;
|
||||||
} ATTRIBUTE_PACKED;
|
} ATTRIBUTE_PACKED;
|
||||||
|
|
||||||
// texture descriptor
|
// texture descriptor
|
||||||
typedef struct _tpldesc TPLDescHeader;
|
typedef struct _tpldesc TPLDescHeader;
|
||||||
|
|
||||||
struct _tpldesc {
|
struct _tpldesc {
|
||||||
TPLImgHeader *imghead;
|
TPLImgHeader *imghead;
|
||||||
TPLPalHeader *palhead;
|
TPLPalHeader *palhead;
|
||||||
} ATTRIBUTE_PACKED;
|
} ATTRIBUTE_PACKED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,34 +192,40 @@ GRRLIB_texImg* GRRLIB_CreateEmptyTexture (const u32 width, const u32 height)
|
||||||
* @param size Size of the TPL buffer to set.
|
* @param size Size of the TPL buffer to set.
|
||||||
* @return A GRRLIB_texImg structure filled with image information.
|
* @return A GRRLIB_texImg structure filled with image information.
|
||||||
*/
|
*/
|
||||||
GRRLIB_texImg* GRRLIB_LoadTextureTPL (u8 *my_tpl, const int size) {
|
GRRLIB_texImg* GRRLIB_LoadTextureTPL (const u8 *my_tpl, const int size, u32 id) {
|
||||||
const s32 id = 0; // Only id zero is valid for now
|
|
||||||
|
|
||||||
if(my_tpl == NULL || size <= 0) {
|
if(my_tpl == NULL || size <= 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
|
const u32 ntextures = *(u32*)(my_tpl + TPL_HDR_NTEXTURE_FIELD);
|
||||||
|
if(id > ntextures) {
|
||||||
if (my_texture == NULL) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TPLFile tdf;
|
const TPLDescHeader *deschead = (TPLDescHeader*)(my_tpl + TPL_HDR_DESCR_FIELD);
|
||||||
if (TPL_OpenTPLFromMemory(&tdf, my_tpl, size) > 0) {
|
|
||||||
const TPLDescHeader *deschead = (TPLDescHeader*)tdf.texdesc;
|
for(u32 c = 0; c <= id; ++c) {
|
||||||
my_texture->data = deschead[id].imghead->data;
|
u32 pos = (u32)deschead[c].imghead;
|
||||||
my_texture->w = deschead[id].imghead->width;
|
const TPLImgHeader *imghead = (TPLImgHeader*)(my_tpl + pos);
|
||||||
my_texture->h = deschead[id].imghead->height;
|
|
||||||
my_texture->freedata = true;
|
if(c == id) {
|
||||||
GRRLIB_SetHandle( my_texture, 0, 0 );
|
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
|
||||||
GRRLIB_FlushTex( my_texture );
|
if (my_texture == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
pos = (u32)imghead->data;
|
||||||
|
my_texture->data = (char*)(my_tpl + pos);
|
||||||
|
my_texture->w = imghead->width;
|
||||||
|
my_texture->h = imghead->height;
|
||||||
|
my_texture->freedata = true;
|
||||||
|
GRRLIB_SetHandle( my_texture, 0, 0 );
|
||||||
|
GRRLIB_FlushTex( my_texture );
|
||||||
|
|
||||||
|
return my_texture;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
free(my_texture);
|
return NULL;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return my_texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -142,7 +142,7 @@ GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png);
|
||||||
GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg);
|
GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg);
|
||||||
GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const u32 my_size);
|
GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const u32 my_size);
|
||||||
GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp);
|
GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp);
|
||||||
GRRLIB_texImg* GRRLIB_LoadTextureTPL (u8 *my_tpl, const int size);
|
GRRLIB_texImg* GRRLIB_LoadTextureTPL (const u8 *my_tpl, const int size, u32 id);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// GRRLIB_gecko.c - USB_Gecko output facilities
|
// GRRLIB_gecko.c - USB_Gecko output facilities
|
||||||
|
|
|
@ -61,7 +61,7 @@ void GRRLIB_FreeTexture (GRRLIB_texImg *tex) {
|
||||||
*/
|
*/
|
||||||
INLINE
|
INLINE
|
||||||
void GRRLIB_ClearTex(GRRLIB_texImg* tex) {
|
void GRRLIB_ClearTex(GRRLIB_texImg* tex) {
|
||||||
if(tex == NULL) {
|
if(tex == NULL || tex->freedata == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memset(tex->data, 0, GX_GetTexBufferSize(tex->w, tex->h, tex->format, 0, 0));
|
memset(tex->data, 0, GX_GetTexBufferSize(tex->w, tex->h, tex->format, 0, 0));
|
||||||
|
|
|
@ -94,7 +94,8 @@ int main() {
|
||||||
GRRLIB_texImg *tex_BMfont5 = GRRLIB_LoadTexture(BMfont5_png);
|
GRRLIB_texImg *tex_BMfont5 = GRRLIB_LoadTexture(BMfont5_png);
|
||||||
GRRLIB_InitTileSet(tex_BMfont5, 8, 16, 0);
|
GRRLIB_InitTileSet(tex_BMfont5, 8, 16, 0);
|
||||||
|
|
||||||
GRRLIB_texImg *tex_test_tpl = GRRLIB_LoadTextureTPL(textures_tpl, textures_tpl_size);
|
GRRLIB_texImg *tex_test_tpl1 = GRRLIB_LoadTextureTPL(textures_tpl, textures_tpl_size, ballsprites);
|
||||||
|
GRRLIB_texImg *tex_test_tpl2 = GRRLIB_LoadTextureTPL(textures_tpl, textures_tpl_size, pirate);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
WPAD_SetVRes(0, 640, 480);
|
WPAD_SetVRes(0, 640, 480);
|
||||||
|
@ -114,7 +115,8 @@ int main() {
|
||||||
GRRLIB_DrawImg(10, 50, tex_test_jpg, 0, 1, 1, GRRLIB_WHITE); // Draw a jpeg
|
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(350, 50, tex_test_bmp, 0, 4, 4, GRRLIB_WHITE); // Draw a bitmap
|
||||||
|
|
||||||
GRRLIB_DrawImg(400, 200, tex_test_tpl, 0, 2, 2, GRRLIB_WHITE); // Draw a TPL
|
GRRLIB_DrawImg(400, 200, tex_test_tpl1, 0, 2, 2, GRRLIB_WHITE); // Draw a TPL
|
||||||
|
GRRLIB_DrawImg(400, 300, tex_test_tpl2, 0, 1, 1, GRRLIB_WHITE); // Draw a TPL
|
||||||
|
|
||||||
// Draw a sprite
|
// Draw a sprite
|
||||||
GRRLIB_DrawTile(600, 400, tex_sprite_png, 0, 2, 2, GRRLIB_WHITE, 12*4); // Rupee
|
GRRLIB_DrawTile(600, 400, tex_sprite_png, 0, 2, 2, GRRLIB_WHITE, 12*4); // Rupee
|
||||||
|
|
BIN
examples/basic_drawing/textures/pirate.png
Normal file
BIN
examples/basic_drawing/textures/pirate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
|
@ -1 +1,2 @@
|
||||||
<filepath="ballsprites.png" id="ballsprites" colfmt=6 />
|
<filepath="ballsprites.png" id="ballsprites" colfmt=6 />
|
||||||
|
<filepath="pirate.png" id="pirate" colfmt=6 />
|
||||||
|
|
Loading…
Reference in a new issue