You are not logged in.
Below some functions implemented in GRRLIB:
-- GRRLIB_DrawImg_FadeInOut (width, height, image, scale X, Y scale, speed);
Performs a fade in and out of selected images.
-- GRRLIB_DrawImg_FadeIn (width, height, image, scale X, Y scale, speed);
Performs fade in the image selected.
-- GRRLIB_DrawImg_FadeOut (width, height, image, scale X, Y scale, speed);
Performs fade out in selected image.
-- GRRLIB_FadeScr ();
It should be used to capture the screen of the current system and make a fade out.
The next functions were withdrawn from this forum
-- GRRLIB_ScrShot (const char *);
Save a PNG file of the screen capture.
-- GRRLIB_ScreenCap ();
Used to capture a screen and send a variable u32 to be used later, its use is given as follows: u32 tex_scrTmp = GRRLIB_ScreenCap ();
inline void GRRLIB_DrawImg_FadeInOut(u16 width, u16 height, u8 data[], float scaleX, f32 scaleY, u16 speed) { GRRLIB_DrawImg_FadeIn(width, height, data, scaleX, scaleY, speed); GRRLIB_DrawImg_FadeOut(width, height, data, scaleX, scaleY, speed); } inline void GRRLIB_DrawImg_FadeIn(u16 width, u16 height, u8 data[], float scaleX, f32 scaleY, u16 speed) { alpha=0; for (alpha=0 ; alpha < 255 ; ) { GRRLIB_DrawImg((640-width)/2, (480-height)/2, width, height, data, 0, scaleX, scaleY, alpha ); GRRLIB_Render(); alpha = alpha + speed; } } inline void GRRLIB_DrawImg_FadeOut(u16 width, u16 height, u8 data[], float scaleX, f32 scaleY, u16 speed) { alpha=0; for (alpha=255 ; alpha > 0 ; --alpha) { GRRLIB_DrawImg((640-width)/2, (480-height)/2, width, height, data, 0, scaleX, scaleY, alpha ); GRRLIB_Render(); alpha = alpha - speed; } } u8 * GRRLIB_LoadTextureFromFile(const char *filename) { PNGUPROP imgProp; IMGCTX ctx; void *my_texture; ctx = PNGU_SelectImageFromDevice(filename); PNGU_GetImageProperties (ctx, &imgProp); my_texture = memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4); PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture, 255); PNGU_ReleaseImageContext (ctx); DCFlushRange (my_texture, imgProp.imgWidth * imgProp.imgHeight * 4); return my_texture; } bool GRRLIB_ScrShot(const char* File) { IMGCTX pngContext; int ErrorCode = -1; if(fatInitDefault() && (pngContext = PNGU_SelectImageFromDevice(File))) { ErrorCode = PNGU_EncodeFromYCbYCr(pngContext, 640, 480, xfb[fb], 0); PNGU_ReleaseImageContext(pngContext); if(!fatUnmount(PI_INTERNAL_SD)) { // I can only hope it's better than nothing fatUnsafeUnmount(PI_INTERNAL_SD); } } return !ErrorCode; } void GRRLIB_FadeScr() { tex_scrTmp = GRRLIB_ScreenCap(); GRRLIB_DrawImg_FadeOut(640, 480, tex_scrTmp, 1, 1, 5); } u8 *GRRLIB_ScreenCap() { void *my_texture; int i; for (i=0;i<2;++i) { GX_SetTexCopySrc(0, 0, 640, 480); GX_SetTexCopyDst(640, 480, GX_TF_RGBA8, GX_FALSE); my_texture = memalign(32, 640 * 480 * 4); // GX_GetTexBufferSize(640, 480, GX_TF_RGBA8, GX_FALSE, 1) GX_CopyTex(my_texture, GX_FALSE); } return my_texture; }
bmic
Offline
Hi, I just want to give you my modify Fade In/Out function. xpos and ypos are calculate once instead of a maximum of 256. So there is 511 less division and 511 less subtraction. I added some information directly in the for loop and some Doxygen comments. I hope you like it!
/** * Fade in, than fade out * @param width Texture width. * @param height Texture height. * @param data Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeInOut(u16 width, u16 height, u8 data[], float scaleX, f32 scaleY, u16 speed) { GRRLIB_DrawImg_FadeIn(width, height, data, scaleX, scaleY, speed); GRRLIB_DrawImg_FadeOut(width, height, data, scaleX, scaleY, speed); } /** * Fade in * @param width Texture width. * @param height Texture height. * @param data Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeIn(u16 width, u16 height, u8 data[], float scaleX, f32 scaleY, u16 speed) { int alpha; f32 xpos = (640 - width) / 2; f32 ypos = (480 - height) / 2; for(alpha = 0; alpha < 255; alpha += speed) { GRRLIB_DrawImg(xpos, ypos, width, height, data, 0, scaleX, scaleY, alpha); GRRLIB_Render(); } } /** * Fade out * @param width Texture width. * @param height Texture height. * @param data Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeOut(u16 width, u16 height, u8 data[], float scaleX, f32 scaleY, u16 speed) { int alpha; f32 xpos = (640 - width) / 2; f32 ypos = (480 - height) / 2; for(alpha = 255; alpha > 0; alpha -= speed) { GRRLIB_DrawImg(xpos, ypos, width, height, data, 0, scaleX, scaleY, alpha); GRRLIB_Render(); } }
PS: Could you explain me why you did a loop in the GRRLIB_ScreenCap function?
Offline
So... you are locking everything else from drawing while you fade, even the CPU?
If you are going to just be doing that texture, you could do something about just locking it to TEX0, and not resetting it to a new TexObj pointer every time with TexInit (though I don't think that is really hurting, since the memory location of the texture data is the same each time. I think that is what the texture cache uses to check if it should send a new texture to the chip)
*Note about the screen capture: That's a 1.2 mb leak :-(
Last edited by RedShade (2008-07-22 07:09:19)
Offline
Crayon wrote:
Hi, I just want to give you my modify Fade In/Out function. xpos and ypos are calculate once instead of a maximum of 256. So there is 511 less division and 511 less subtraction. I added some information directly in the for loop and some Doxygen comments. I hope you like it!
Code:
/** * Fade in, than fade out * @param width Texture width. * @param height Texture height. * @param data Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeInOut(u16 width, u16 height, u8 data[], float scaleX, f32 scaleY, u16 speed) { GRRLIB_DrawImg_FadeIn(width, height, data, scaleX, scaleY, speed); GRRLIB_DrawImg_FadeOut(width, height, data, scaleX, scaleY, speed); } /** * Fade in * @param width Texture width. * @param height Texture height. * @param data Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeIn(u16 width, u16 height, u8 data[], float scaleX, f32 scaleY, u16 speed) { int alpha; f32 xpos = (640 - width) / 2; f32 ypos = (480 - height) / 2; for(alpha = 0; alpha < 255; alpha += speed) { GRRLIB_DrawImg(xpos, ypos, width, height, data, 0, scaleX, scaleY, alpha); GRRLIB_Render(); } } /** * Fade out * @param width Texture width. * @param height Texture height. * @param data Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeOut(u16 width, u16 height, u8 data[], float scaleX, f32 scaleY, u16 speed) { int alpha; f32 xpos = (640 - width) / 2; f32 ypos = (480 - height) / 2; for(alpha = 255; alpha > 0; alpha -= speed) { GRRLIB_DrawImg(xpos, ypos, width, height, data, 0, scaleX, scaleY, alpha); GRRLIB_Render(); } }PS: Could you explain me why you did a loop in the GRRLIB_ScreenCap function?
Becouse without the loop, the tex come out with a little garbage in the top, that was the only way i could make it work fine.
Any improvement is welcome
bmic
Offline
RedShade wrote:
So... you are locking everything else from drawing while you fade, even the CPU?
If you are going to just be doing that texture, you could do something about just locking it to TEX0, and not resetting it to a new TexObj pointer every time with TexInit (though I don't think that is really hurting, since the memory location of the texture data is the same each time. I think that is what the texture cache uses to check if it should send a new texture to the chip)
*Note about the screen capture: That's a 1.2 mb leak :-(
I was realy thinking that the memory location of the texture data is the same, but maybe improve quality and stability, after my vacations i will see that.
bmic
Offline
my_texture = memalign(32, 640 * 480 * 4);
the memory is pulled from memalign, which is called twice, thus two different memory locations are created, and the first loop through location is left without destroying the memory allocation, so it's leaked.
GX_SetTexCopySrc(0, 0, 640, 480); GX_SetTexCopyDst(640, 480, GX_TF_RGBA8, GX_FALSE);
<-- unles you are planning on copying from another size, or to another size, or using a different format than RGBA8, you never need to call these more than once in a program. If you do change, you only need to call it then, and nowhere else.
I've tried to mention a function like this, but kept getting the name wrong :-/... the syncronization thing on the fifo that guarentee's full copy:
void GX_PixModeSync () Inserts a synchronization command into the graphics FIFO. When the GPU sees this command it will allow the rest of the pipe to flush before continuing. This command is useful in certain situation such as after a GX_CopyTex() command and before a primitive that uses the copied texture.
Last edited by RedShade (2008-07-22 19:45:43)
Offline
RedShade wrote:
Code:
GX_SetTexCopySrc(0, 0, 640, 480); GX_SetTexCopyDst(640, 480, GX_TF_RGBA8, GX_FALSE);<-- unles you are planning on copying from another size, or to another size, or using a different format than RGBA8, you never need to call these more than once in a program. If you do change, you only need to call it then, and nowhere else.
So normally those two lines should be in GRRLIB_InitVideo if no other size are needed:
void GRRLIB_InitVideo () { ... GX_SetTexCopySrc(0, 0, 640, 480); GX_SetTexCopyDst(640, 480, GX_TF_RGBA8, GX_FALSE); }
whit that in mind, the function should be like this:
/** * Make a snapshot of the sreen in a texture. * @return A texture representing the screen. */ u8 *GRRLIB_ScreenCap() { void *my_texture; my_texture = memalign(32, 640 * 480 * 4); GX_CopyTex(my_texture, GX_FALSE); GX_PixModeSync(); return my_texture; }
Thanks again RedShade
Offline
Crayon wrote:
So normally those two lines should be in GRRLIB_InitVideo if no other size are needed:
Code:
void GRRLIB_InitVideo () { ... GX_SetTexCopySrc(0, 0, 640, 480); GX_SetTexCopyDst(640, 480, GX_TF_RGBA8, GX_FALSE); }whit that in mind, the function should be like this:
Code:
/** * Make a snapshot of the sreen in a texture. * @return A texture representing the screen. */ u8 *GRRLIB_ScreenCap() { void *my_texture; my_texture = memalign(32, 640 * 480 * 4); GX_CopyTex(my_texture, GX_FALSE); GX_PixModeSync(); return my_texture; }
I tried to move those two lines from the GRRLIB_ScreenCap and it seems like it's not working. I needed to reset my Wii
Offline
I think I found a way to correct the garbage with the GRRLIB_ScreenCap() function, check this message:
http://grrlib.santo.fr/forum/viewtopic.php?pid=376#p376
Offline
Just in case there are other people out there using GRRLIB 3.0.5 alpha. This is the modified Fading functions.
/** * Fade in, than fade out * @param data Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeInOut(GRRLIB_texImg tex, float scaleX, f32 scaleY, u16 speed) { GRRLIB_DrawImg_FadeIn(tex, scaleX, scaleY, speed); GRRLIB_DrawImg_FadeOut(tex, scaleX, scaleY, speed); } /** * Fade in * @param data Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeIn(GRRLIB_texImg tex, float scaleX, f32 scaleY, u16 speed) { int alpha; f32 xpos = (640 - tex.w) / 2; f32 ypos = (480 - tex.h) / 2; for(alpha = 0; alpha < 255; alpha += speed) { if(alpha > 255) alpha = 255; GRRLIB_DrawImg(xpos, ypos, tex, 0, scaleX, scaleY, 0xFFFFFF00 | alpha); GRRLIB_Render(); } } /** * Fade out * @param data Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeOut(GRRLIB_texImg tex, float scaleX, f32 scaleY, u16 speed) { int alpha; f32 xpos = (640 - tex.w) / 2; f32 ypos = (480 - tex.h) / 2; for(alpha = 255; alpha > 0; alpha -= speed) { if(alpha < 0) alpha = 0; GRRLIB_DrawImg(xpos, ypos, tex, 0, scaleX, scaleY, 0xFFFFFF00 | alpha); GRRLIB_Render(); } }
Last edited by Crayon (2009-02-10 05:26:38)
Offline
f32 xpos = (640 - tex.w) / 2; f32 ypos = (480 - tex.h) / 2;
humm and if my Img isn't on center of screen ????
Offline
Cid2mizard wrote:
humm and if my Img isn't on center of screen ????
I know it's not flexible, but you just have to change the code for your needs
I only adapted the function given by bmic. And that's what I needed for my game.
Offline
This is my last version of GRRLIB_DrawImg_FadeInOut, GRRLIB_DrawImg_FadeIn and GRRLIB_DrawImg_FadeOut. The only difference is that I'm using rmode->fbWidth and rmode->efbHeight instead of hard-coded value 640x480. For alpha I'm using s16 instead of int
/** * Fade in, than fade out. * @param tex Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeInOut(struct GRRLIB_texImg *tex, f32 scaleX, f32 scaleY, u16 speed) { GRRLIB_DrawImg_FadeIn(tex, scaleX, scaleY, speed); GRRLIB_DrawImg_FadeOut(tex, scaleX, scaleY, speed); } /** * Fade in. * @param tex Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeIn(struct GRRLIB_texImg *tex, f32 scaleX, f32 scaleY, u16 speed) { s16 alpha; f32 xpos = (rmode->fbWidth - tex->w) / 2; f32 ypos = (rmode->efbHeight - tex->h) / 2; for(alpha = 0; alpha < 255; alpha += speed) { if(alpha > 255) alpha = 255; GRRLIB_DrawImg(xpos, ypos, tex, 0, scaleX, scaleY, 0xFFFFFF00 | alpha); GRRLIB_Render(); } } /** * Fade out. * @param tex Texture. * @param scaleX Texture X scale. * @param scaleY Texture Y scale. * @param speed Fade speed (1 is the normal speed, 2 is two time the normal speed, etc). */ void GRRLIB_DrawImg_FadeOut(struct GRRLIB_texImg *tex, f32 scaleX, f32 scaleY, u16 speed) { s16 alpha; f32 xpos = (rmode->fbWidth - tex->w) / 2; f32 ypos = (rmode->efbHeight - tex->h) / 2; for(alpha = 255; alpha > 0; alpha -= speed) { if(alpha < 0) alpha = 0; GRRLIB_DrawImg(xpos, ypos, tex, 0, scaleX, scaleY, 0xFFFFFF00 | alpha); GRRLIB_Render(); } }
Offline