Author Topic: C64-ize graphics  (Read 20292 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
C64-ize graphics
« on: 2008-Mar-25 »
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

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5116
  • O Rly?
    • View Profile
C64-ize graphics
« Reply #1 on: 2008-Mar-25 »
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

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
C64-ize graphics
« Reply #2 on: 2008-Mar-25 »
Wow!

Offline Achim

  • Mr. Drawsprite
  • **
  • Posts: 87
    • View Profile
    • softworXs
C64-ize graphics
« Reply #3 on: 2008-Mar-25 »
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]

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
C64-ize graphics
« Reply #4 on: 2008-Apr-02 »
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

  • Guest
C64-ize graphics
« Reply #5 on: 2008-Apr-02 »
Yeah, C64-like graphics REALTIME... but with DX9 capable graphics cards only. That's quite ironic ;)
Anyway, great work!

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
C64-ize graphics
« Reply #6 on: 2008-Apr-02 »
It doesn't seem to work on my 7900 GS Go.

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
C64-ize graphics
« Reply #7 on: 2008-Apr-03 »
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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
C64-ize graphics
« Reply #8 on: 2008-Apr-03 »
What GFX card, PJ?

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4176
  • On the shoulders of giants.
    • View Profile
    • My Apps
C64-ize graphics
« Reply #9 on: 2008-Apr-03 »
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.

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
C64-ize graphics
« Reply #10 on: 2008-Apr-03 »
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

  • Guest
C64-ize graphics
« Reply #11 on: 2008-Apr-04 »
Works fine for me.  NVidia GeForce 8600M GT here.  Sounds like it's more a problem for older cards maybe?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
C64-ize graphics
« Reply #12 on: 2008-Apr-04 »
Might be. It needs Shader Language 2.0

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
C64-ize graphics
« Reply #13 on: 2008-Apr-04 »
Mine has shader 2 and is not that old.  I've some shader's (reportedly v2) in MMF that work ok.

Hatonastick

  • Guest
C64-ize graphics
« Reply #14 on: 2008-Apr-04 »
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?