Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Blitz => Topic started by: TinDragon on July 26, 2009

Title: [BMAX]Magnified Rotozoom source
Post by: TinDragon on July 26, 2009
Here's the source code to one of my challenge entries, it requires Zawrans software render framework to compile which is also available on the forum.
It's not the best commented source in the world but atleast shows some more uses for Zawrans code for any bmax users interested :)

Code: [Select]
SuperStrict

Framework BRL.GLMax2D
Import BRL.Pixmap
Import BRL.PNGLoader
'Import BRL.Random
Import BRL.Retro

AppTitle="Rotozoom Magnify"

SetGraphicsDriver GLMax2DDriver()

Include "zSoftwareRenderFramework_v04.bmx"
Const XRES:Int=800
Const YRES:Int=600
Graphics XRES,YRES,0

Global timerUpd:Int = MilliSecs()
Global timerFrq:Int = 1000/30 ' 30 fps

' create an image buffer to store the screen in
Global screenBuffer:zImageBuffer = zImageBuffer.make(XRES,YRES)

' create an image buffer used for the magnification frame
Global tmpImg:zImageBuffer = zImageBuffer.make(62,62)


Const hxres:Int=XRES/2
Const hyres:Int=YRES/2

Local ang:Float=0.0
Local c:Int,xo:Int,yo:Int,y:Int,x:Int,i:Int,j:Int

Repeat

' clear screen buffer
screenBuffer.clear()

ang=ang+0.75
c=750*Cos(ang)
xo=200+200*Sin(ang*2)
yo=200+200*Cos(ang*3)
For y=0 To yres-1
For x=0 To xres-192
i=x+xo-hxres
j=y+yo-hyres
screenBuffer.setpixel(x,y,(((i+j*c/256) & 255) ~ ((j-i*c/256) & 255)),0,0,255)
Next
Next

' copy rects from screen buffer to temporary buffers
tmpImg.copyrectblock(screenBuffer,288,208,62,62,0,0)
' draw temporary buffers scaled to the screen buffer
tmpImg.drawScaledBlock(screenBuffer,xres-188,4,3.0,3.0)
tmpImg.drawScaledBlock(screenBuffer,xres-188,204,3.0,3.0)
tmpImg.drawScaledBlock(screenBuffer,xres-188,yres-191,3.0,3.0)
' draw screenbuffer to the screen
screenBuffer.blitToScreen()
Flip

While MilliSecs() < timerUpd+timerFrq
Wend
timerUpd = MilliSecs()

Until KeyDown(KEY_ESCAPE)
End

hehe notice I have a clear screen in there that I dont even thing I need :P

cheers
Jon
Title: Re: [BMAX]Magnified Rotozoom source
Post by: zawran on July 26, 2009
Yes since you are drawing into the entire screen buffer, you really don't have to clear it first so you can safely do without the following line:

Code: [Select]
screenBuffer.clear()
Thanks for sharing the code, and for using the framework for the entry.
Title: Re: [BMAX]Magnified Rotozoom source
Post by: Shockwave on July 26, 2009
Thank you for sharing the code mate K+
Title: Re: [BMAX]Magnified Rotozoom source
Post by: benny! on July 26, 2009
inc karma.