mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-21 14:32:20 +00:00
Compare commits
8 commits
b1fdc58bed
...
507186821c
Author | SHA1 | Date | |
---|---|---|---|
|
507186821c | ||
|
3bb5817f33 | ||
|
7d08f7eed5 | ||
|
6795c0b1ce | ||
|
d65a16765b | ||
|
d67e646e67 | ||
|
fee01d1f4c | ||
|
efdbfedb30 |
10 changed files with 126 additions and 5 deletions
|
@ -28,6 +28,64 @@ THE SOFTWARE.
|
|||
|
||||
#include <grrlib.h>
|
||||
|
||||
#define TPL_HDR_VERSION_FIELD 0 /**< Version field. */
|
||||
#define TPL_HDR_NTEXTURE_FIELD 4 /**< Textrure field. */
|
||||
#define TPL_HDR_HDRSIZE_FIELD 8 /**< Header size field. */
|
||||
#define TPL_HDR_DESCR_FIELD 12 /**< Descriptor field. */
|
||||
|
||||
/**
|
||||
* Texture header.
|
||||
*/
|
||||
typedef struct _tplimgheader TPLImgHeader;
|
||||
|
||||
/**
|
||||
* Texture header.
|
||||
*/
|
||||
struct _tplimgheader {
|
||||
u16 height; /**< Height of the texture in pixels. */
|
||||
u16 width; /**< Width of the texture in pixels. */
|
||||
u32 fmt; /**< Format of the texture. */
|
||||
void *data; /**< Pointer to the texture data. */
|
||||
u32 wraps; /**< Texture coordinate wrapping strategy in the S direction. */
|
||||
u32 wrapt; /**< Texture coordinate wrapping strategy in the T direction. */
|
||||
u32 minfilter; /**< Filter mode when the texel/pixel ratio is ≤ 1.0. */
|
||||
u32 magfilter; /**< Filter mode when the texel/pixel ratio is > 1.0. */
|
||||
f32 lodbias; /**< LOD bias. */
|
||||
u8 edgelod; /**< Edge LOD. */
|
||||
u8 minlod; /**< Minimum LOD value. */
|
||||
u8 maxlod; /**< Maximum LOD value. */
|
||||
u8 unpacked; /**< Internal flag. */
|
||||
} ATTRIBUTE_PACKED;
|
||||
|
||||
/**
|
||||
* Texture palette header.
|
||||
*/
|
||||
typedef struct _tplpalheader TPLPalHeader;
|
||||
|
||||
/**
|
||||
* Texture palette header.
|
||||
*/
|
||||
struct _tplpalheader {
|
||||
u16 nitems; /**< Number of palette entries. */
|
||||
u8 unpacked; /**< Internal flag. */
|
||||
u8 pad; /**< Padding. */
|
||||
u32 fmt; /**< Format of the color lookup table (CLUT). */
|
||||
void *data; /**< Pointer to the color lookup table (CLUT) data. */
|
||||
} ATTRIBUTE_PACKED;
|
||||
|
||||
/**
|
||||
* Texture descriptor.
|
||||
*/
|
||||
typedef struct _tpldesc TPLDescHeader;
|
||||
|
||||
/**
|
||||
* Texture descriptor.
|
||||
*/
|
||||
struct _tpldesc {
|
||||
TPLImgHeader *imghead; /**< Pointer to texture header structure. */
|
||||
TPLPalHeader *palhead; /**< Pointer to color lookup table (CLUT) header. */
|
||||
} ATTRIBUTE_PACKED;
|
||||
|
||||
/**
|
||||
* This structure contains information about the type, size, and layout of a file that containing a device-independent bitmap (DIB).
|
||||
*/
|
||||
|
@ -143,6 +201,44 @@ 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 (const u8 *my_tpl, const int size, u32 id) {
|
||||
if(my_tpl == NULL || size <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const u32 ntextures = *(u32*)(my_tpl + TPL_HDR_NTEXTURE_FIELD);
|
||||
if(id > ntextures) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
|
||||
if (my_texture == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const TPLDescHeader *deschead = (TPLDescHeader*)(my_tpl + TPL_HDR_DESCR_FIELD);
|
||||
|
||||
u32 pos = (u32)deschead[id].imghead;
|
||||
const TPLImgHeader *imghead = (TPLImgHeader*)(my_tpl + pos);
|
||||
|
||||
pos = (u32)imghead->data;
|
||||
my_texture->data = (u8*)(my_tpl + pos);
|
||||
my_texture->w = imghead->width;
|
||||
my_texture->h = imghead->height;
|
||||
my_texture->format = imghead->fmt;
|
||||
my_texture->freedata = true;
|
||||
GRRLIB_SetHandle( my_texture, 0, 0 );
|
||||
GRRLIB_FlushTex( my_texture );
|
||||
|
||||
return my_texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a texture from a buffer.
|
||||
* @param my_img The JPEG, PNG or Bitmap buffer to load.
|
||||
|
|
|
@ -123,6 +123,7 @@ typedef struct GRRLIB_texImg {
|
|||
f32 ofnormaltexy;/**< Offset of normalized texture on y. */
|
||||
|
||||
void *data; /**< Pointer to the texture data. */
|
||||
bool freedata; /**< Should the data be freed. */
|
||||
} 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 (const u8 *my_tpl, const int size, u32 id);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// GRRLIB_gecko.c - USB_Gecko output facilities
|
||||
|
|
|
@ -49,7 +49,7 @@ void GRRLIB_FreeTexture (GRRLIB_texImg *tex) {
|
|||
if(tex == NULL) {
|
||||
return;
|
||||
}
|
||||
if (tex->data != NULL) {
|
||||
if (tex->data != NULL && tex->freedata == true) {
|
||||
free(tex->data);
|
||||
}
|
||||
free(tex);
|
||||
|
@ -61,7 +61,7 @@ void GRRLIB_FreeTexture (GRRLIB_texImg *tex) {
|
|||
*/
|
||||
INLINE
|
||||
void GRRLIB_ClearTex(GRRLIB_texImg* tex) {
|
||||
if(tex == NULL) {
|
||||
if(tex == NULL || tex->freedata == false) {
|
||||
return;
|
||||
}
|
||||
memset(tex->data, 0, GX_GetTexBufferSize(tex->w, tex->h, tex->format, 0, 0));
|
||||
|
|
|
@ -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,10 @@ int main() {
|
|||
GRRLIB_texImg *tex_BMfont5 = GRRLIB_LoadTexture(BMfont5_png);
|
||||
GRRLIB_InitTileSet(tex_BMfont5, 8, 16, 0);
|
||||
|
||||
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);
|
||||
GRRLIB_texImg *tex_test_tpl3 = GRRLIB_LoadTextureTPL(textures_tpl, textures_tpl_size, girl);
|
||||
|
||||
while(1) {
|
||||
WPAD_SetVRes(0, 640, 480);
|
||||
WPAD_ScanPads();
|
||||
|
@ -109,6 +116,9 @@ 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, 200, tex_test_tpl1, 0, 2, 2, GRRLIB_WHITE); // Draw a TPL
|
||||
GRRLIB_DrawImg(100, 200, tex_test_tpl3, 0, 1, 1, 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 |
BIN
examples/basic_drawing/textures/girl.png
Normal file
BIN
examples/basic_drawing/textures/girl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 154 KiB |
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 |
3
examples/basic_drawing/textures/textures.scf
Normal file
3
examples/basic_drawing/textures/textures.scf
Normal file
|
@ -0,0 +1,3 @@
|
|||
<filepath="ballsprites.png" id="ballsprites" colfmt=6 />
|
||||
<filepath="pirate.png" id="pirate" colfmt=6 />
|
||||
<filepath="girl.png" id="girl" colfmt=5 />
|
Loading…
Reference in a new issue