PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Homebrew GapiDraw effects (fading, blur, etc..)

Hi,

I did some quick searching and I'm looking for code people have come up with for GapiDraw that do some nifty effects. What have you guys/gals come up with? Anyone have a good fade in/out routine? Caring means sharing! Spicing up our games with new effects would be good. I currently don't have anything special to share though, but I originally just was looking for that fading routine. Hopefully people will contribute to this thread and we'll all get to see some nice effects to plug in.

-Fraggler
To be more specific on the fade I was looking for...

I can currently fade in surface's made with CreateSurface by using the 'opacity' setting for BltFast Such as:

Code:


m_pDisplay->Flip();
//fades in splash screen from current screen
GDBLTFASTFX gdbltfastfx;
for(int i = 0; i < 256; i++)
{
gdbltfastfx.dwOpacity = i;
m_pDisplay->GetBackBuffer()->BltFast(0, 0, &m_splash, NULL, GDBLT_KEYSRC | GDBLTFAST_OPACITY, &gdbltfastfx);
m_pDisplay->Flip();
}


But I was looking for a way to do this with the current BackBuffer. Also, how would you fade out? If fading out like done above, it will just overlay itself with a more transparent version, resulting in no more transparency as last time. I could always BltFast the current buffer to a new surface, then fade that surface back to the BackBuffer to get a surface of the backbuffer. Then I can use FillRect to fill the backbuffer before each blit of each frame of the fade out to fix the problem just mentioned. Only problem is its too slow, could be FillRect lagging it, but maybe i'm not doing this the best way possible. Any ideas?

I imagine it would look something like:

Code:

copyOfBuffer.CreateSurface(GDSURFACE_SYSTEMMEMORY, m_pDisplay->GetWidth(), m_pDisplay->GetHeight());
copyOfBuffer.BltFast(0,0,m_pDisplay->GetBackBuffer(),NULL,NULL,NULL);
m_pDisplay->Flip();
//fades out
GDBLTFASTFX gdbltfastfx;
for(int i = 0; i < 256; i++)
{
gdbltfastfx.dwOpacity = 255 - i;
//fills screen with black for fading out so opacity works
m_pDisplay->GetBackBuffer()->FillRect(NULL, RGB(255,255,255),NULL,NULL);
m_pDisplay->GetBackBuffer()->BltFast(0,0,&copyOfBuffer,NULL, GDBLTFAST_OPACITY, &gdbltfastfx);
m_pDisplay->Flip();
}


Would also love to see some peoples effect's posted here though. I read the post on dissolve effects put couldn't produce a nice one myself.

EDIT: Changed this post around to reflect changes made in code and testing.
Hi,

Why dont you try this trick :

1. Draw the images first with 100% opacity.

2. Draw a full screen solid BLACK rectangle with 100% opacity.

3. Then FADE IN your rectangle slowly. ( of course the image is at the back )

Regards.
Eh, because I'm such a nice guy...

I'm pretty sure I was the one that started the referenced dissolve effect thread. Here's how I did it as seen in K&G Arcade (disclaimer: I don't for a second think this is the best way of doing it, but it does have the virtue of working, so shoot me for not writing doctoral-quality code!)...

Attached is an Excel spreadsheet that will generate a data file which represents a random set of coordinates for a 40x40 block. After you open it and click the button, it will spit out a binary data file. Import it into your project.

Here's the general code that you'll use (I hacked this out of the game, so it might not be 100%... it's pretty darn simple anyway, so I have no doubt you can fix it if it's broke)...

Code:

COLORREF pixel_color = RGB(0, 0, 0);
CGapiSurface* dissolve_surface; // Create an empty 40x40 dissolve_surface here, I'm too lazy to look up the code!
int dissolve_data_index = 0;
unsigned char* dissolve_data // This is a pointer to the dissolve data resource

for (int i = 0; i < 35; i++) {
unsigned char x = *(dissolve_data + dissolve_data_index);
dissolve_data_index++;
unsigned char y = *(dissolve_data + dissolve_data_index);
dissolve_data_index++;
dissolve_surface->SetPixel(x, y, pixel_color);
}
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 6; x++) {
backbuffer->BltFast((x * 40), (y * 40), dissolve_surface, NULL, GDBLTFAST_KEYSRC, NULL);
}
}
if (dissolve_data_index > 3200) {
// Dissolve is done
}


Call that code once per frame (being sure to NOT reset any of the variables at the top!) and you'll get a decent dissolve effect.
I'm assuming this code gets calls each time thru the game loop? Otherwise, how do you control the speed of the dissolve (the 'for' loop)?

*Modified* - Oops, I just read the last line of your message ("once per frame").
Yes, as I said near the end, call this code once per frame.

Basically, the math works like this... A 40x40 square yields 1600 pixels. So:

x = Number of frames
y = Number of pixels dissolved per frame

x * y >= 1600

(You want to be as close to 1600 as possible, going over is OK). So, as written, the dissolve will take right around 46 frames to complete, about 1.5 seconds at 30fps.

You could of course increase or decrease the size of the dissolve surface, but you'll have to modify the data generator macro, which certainly is no big deal. 40x40 seemed like a good compromise between data size and speed.

*Modified* - Sorry, you must have modified your post as I was typing my reply :)