Codesnippets > 2D-snippets

C64-ize graphics

(1/6) > >>

Kitty Hello:
This function uses the current back buffer's contents and re-renders it with the C64 color palette. Unfortunately it's too slow for real-time updates :(. I'll try to find a way for that.

--- Code: GLBasic ---// --------------------------------- //
// Project: C64izer
// Start: Tuesday, March 25, 2008
// IDE Version: 5.212


LOADBMP "test.png"
C64ize()
SHOWSCREEN
MOUSEWAIT




FUNCTION C64ize:
        // weighting of color components
LOCAL x,y,c, r,g,b, dr,dg,db
LOCAL mindist, dist, ibest, i
LOCAL c64_pal[]
        DIMDATA c64_pal[], _
                        0x00    , 0x00  , 0x00, 0, _
                        0xff    , 0xff  , 0xff, 0, _
                        0x88    , 0x00  , 0x00, 0, _
                        0xaa    , 0xff  , 0xee, 0, _
                        0xcc    , 0x44  , 0xcc, 0, _
                        0x00    , 0xcc  , 0x55, 0, _
                        0x00    , 0x00  , 0xaa, 0, _
                        0xee    , 0xee  , 0x77, 0, _
                        0xdd    , 0x88  , 0x55, 0, _
                        0x66    , 0x44  , 0x00, 0, _
                        0xff    , 0x77  , 0x77, 0, _
                        0x33    , 0x33  , 0x33, 0, _
                        0x77    , 0x77  , 0x77, 0, _
                        0xaa    , 0xff  , 0x66, 0, _
                        0x00    , 0x88  , 0xff, 0, _
                        0xbb    , 0xbb  , 0xbb, 0

        FOR i=0 TO 15
                c64_pal[i*4+3] = RGB(c64_pal[i*4], c64_pal[i*4+1], c64_pal[i*4+2])
        NEXT

        FOR x=0 TO 319 STEP 2
                FOR y=0 TO 239
                        c = GETPIXEL(x,y)
                        b=BAND(c/0x10000, 0xff)/2
                        g=BAND(c/0x100  , 0xff)/2
                        r=BAND(c        , 0xff)/2
                        mindist=0
                        c = GETPIXEL(x+1,y)
                        INC b,BAND(c/0x10000, 0xff)/2
                        INC g,BAND(c/0x100  , 0xff)/2
                        INC r,BAND(c        , 0xff)/2



                        ibest=0
                        FOR i=0 TO 15
                                db=ABS(BAND(c/0x10000, 0xff) - c64_pal[i*4+2])
                                dg=ABS(BAND(c/0x100  , 0xff) - c64_pal[i*4+1])
                                dr=ABS(BAND(c        , 0xff) - c64_pal[i*4  ])
                                dist=dr*dr+dg*dg+db*db
                                IF i=0 OR dist<mindist
                                        mindist=dist
                                        ibest=i
                                ENDIF
                        NEXT
                        DRAWRECT x,y,2,1,c64_pal[ibest*4+3]
                NEXT
        NEXT
ENDFUNCTION

Schranz0r:
Cool, but very slow :(

AndyH:
Wow!

Achim:
Sweet Gernot ! Nice piece of code ... reminds me to the good old days ... once upon, a long ago :D

CYA !

Kitty Hello:
So, now in realtime:
http://www.glbasic.com/showroom.php?game=C64colorshader
Forgive me, for this is my first fragment shader, ever. It's not very optimized, but it works REALTIME.

Navigation

[0] Message Index

[#] Next page

Go to full version