Author Topic: Cheap & cheerful Scanline effect  (Read 1638 times)

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Cheap & cheerful Scanline effect
« on: 2013-Aug-04 »
Just a quick thing I knocked up purely out of curiosity, some may find it useful  :D

Simple to use with just a call to make_scanlines function with the sprite id you want to use then a call to draw_scanlines immediately before showscreen, although you can call it at a different time for strange effects.

Play around with the alphamode and/or the INTEGER(0xff000000) to alter the effect.

Works best with 2x2 blocky gfx (or normal gfx scaled x2).

Because the mem2sprite part is only dealing with a 1 pixel wide sprite it should be easily modified to provide a shutter like fade effect seen a lot in the 8bit days without to much trouble. Have a play around & see what you can come up with  =D

Lee

Code: GLBasic [Select]
// --------------------------------- //
// Project: Scanlines
// Start: Saturday, August 03, 2013
// IDE Version: 10.283


SETCURRENTDIR("Media") // go to media files

GLOBAL showlines%=FALSE,line_sprite%=1
GLOBAL sw%,sh%

SETSCREEN 640,480,FALSE

GETSCREENSIZE sw%,sh%

LOADSPRITE "Test1.png",0

make_scanlines(line_sprite%)

REPEAT

        DRAWSPRITE 0,0,0

        IF KEY(2)=TRUE THEN showlines%=TRUE             // Press "1" to show scanlines
        IF KEY(3)=TRUE THEN showlines%=FALSE    // Press "2" to hide scanlines

        IF showlines%=TRUE THEN draw_scanlines(line_sprite%)

        SHOWSCREEN

UNTIL KEY(1)


FUNCTION make_scanlines: spr_id%

        LOCAL pix%[],loop%

        DIM pix%[sh%]

        FOR loop%=0 TO sh%-1 STEP 2
                pix%[loop%]=INTEGER(0xff000000)
        NEXT

        MEM2SPRITE(pix%[],spr_id%,1,sh)

ENDFUNCTION

FUNCTION draw_scanlines: spr_id%

        ALPHAMODE -1

        STARTPOLY spr_id%
                POLYVECTOR     0,    0,0,    0,RGB(255,255,255)
                POLYVECTOR     0,sh%-1,0,sh%-1,RGB(255,255,255)
                POLYVECTOR sw%-1,sh%-1,0,sh%-1,RGB(255,255,255)
                POLYVECTOR sw%-1,    0,0,    0,RGB(255,255,255)
        ENDPOLY

        ALPHAMODE 0

ENDFUNCTION
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)