mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-10-29 21:12: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,10 +25,14 @@ 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;
|
||||||
|
|
||||||
|
@ -188,35 +192,41 @@ 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) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TPLDescHeader *deschead = (TPLDescHeader*)(my_tpl + TPL_HDR_DESCR_FIELD);
|
||||||
|
|
||||||
|
for(u32 c = 0; c <= id; ++c) {
|
||||||
|
u32 pos = (u32)deschead[c].imghead;
|
||||||
|
const TPLImgHeader *imghead = (TPLImgHeader*)(my_tpl + pos);
|
||||||
|
|
||||||
|
if(c == id) {
|
||||||
|
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
|
||||||
if (my_texture == NULL) {
|
if (my_texture == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
pos = (u32)imghead->data;
|
||||||
TPLFile tdf;
|
my_texture->data = (char*)(my_tpl + pos);
|
||||||
if (TPL_OpenTPLFromMemory(&tdf, my_tpl, size) > 0) {
|
my_texture->w = imghead->width;
|
||||||
const TPLDescHeader *deschead = (TPLDescHeader*)tdf.texdesc;
|
my_texture->h = imghead->height;
|
||||||
my_texture->data = deschead[id].imghead->data;
|
|
||||||
my_texture->w = deschead[id].imghead->width;
|
|
||||||
my_texture->h = deschead[id].imghead->height;
|
|
||||||
my_texture->freedata = true;
|
my_texture->freedata = true;
|
||||||
GRRLIB_SetHandle( my_texture, 0, 0 );
|
GRRLIB_SetHandle( my_texture, 0, 0 );
|
||||||
GRRLIB_FlushTex( my_texture );
|
GRRLIB_FlushTex( my_texture );
|
||||||
}
|
|
||||||
else {
|
|
||||||
free(my_texture);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return my_texture;
|
return my_texture;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a texture from a buffer.
|
* Load a texture from a buffer.
|
||||||
|
|
|
@ -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