C64-ize graphics

Previous topic - Next topic

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) Select
// --------------------------------- //
// 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=dist
ibest=i
ENDIF
NEXT
DRAWRECT x,y,2,1,c64_pal[ibest*4+3]
NEXT
NEXT
ENDFUNCTION

Schranz0r

Cool, but very slow :(
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

AndyH


Achim

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

CYA !
- www.softworxs.de -
[Be different - play smart]

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.

Simon Parzer

Yeah, C64-like graphics REALTIME... but with DX9 capable graphics cards only. That's quite ironic ;)
Anyway, great work!

AndyH

It doesn't seem to work on my 7900 GS Go.

PeeJay

You're not alone, Andy. All I get is the image displayed as normal, not C64ized. :(
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Kitty Hello

What GFX card, PJ?

Ian Price

On my machine, the image does turn blocky a la C64, but it's still true colour and doesn't use only C64 palette :(

ATI Radeon 9800+ 256Mb (old, but gold).
I came. I saw. I played.

PeeJay

NVidia GeForce FX 5500 here (old, but, er, crap :D)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Hatonastick

Works fine for me.  NVidia GeForce 8600M GT here.  Sounds like it's more a problem for older cards maybe?

Kitty Hello

Might be. It needs Shader Language 2.0

AndyH

Mine has shader 2 and is not that old.  I've some shader's (reportedly v2) in MMF that work ok.

Hatonastick

Yeah I noticed that when I went and did a bit of research on each of the cards mentioned.  Unfortunately in the case of Ian and PJ I'm not surprised theirs are having problems with Open GL Shader 2.  BTW Andy, not that it might be the problem, but are you running XP or Vista and are your drivers up to date?