Open Surge Forum

A fun 2D retro platformer inspired by Sonic games and a game creation system

You are not logged in.

Announcement

Our community has moved to Discord! https://discord.gg/w8JqM7m

#1 2012-06-29 07:21:26

KZR
Member
Registered: 2010-07-14
Posts: 1,447
Website

[questions] screen filter

i have just successfully built a screen filter based on water. instead of having a Y level, it blends the whole screen with a specific color.

how could i make this adjustable through decorators? i will also build adjustable water if this works.


SD_sml.pngSeD_sml.pngLTot_W_sml.png
https://discord.gg/w8JqM7m ---> Open Surge's Discord server

Offline

#2 2012-06-29 07:29:02

S32X
Member
From: Rochester, New York
Registered: 2012-03-18
Posts: 880
Website

Re: [questions] screen filter

Let me ask you this question. How did you get the "force_daytime" thing to work? It doesn't work on Open Surge.

Last edited by S32X (2012-06-29 07:29:14)

Offline

#3 2012-06-29 07:32:48

KZR
Member
Registered: 2010-07-14
Posts: 1,447
Website

Re: [questions] screen filter

force_daytime? you mean the day/night system?


SD_sml.pngSeD_sml.pngLTot_W_sml.png
https://discord.gg/w8JqM7m ---> Open Surge's Discord server

Offline

#4 2012-06-29 07:34:41

S32X
Member
From: Rochester, New York
Registered: 2012-03-18
Posts: 880
Website

Re: [questions] screen filter

Yes. One of my levels takes place at night. I tried doing this:

set_animation SD_FADEOUT 0
set_alpha 0.5

but that just slowed down the system. hmm

Offline

#5 2012-06-29 07:37:40

lunarrush
Member
Registered: 2010-05-13
Posts: 278

Re: [questions] screen filter

@S32X: That is how it is done, unfortunately that slowdown is built into the engine when you run an alpha based call.  In other words you will not be able to make a system like this without either creating a dithered night screen or by allowing for that slowdown.


If I knew then what I know now I'd tell you that the story's true.  Cause whatever you do, it comes back to you.  -Slaughter, Burning Bridges

Offline

#6 2012-06-29 07:42:11

S32X
Member
From: Rochester, New York
Registered: 2012-03-18
Posts: 880
Website

Re: [questions] screen filter

KZR's object had only one object, but it darkened/lightened the entire level.

Offline

#7 2012-06-29 08:08:38

KZR
Member
Registered: 2010-07-14
Posts: 1,447
Website

Re: [questions] screen filter

you will always get a slowdown. even this screen filter slows down, and is simply a color, not a whole image.


SD_sml.pngSeD_sml.pngLTot_W_sml.png
https://discord.gg/w8JqM7m ---> Open Surge's Discord server

Offline

#8 2012-06-29 08:31:23

lunarrush
Member
Registered: 2010-05-13
Posts: 278

Re: [questions] screen filter

That object was exactly the size of the screen, detached from the camera, and positioned correctly.  Hope that helps.


If I knew then what I know now I'd tell you that the story's true.  Cause whatever you do, it comes back to you.  -Slaughter, Burning Bridges

Offline

#9 2012-06-29 12:37:32

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,300
Website

Re: [questions] screen filter

I don't understand what you've built. You changed the y position of the water to make it fill the whole screen? Is it an additional filter that isn't affected by the logic of the water? Can I see the code?

The water filter has always a 50% alpha value, which enables us to do the calculations faster, reducing the slowdown. Also, when in 16-bit color mode, we use a dithered pattern instead of blending the colors, thus making it super fast.

Offline

#10 2012-06-29 14:36:12

KZR
Member
Registered: 2010-07-14
Posts: 1,447
Website

Re: [questions] screen filter

it has nothing to do with water, except it was built from its code.

It blends the screen with a specified color, much like when you are underwater, but without a height value. it starts at 0, 0.

It also uses its own color, which is for now, hard coded. Since it works, it makes sense to have a way to adjust it somewhere else, preferably through scripting.

here's the function:

/*
 * image_global_lightfx()
 * pixels below y will have a light-dark effect
 */
void image_global_lightfx(image_t *img, int y, uint32 color)
{
    fast_getpixel_funptr fast_getpixel = fast_getpixel_fun();
    fast_putpixel_funptr fast_putpixel = fast_putpixel_fun();
    fast_makecol_funptr fast_makecol = fast_makecol_fun();
    fast_getr_funptr fast_getr = fast_getr_fun();
    fast_getg_funptr fast_getg = fast_getg_fun();
    fast_getb_funptr fast_getb = fast_getb_fun();
    int col, wr, wg, wb; /* don't use uint8 */
    int i, j;

    /* adjust y */
    y = 0;

    /* color to blend */
    wr = fast_getr(color);
    wg = fast_getg(color);
    wb = fast_getb(color);

    /* color blending effect */
    if(video_get_color_depth() > 16) {
        /* fast blending algorithm (alpha = 0.5) */
        for(j=y; j<img->h; j++) {
            for(i=0; i<img->w; i++) {
                col = fast_getpixel(img->data, i, j);
                fast_putpixel(img->data, i, j, fast_makecol((fast_getr(col) + wr)>>1, (fast_getg(col) + wg)>>1, (fast_getb(col) + wb)>>1));
            }
        }
    }
    else {
       /* fast "dithered" lights, when bpp is not greater than 16 (slow computers?) */
       for(j=y; j<img->h; j++) {
           for(i=j%2; i<img->w; i+=2) {
               fast_putpixel(img->data, i, j, color);
           }
        }
    }
}

it's pretty much the water effect function, with a different purpose. I also had to add some stuff to level.c, basically i followed your water implementation.

by the way, we could also add decorators to manipulate image_draw_lit() and make color-blended sprites

Last edited by KZR (2012-06-29 14:38:51)


SD_sml.pngSeD_sml.pngLTot_W_sml.png
https://discord.gg/w8JqM7m ---> Open Surge's Discord server

Offline

#11 2012-06-29 15:46:29

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,300
Website

Re: [questions] screen filter

KZR wrote:
/*
 * image_global_lightfx()
 * pixels below y will have a light-dark effect
 */
void image_global_lightfx(image_t *img, int y, uint32 color)
{
    fast_getpixel_funptr fast_getpixel = fast_getpixel_fun();
    fast_putpixel_funptr fast_putpixel = fast_putpixel_fun();
    fast_makecol_funptr fast_makecol = fast_makecol_fun();
    fast_getr_funptr fast_getr = fast_getr_fun();
    fast_getg_funptr fast_getg = fast_getg_fun();
    fast_getb_funptr fast_getb = fast_getb_fun();
    int col, wr, wg, wb; /* don't use uint8 */
    int i, j;

    /* adjust y */
    y = 0;

    /* color to blend */
    wr = fast_getr(color);
    wg = fast_getg(color);
    wb = fast_getb(color);

    /* color blending effect */
    if(video_get_color_depth() > 16) {
        /* fast blending algorithm (alpha = 0.5) */
        for(j=y; j<img->h; j++) {
            for(i=0; i<img->w; i++) {
                col = fast_getpixel(img->data, i, j);
                fast_putpixel(img->data, i, j, fast_makecol((fast_getr(col) + wr)>>1, (fast_getg(col) + wg)>>1, (fast_getb(col) + wb)>>1));
            }
        }
    }
    else {
       /* fast "dithered" lights, when bpp is not greater than 16 (slow computers?) */
       for(j=y; j<img->h; j++) {
           for(i=j%2; i<img->w; i+=2) {
               fast_putpixel(img->data, i, j, color);
           }
        }
    }
}

I'm really happy that you guys are so eager to contribute new features to the engine. I am. But if we're going to incorporate this into the engine (not just in your hack, but in open surge, so everybody can benefit from your work), you really, really, really need to learn C. Please. I'm sorry I'm criticizing that piece of code in public, but I'm just trying to help. I do want that you guys continue to contribute, but if you're going to contribute with code, it must have quality.

I learned C years ago using this site: http://www.ead.cpdee.ufmg.br/cursos/C/c.html . It's a really good course (in portuguese). Please take some time and learn it.

Before adding any non-trivial feature to the engine, you must understand what you're doing. Otherwise, if you just blindly follow cookbooks, the code generated will be of bad quality, like this one. I cannot merge this into the codebase.

---

If your function takes an integer y as an input parameter, but immediately after resets it to zero, it makes no sense at all asking for that parameter. It just confuses anyone who's going to call that function. It would be best if, instead of creating a new function, you just called the water effect function setting the parameter y to zero. Or, created a new filter that just called waterfx with y=0, and then you call that new filter in your main code.

Since you plan to make a decorator, you don't need to modify level.c (you can, but you don't have to). In programming, we do our best to avoid side effects (that is, a modification we do in one part of the code shouldn't affect others). If we want to add some new feature, we do our best to change the minimum number of modules that we can. That way, our modifications become localized, and eventual new bugs do not spread through all the code.

I think that creating a new decorator that just calls the waterfx function in its render routine solves your problem (I never tested it, but I think it should work). Then, the filter would cover everything behind the object, but nothing in front of the object. That way, you could also combine several filters at once. Plus, if your decorator took 3 parameters (r, g, b), you could play with the colors of the filter. No need to modify level.c. But then you'd have to understand what you code.

Of course you don't need to follow my suggestion, but the code you write must have quality. This, unfortunately, is a bit difficult to define. Sorry for the criticism (it's a constructive one), but please learn C. You'll enjoy it, I'm sure. smile

Offline

#12 2012-06-29 21:53:46

S32X
Member
From: Rochester, New York
Registered: 2012-03-18
Posts: 880
Website

Re: [questions] screen filter

Alexandre wrote:

I learned C years ago using this site: http://www.ead.cpdee.ufmg.br/cursos/C/c.html . It's a really good course (in portuguese). Please take some time and learn it.

No problem I'll just use Google Translate to English.

Offline

#13 2012-06-29 22:14:22

KZR
Member
Registered: 2010-07-14
Posts: 1,447
Website

Re: [questions] screen filter

if i didn't modify level.c how would the function be rendered? and i had to set the parameter to 0 to know it was working.
other than those 2 points your critics are perfectly valid, and thank you for taking your time to look at a beginner's piece of crap code. It's not your duty or responsibility to teach us how to code, and yet, you assure everyone is going the right way, even if the features never make it into the official release, so, thank you, once more smile

Last edited by KZR (2012-06-29 22:14:39)


SD_sml.pngSeD_sml.pngLTot_W_sml.png
https://discord.gg/w8JqM7m ---> Open Surge's Discord server

Offline

#14 2012-06-30 07:36:50

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,300
Website

Re: [questions] screen filter

every decorator has a render function. This is how textout is done, for example.

Offline

#15 2012-07-01 05:06:51

jobromedia
Member
From: Stockholm, Sweden
Registered: 2009-11-01
Posts: 1,072
Website

Re: [questions] screen filter

Really nice feature. Looking forward to test it tonight.

Offline

Board footer

Powered by FluxBB  hosted by tuxfamily.org