[CHG] Examples are using GRRLIB_FreeTexture

This commit is contained in:
Crayon2000 2009-03-17 03:38:34 +00:00
parent 7b3c6c0d16
commit e9bb506e09
6 changed files with 69 additions and 70 deletions

View file

@ -494,17 +494,16 @@ GRRLIB_texImg *GRRLIB_LoadTextureFromFile(const char *filename) {
fatInitDefault();
FILE *fd = fopen(filename, "rb");
fseek(fd , 0 , SEEK_END);
fseek(fd, 0, SEEK_END);
long lsize = ftell(fd);
rewind(fd);
unsigned char *buffer = (unsigned char*) malloc (sizeof(unsigned char)*lsize);
fread (buffer, 1, lsize, fd);
fclose(fd);
GRRLIB_texImg *tex = GRRLIB_LoadTexture(buffer);
free(buffer);
fclose(fd);
return tex;
}

View file

@ -215,13 +215,13 @@ int main() {
}
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
// Free some textures
free(tex_test_jpg);
free(tex_sprite_png);
free(tex_BMfont1);
free(tex_BMfont2);
free(tex_BMfont3);
free(tex_BMfont4);
free(tex_BMfont5);
GRRLIB_FreeTexture(tex_test_jpg);
GRRLIB_FreeTexture(tex_sprite_png);
GRRLIB_FreeTexture(tex_BMfont1);
GRRLIB_FreeTexture(tex_BMfont2);
GRRLIB_FreeTexture(tex_BMfont3);
GRRLIB_FreeTexture(tex_BMfont4);
GRRLIB_FreeTexture(tex_BMfont5);
GRRLIB_FreeBMF(bmf_Font1);
GRRLIB_FreeBMF(bmf_Font2);
return 0;

View file

@ -192,29 +192,29 @@ int main() {
}
}
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
free(tex_pirate);
free(tex_gray);
free(tex_invert);
free(tex_fliph);
free(tex_flipv);
free(tex_fliphv);
free(tex_blur1);
free(tex_blur2);
free(tex_blur3);
free(tex_blur4);
free(tex_blur5);
free(tex_blur6);
free(tex_pixel1);
free(tex_pixel2);
free(tex_pixel3);
free(tex_pixel4);
free(tex_pixel5);
free(tex_pixel6);
free(tex_scatter1);
free(tex_scatter2);
free(tex_scatter3);
free(tex_scatter4);
free(tex_scatter5);
free(tex_scatter6);
GRRLIB_FreeTexture(tex_pirate);
GRRLIB_FreeTexture(tex_gray);
GRRLIB_FreeTexture(tex_invert);
GRRLIB_FreeTexture(tex_fliph);
GRRLIB_FreeTexture(tex_flipv);
GRRLIB_FreeTexture(tex_fliphv);
GRRLIB_FreeTexture(tex_blur1);
GRRLIB_FreeTexture(tex_blur2);
GRRLIB_FreeTexture(tex_blur3);
GRRLIB_FreeTexture(tex_blur4);
GRRLIB_FreeTexture(tex_blur5);
GRRLIB_FreeTexture(tex_blur6);
GRRLIB_FreeTexture(tex_pixel1);
GRRLIB_FreeTexture(tex_pixel2);
GRRLIB_FreeTexture(tex_pixel3);
GRRLIB_FreeTexture(tex_pixel4);
GRRLIB_FreeTexture(tex_pixel5);
GRRLIB_FreeTexture(tex_pixel6);
GRRLIB_FreeTexture(tex_scatter1);
GRRLIB_FreeTexture(tex_scatter2);
GRRLIB_FreeTexture(tex_scatter3);
GRRLIB_FreeTexture(tex_scatter4);
GRRLIB_FreeTexture(tex_scatter5);
GRRLIB_FreeTexture(tex_scatter6);
return 0;
}

View file

@ -29,13 +29,13 @@ int main() {
GRRLIB_Init();
WPAD_Init();
GRRLIB_texImg *tex_pirate = GRRLIB_LoadTexture(pirate);
while(1) {
WPAD_ScanPads();
wpaddown = WPAD_ButtonsDown(0);
a=a+0.04;
b=b+0.02;
a+=0.04;
b+=0.02;
for(i=0;i<4;i++){
xt=l[i].x*cos(a)-l[i].z*sin(a);
yt=l[i].y;
@ -50,7 +50,6 @@ int main() {
GRRLIB_FillScreen(0xFFFFFFFF);
GRRLIB_DrawImgQuad(d, tex_pirate, 0xFFFFFFFF);
GRRLIB_Render();
if(wpaddown & WPAD_BUTTON_HOME) {
@ -58,5 +57,6 @@ int main() {
}
}
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
GRRLIB_FreeTexture(tex_pirate);
return 0;
}

View file

@ -37,13 +37,13 @@ int main() {
u32 WPADKeyHeld;
short WinW, WinH;
int P1MX, P1MY;
u8 Stage = 0, Blending = 0;
u8 BlobType = 0;
u8 Color = 255;
u16 Step = 0;
float SX, SY;
// Init GRRLIB & WiiUse
GRRLIB_Init();
@ -52,7 +52,7 @@ int main() {
WPAD_Init();
WPAD_SetIdleTimeout( 60*10 );
WPAD_SetDataFormat( WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR );
// Load Textures
GFX_Background = GRRLIB_LoadTextureJPG(RGFX_Background);
GFX_Blob[0] = GRRLIB_LoadTexturePNG(RGFX_Blob01);
@ -60,12 +60,12 @@ int main() {
GFX_Blob[2] = GRRLIB_LoadTexturePNG(RGFX_Blob03);
GFX_Font = GRRLIB_LoadTexturePNG(RGFX_Font);
GRRLIB_InitTileSet(GFX_Font, 8, 16, 32);
// Set Handles
GRRLIB_SetMidHandle( GFX_Blob[0], true );
GRRLIB_SetMidHandle( GFX_Blob[1], true );
GRRLIB_SetMidHandle( GFX_Blob[2], true );
while (true) {
WPAD_ScanPads();
@ -73,17 +73,17 @@ int main() {
WPADKeyHeld = WPAD_ButtonsHeld(WPAD_CHAN_0);
WPAD_SetVRes(WPAD_CHAN_0, WinW, WinH);
WPAD_IR(WPAD_CHAN_0, &P1Mote);
// WiiMote IR Viewport Correction
P1MX = P1Mote.sx - 150;
P1MY = P1Mote.sy - 150;
// Update Stage
Step = Step + 1;
if (Step == 720) { Step = 0; }
SX = 320 + (sin(DegToRad(Step )) * 250);
SY = 240 + (cos(DegToRad(Step*3)) * 100);
// Draw Stage
GRRLIB_DrawImg( 0, 0, GFX_Background, 0, 1, 1, GRRLIB_GetColor(255, 255, 255, 255) );
GRRLIB_SetBlend( (Blending+1) ); Color = 255;
@ -93,12 +93,12 @@ int main() {
case 4: Color = 64; break;
}
GRRLIB_DrawImg( SX, SY, GFX_Blob[BlobType], 0, 1, 1, GRRLIB_GetColor(Color, Color, Color, 255) );
// IR Pointer
if (P1Mote.state == 1) {
GRRLIB_DrawImg( P1MX, P1MY, GFX_Blob[BlobType], 0, 1, 1, GRRLIB_GetColor(Color, Color, Color, 255) );
}
// Draw Text
GRRLIB_SetBlend ( GRRLIB_BLEND_ALPHA );
GRRLIB_Rectangle( 28, 28, 480 + 16, 76, GRRLIB_GetColor(0, 0, 0, 160), 1 );
@ -127,14 +127,14 @@ int main() {
static void ExitGame() {
// Deinitialize GRRLIB & Video
GRRLIB_Exit();
// Free all memory used by textures.
free(GFX_Background);
free(GFX_Blob[0]);
free(GFX_Blob[1]);
free(GFX_Blob[2]);
free(GFX_Font);
GRRLIB_FreeTexture(GFX_Background);
GRRLIB_FreeTexture(GFX_Blob[0]);
GRRLIB_FreeTexture(GFX_Blob[1]);
GRRLIB_FreeTexture(GFX_Blob[2]);
GRRLIB_FreeTexture(GFX_Font);
// Exit application
exit(0);
}

View file

@ -1,7 +1,7 @@
/*===========================================
GRRLIB (GX Version)
Example code by Xane
This example shows a basic particle
engine creating a Smokebomb.
============================================*/
@ -73,7 +73,7 @@ GRRLIB_texImg *GFX_Font;
int main() {
u32 WPADKeyDown;
u32 WPADKeyHeld;
u8 FPS = 0;
u32 ParticleCnt = 0;
@ -84,18 +84,18 @@ int main() {
WPAD_Init();
WPAD_SetIdleTimeout( 60*10 );
WPAD_SetDataFormat( WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR );
// Load textures
GFX_Background = GRRLIB_LoadTextureJPG(RGFX_Background);
GFX_Crosshair = GRRLIB_LoadTexturePNG(RGFX_Crosshair);
GFX_Smoke = GRRLIB_LoadTexturePNG(RGFX_Smoke);
GFX_Font = GRRLIB_LoadTexturePNG(RGFX_Font);
GFX_Font = GRRLIB_LoadTexturePNG(RGFX_Font);
GRRLIB_InitTileSet( GFX_Font, 8, 16, 32 );
// Set handles
GRRLIB_SetMidHandle( GFX_Crosshair, true );
GRRLIB_SetMidHandle( GFX_Smoke, true );
// Feed the vector with the textures
TextureList.push_back( GFX_Background );
TextureList.push_back( GFX_Crosshair );
@ -108,15 +108,15 @@ int main() {
WPADKeyHeld = WPAD_ButtonsHeld(WPAD_CHAN_0);
WPAD_SetVRes(WPAD_CHAN_0, WinW, WinH);
WPAD_IR(WPAD_CHAN_0, &P1Mote);
// Resetting Vars
GRRLIB_SetBlend( GRRLIB_BLEND_ALPHA );
ParticleCnt = 0;
// WiiMote IR Viewport correction
P1MX = P1Mote.sx - 150;
P1MY = P1Mote.sy - 150;
// Drawing Background
GRRLIB_DrawImg( 0, 0, GFX_Background, 0, 1, 1, GRRLIB_GetColor(255, 255, 255, 255) );
@ -140,7 +140,7 @@ int main() {
ParticleCnt += 1;
PartIter++;
}
// Draw Crosshair
GRRLIB_DrawImg( P1MX, P1MY, GFX_Crosshair, 0, 1, 1, GRRLIB_GetColor(255, 255, 255, 255) );
@ -155,7 +155,7 @@ int main() {
// Renders the Scene
GRRLIB_Render();
FPS = CalculateFrameRate();
if (WPADKeyDown & WPAD_BUTTON_B) {
createEffect( EFFECT_SMOKEBOMB, P1MX, P1MY );
}
@ -196,7 +196,7 @@ static void createParticle( u8 _id, int _x, int _y, float _scale, float _alpha,
part->blue = _blue;
part->scale = _scale;
part->alpha = _alpha;
part->tex = GFX_Smoke;
part->sy = RANDOM;
part->sx = RANDOM;
@ -259,14 +259,14 @@ static bool updateParticle( Particle *part ) {
static void ExitGame() {
// Deinitialize GRRLIB & Video
GRRLIB_Exit();
// Free all memory used by textures.
for (vector<GRRLIB_texImg *>::iterator TexIter = TextureList.begin(); TexIter != TextureList.end(); TexIter++) {
free((*TexIter)->data);
free((*TexIter));
}
TextureList.clear();
// Exit application
exit(0);
}