scale graphics

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
sys49152
Posts: 43
Joined: Jun 11, 2005 21:36

scale graphics

Post by sys49152 »

I was looking for a fast routine to scale 320x240 to 640x480
and put some old monitor raster line effect to it for every
frame when i got an idea. Why not precalculate scale and
raster in the beginning of the program. and skip the
(320x240 --> scale and raster --> 640x480) routine for
every frame.

Here's a quick, not so good, example on what i mean.

What do you think?

sorry bad english.

Code: Select all

'Example on How to resize the 320,240 graphics to 640,480 graphics,
'and while you are at it, put some retrostyle raster effects to the graphics too.
'All done only ones in the beginning of the program insted of for every frame.

ScreenRes 640,480,32,1,0
Static As Any Ptr sprite(1)
sprite(0)=ImageCreate(32,32,&hff00ff)
sprite(1)=ImageCreate(32,32,&hff00ff)

Static As Integer x,y,d,c(6),r

c(1)=&h444444 'colors
c(2)=&hff4444
c(3)=&h44ff44

c(4)=&h000000 'dark part of color 1 to be used for the raster effect.
c(5)=&haa0000 '             color 2
c(6)=&h00aa00 '             color 3

For r=0 To 1
 For y=0 To 15
  For x=0 To 15
   Read d
   If d>0 Then
    PSet(16+x+(32*r),16+y),c(d)                 'draw original sprite data to screen.
    Line sprite(r),(x*2,y*2)-Step(1,0),c(d)     'create resized sprite...
    Line sprite(r),(x*2,y*2+1)-Step(1,0),c(d+3) '...with raster effect.
   End If
  Next
 Next
Next

Put(16,64),sprite(0),Trans 'draw sprites to the screen
Put(64,64),sprite(1),Trans

Draw string(16,4),"Original graphic data."
Draw String(16,52),"Resized images with raster effect."
Draw String(16,150),"Hit any key..."

Sleep

'now, you can draw graphics directly to 640,480 screen. No resize or raster calculation for every frame neded.
'The only recalculation you have to do for every frame is to double the value of the X and Y with "Shl 1".

Static As Integer x1,y1,x2,y2

Do
 For x1=0 To 19
  For y1=0 To 10
   Put((x1*16) Shl 1,(y1*16) Shl 1),sprite(1),Trans
  Next
 Next

 x2+=1
 y2+=1
 If x2>320 Then x2=-16
 If y2>240 Then y2=-16
 Put((x2) Shl 1,(y2) Shl 1),sprite(0),Trans
 Draw String(5,5),"Hit Esc to end."

 Sleep 20
Loop Until MultiKey(1)
End

'Graphics data...
Data 0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0
Data 0,0,0,1,1,2,2,2,2,2,2,1,1,0,0,0
Data 0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0
Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0
Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0
Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0
Data 0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0
Data 0,0,0,1,1,2,2,2,2,2,2,1,1,0,0,0
Data 0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0

Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
ShawnLG
Posts: 142
Joined: Dec 25, 2008 20:21

Post by ShawnLG »

I like the retro raster effect.
Post Reply